Skip to content

Commit 2a55fdc

Browse files
committed
Fix some tests
1 parent 35e5972 commit 2a55fdc

File tree

3 files changed

+121
-43
lines changed

3 files changed

+121
-43
lines changed

src/Factory/MenuFactory.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace PhpSchool\PhpWorkshop\Factory;
44

5+
use PhpSchool\CliMenu\Style\SelectableStyle;
56
use Psr\Container\ContainerInterface;
67
use PhpSchool\CliMenu\CliMenu;
78
use PhpSchool\CliMenu\Builder\CliMenuBuilder;
@@ -74,8 +75,11 @@ function (CliMenu $menu) use ($exerciseRenderer, $eventDispatcher, $exercise) {
7475
->setBackgroundColour($c->get('bgColour'))
7576
->setForegroundColour($c->get('fgColour'))
7677
->setWidth(70)
77-
->setUnselectedMarker(' ')
78-
->setSelectedMarker('')
78+
->modifySelectableStyle(function (SelectableStyle $style) {
79+
$style
80+
->setUnselectedMarker(' ')
81+
->setSelectedMarker('');
82+
})
7983
->setItemExtra('[COMPLETED]');
8084

8185
$builder

test/ExerciseDispatcherTest.php

Lines changed: 112 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -271,28 +271,59 @@ public function testVerifyOnlyRunsRequiredChecks() : void
271271
$input = new Input('app', ['program' => $this->file]);
272272
$exercise = new CliExerciseImpl('Some Exercise');
273273

274-
$checkProphecy1 = $this->prophesize(SimpleCheckInterface::class);
275-
$checkProphecy1->canRun($exercise->getType())->willReturn(true);
276-
$checkProphecy1->getPosition()->willReturn(SimpleCheckInterface::CHECK_BEFORE);
277-
$checkProphecy1->getExerciseInterface()->willReturn(ExerciseInterface::class);
278-
$checkProphecy1->check($exercise, $input)->willReturn(new Success('Success!'));
279-
280-
$checkProphecy2 = $this->prophesize(SimpleCheckInterface::class);
281-
$checkProphecy2->check($exercise, $input)->shouldNotBeCalled();
282-
283-
$check1 = $checkProphecy1->reveal();
284-
$check2 = $checkProphecy2->reveal();
285-
286-
$runner = $this->prophesize(ExerciseRunnerInterface::class);
287-
$runner->getRequiredChecks()->willReturn([get_class($check1)]);
288-
$runner->verify($input)->willReturn(new Success('Success!'));
289-
$runnerManager = $this->prophesize(RunnerManager::class);
290-
$runnerManager->getRunner($exercise)->willReturn($runner->reveal());
274+
$check1 = $this
275+
->getMockBuilder(SimpleCheckInterface::class)
276+
->setMockClassName('SimpleCheckMock1')
277+
->getMock();
278+
279+
$check1
280+
->method('canRun')
281+
->willReturn(true);
282+
283+
$check1
284+
->method('getPosition')
285+
->willReturn(SimpleCheckInterface::CHECK_BEFORE);
286+
287+
$check1
288+
->method('getExerciseInterface')
289+
->willReturn(ExerciseInterface::class);
290+
291+
$check1
292+
->method('check')
293+
->with($exercise, $input)
294+
->willReturn(new Success('Success!'));
295+
296+
$check2 = $this
297+
->getMockBuilder(SimpleCheckInterface::class)
298+
->setMockClassName('SimpleCheckMock2')
299+
->getMock();
300+
301+
$check2
302+
->expects($this->never())
303+
->method('check')
304+
->with($exercise, $input);
305+
306+
$runner = $this->createMock(ExerciseRunnerInterface::class);
307+
$runner
308+
->expects($this->once())
309+
->method('getRequiredChecks')
310+
->willReturn([get_class($check1)]);
311+
312+
$runner
313+
->method('verify')
314+
->with($input)
315+
->willReturn(new Success('Success!'));
316+
317+
$runnerManager = $this->createMock(RunnerManager::class);
318+
$runnerManager
319+
->method('getRunner')
320+
->with($exercise)
321+
->willReturn($runner);
291322

292323
$exerciseDispatcher = new ExerciseDispatcher(
293-
$runnerManager->reveal(),
324+
$runnerManager,
294325
new ResultAggregator,
295-
$this->prophesize(EventDispatcher::class)->reveal(),
326+
new EventDispatcher(new ResultAggregator()),
296327
new CheckRepository([$check1, $check2])
297328
);
298329

@@ -346,31 +377,71 @@ public function testWhenBeforeChecksFailTheyReturnImmediately() : void
346377
$input = new Input('app', ['program' => $this->file]);
347378
$exercise = new CliExerciseImpl('Some Exercise');
348379

349-
$checkProphecy1 = $this->prophesize(SimpleCheckInterface::class);
350-
$checkProphecy1->canRun($exercise->getType())->willReturn(true);
351-
$checkProphecy1->getPosition()->willReturn(SimpleCheckInterface::CHECK_BEFORE);
352-
$checkProphecy1->getExerciseInterface()->willReturn(ExerciseInterface::class);
353-
$checkProphecy1->check($exercise, $input)->willReturn(new Failure('Failure', 'nope'));
354-
355-
$checkProphecy2 = $this->prophesize(SimpleCheckInterface::class);
356-
$checkProphecy2->canRun($exercise->getType())->willReturn(true);
357-
$checkProphecy2->getPosition()->willReturn(SimpleCheckInterface::CHECK_BEFORE);
358-
$checkProphecy2->getExerciseInterface()->willReturn(ExerciseInterface::class);
359-
$checkProphecy2->check($exercise, $input)->shouldNotBeCalled();
360-
361-
$check1 = $checkProphecy1->reveal();
362-
$check2 = $checkProphecy2->reveal();
363-
364-
$runner = $this->prophesize(ExerciseRunnerInterface::class);
365-
$runner->getRequiredChecks()->willReturn([get_class($check1), get_class($check2)]);
366-
$runner->verify($input)->shouldNotBeCalled();
367-
$runnerManager = $this->prophesize(RunnerManager::class);
368-
$runnerManager->getRunner($exercise)->willReturn($runner->reveal());
380+
$check1 = $this
381+
->getMockBuilder(SimpleCheckInterface::class)
382+
->setMockClassName('SimpleCheckMock1')
383+
->getMock();
384+
385+
$check1
386+
->method('canRun')
387+
->willReturn(true);
388+
389+
$check1
390+
->method('getPosition')
391+
->willReturn(SimpleCheckInterface::CHECK_BEFORE);
392+
393+
$check1
394+
->method('getExerciseInterface')
395+
->willReturn(ExerciseInterface::class);
396+
397+
$check1
398+
->method('check')
399+
->with($exercise, $input)
400+
->willReturn(new Failure('Failure', 'nope'));
401+
402+
$check2 = $this
403+
->getMockBuilder(SimpleCheckInterface::class)
404+
->setMockClassName('SimpleCheckMock2')
405+
->getMock();
406+
407+
$check2
408+
->method('canRun')
409+
->willReturn(true);
410+
411+
$check2
412+
->method('getPosition')
413+
->willReturn(SimpleCheckInterface::CHECK_BEFORE);
414+
415+
$check2
416+
->method('getExerciseInterface')
417+
->willReturn(ExerciseInterface::class);
418+
419+
$check2
420+
->expects($this->never())
421+
->method('check')
422+
->with($exercise, $input);
423+
424+
$runner = $this->createMock(ExerciseRunnerInterface::class);
425+
$runner
426+
->expects($this->once())
427+
->method('getRequiredChecks')
428+
->willReturn([get_class($check1), get_class($check2)]);
429+
430+
$runner
431+
->expects($this->never())
432+
->method('verify')
433+
->with($input);
434+
435+
$runnerManager = $this->createMock(RunnerManager::class);
436+
$runnerManager
437+
->method('getRunner')
438+
->with($exercise)
439+
->willReturn($runner);
369440

370441
$exerciseDispatcher = new ExerciseDispatcher(
371-
$runnerManager->reveal(),
442+
$runnerManager,
372443
new ResultAggregator,
373-
$this->prophesize(EventDispatcher::class)->reveal(),
444+
new EventDispatcher(new ResultAggregator()),
374445
new CheckRepository([$check1, $check2])
375446
);
376447

test/MenuItem/ResetProgressTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public function testResetProgressDisablesParentMenuItems() : void
3434
->method('hideItemExtra');
3535

3636
$terminal = $this->createMock(Terminal::class);
37+
$terminal
38+
->method('getWidth')
39+
->willReturn(100);
3740

3841
$menu = new CliMenu('Menu', [$item1, $item2], $terminal);
3942

0 commit comments

Comments
 (0)