|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PhpSchool\PhpWorkshopTest\Listener; |
| 4 | + |
| 5 | +use PhpSchool\PhpWorkshop\CommandDefinition; |
| 6 | +use PhpSchool\PhpWorkshop\Event\Event; |
| 7 | +use PhpSchool\PhpWorkshop\ExerciseRepository; |
| 8 | +use PhpSchool\PhpWorkshop\ExerciseRunner\RunnerManager; |
| 9 | +use PhpSchool\PhpWorkshop\Listener\ConfigureCommandListener; |
| 10 | +use PhpSchool\PhpWorkshop\UserState; |
| 11 | +use PhpSchool\PhpWorkshopTest\Asset\CliExerciseImpl; |
| 12 | +use PHPUnit_Framework_TestCase; |
| 13 | + |
| 14 | +/** |
| 15 | + * @author Aydin Hassan <aydin@hotmail.co.uk> |
| 16 | + */ |
| 17 | +class ConfigureCommandListenerTest extends PHPUnit_Framework_TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @dataProvider configurableCommands |
| 21 | + * @param string $commandName |
| 22 | + */ |
| 23 | + public function testInputIsConfiguredForCorrectCommands($commandName) |
| 24 | + { |
| 25 | + $command = new CommandDefinition($commandName, [], function () { |
| 26 | + }); |
| 27 | + |
| 28 | + $state = new UserState([], 'Exercise 1'); |
| 29 | + $exercise = new CliExerciseImpl('Exercise 1'); |
| 30 | + $repo = new ExerciseRepository([$exercise]); |
| 31 | + |
| 32 | + $runnerManager = $this->prophesize(RunnerManager::class); |
| 33 | + $runnerManager->configureInput($exercise, $command)->shouldBeCalled(); |
| 34 | + |
| 35 | + $event = new Event('some-event', ['command' => $command]); |
| 36 | + (new ConfigureCommandListener($state, $repo, $runnerManager->reveal()))->__invoke($event); |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * @return array |
| 41 | + */ |
| 42 | + public function configurableCommands() |
| 43 | + { |
| 44 | + return [ |
| 45 | + ['verify'], |
| 46 | + ['run'], |
| 47 | + ]; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @dataProvider nonConfigurableCommands |
| 52 | + * @param string $commandName |
| 53 | + */ |
| 54 | + public function testInputIsNotConfiguredForCorrectCommands($commandName) |
| 55 | + { |
| 56 | + $command = new CommandDefinition($commandName, [], function () { |
| 57 | + }); |
| 58 | + |
| 59 | + $state = new UserState([], 'Exercise 1'); |
| 60 | + $exercise = new CliExerciseImpl('Exercise 1'); |
| 61 | + $repo = new ExerciseRepository([$exercise]); |
| 62 | + |
| 63 | + $runnerManager = $this->prophesize(RunnerManager::class); |
| 64 | + |
| 65 | + $event = new Event('some-event', ['command' => $command]); |
| 66 | + (new ConfigureCommandListener($state, $repo, $runnerManager->reveal()))->__invoke($event); |
| 67 | + |
| 68 | + $runnerManager->configureInput($exercise, $command)->shouldNotHaveBeenCalled(); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @return array |
| 73 | + */ |
| 74 | + public function nonConfigurableCommands() |
| 75 | + { |
| 76 | + return [ |
| 77 | + ['print'], |
| 78 | + ['help'], |
| 79 | + ['credits'], |
| 80 | + ['menu'], |
| 81 | + ]; |
| 82 | + } |
| 83 | +} |
0 commit comments