From 9b72245db3263c25c5bb88bfb74f5075a0cf6822 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Fri, 25 Nov 2016 10:47:02 +0100 Subject: [PATCH 1/7] Custom Runner --- app/config.php | 2 + src/Exercise/CustomExercise.php | 16 ++++ src/Exercise/ExerciseType.php | 3 + src/ExerciseRunner/CustomRunner.php | 82 +++++++++++++++++++ .../Factory/CustomRunnerFactory.php | 54 ++++++++++++ test/Asset/ExtExerciseImpl.php | 55 +++++++++++++ test/ExerciseRunner/CustomRunnerTest.php | 54 ++++++++++++ .../Factory/CustomRunnerFactoryTest.php | 58 +++++++++++++ 8 files changed, 324 insertions(+) create mode 100644 src/Exercise/CustomExercise.php create mode 100644 src/ExerciseRunner/CustomRunner.php create mode 100644 src/ExerciseRunner/Factory/CustomRunnerFactory.php create mode 100644 test/Asset/ExtExerciseImpl.php create mode 100644 test/ExerciseRunner/CustomRunnerTest.php create mode 100644 test/ExerciseRunner/Factory/CustomRunnerFactoryTest.php diff --git a/app/config.php b/app/config.php index d82897da..92ce942b 100644 --- a/app/config.php +++ b/app/config.php @@ -22,6 +22,7 @@ use PhpSchool\PhpWorkshop\ExerciseDispatcher; use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CgiRunnerFactory; use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CliRunnerFactory; +use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CustomRunnerFactory; use PhpSchool\PhpWorkshop\ExerciseRunner\RunnerManager; use PhpSchool\PhpWorkshop\Factory\EventDispatcherFactory; use PhpSchool\PhpWorkshop\Factory\MenuFactory; @@ -125,6 +126,7 @@ $manager = new RunnerManager; $manager->addFactory(new CliRunnerFactory($c->get(EventDispatcher::class))); $manager->addFactory(new CgiRunnerFactory($c->get(EventDispatcher::class))); + $manager->addFactory(new CustomRunnerFactory); return $manager; }, diff --git a/src/Exercise/CustomExercise.php b/src/Exercise/CustomExercise.php new file mode 100644 index 00000000..de16ea01 --- /dev/null +++ b/src/Exercise/CustomExercise.php @@ -0,0 +1,16 @@ + + */ +interface CustomExercise +{ + /** + * @return ResultInterface + */ + public function verify(); +} diff --git a/src/Exercise/ExerciseType.php b/src/Exercise/ExerciseType.php index 893e27a5..e4e56591 100644 --- a/src/Exercise/ExerciseType.php +++ b/src/Exercise/ExerciseType.php @@ -20,6 +20,8 @@ class ExerciseType extends Enum { const CLI = 'CLI'; const CGI = 'CGI'; + const CUSTOM = 'CUSTOM'; + /** * Map of exercise types to the required interfaces exercises of that particular @@ -30,6 +32,7 @@ class ExerciseType extends Enum private static $exerciseTypeToExerciseInterfaceMap = [ self::CLI => CliExercise::class, self::CGI => CgiExercise::class, + self::CUSTOM => CustomExercise::class, ]; /** diff --git a/src/ExerciseRunner/CustomRunner.php b/src/ExerciseRunner/CustomRunner.php new file mode 100644 index 00000000..5977bedf --- /dev/null +++ b/src/ExerciseRunner/CustomRunner.php @@ -0,0 +1,82 @@ + + */ +class CustomRunner implements ExerciseRunnerInterface +{ + /** + * @var CustomExercise + */ + private $exercise; + + /** + * @param CustomExercise $exercise + */ + public function __construct(CustomExercise $exercise) + { + $this->exercise = $exercise; + } + + /** + * Get the name of the exercise runner. + * + * @return string + */ + public function getName() + { + return 'External Runner'; + } + + /** + * Get an array of the class names of the required checks this runner needs. + * + * @return array + */ + public function getRequiredChecks() + { + return []; + } + + /** + * Verify a solution to an exercise. Verification involves executing the reference solution + * and the student's solution and comparing their output. If the output is the same + * an instance of `PhpSchool\PhpWorkshop\Result\SuccessInterface` should be returned, if the output + * is not the same, or something else went wrong then an instance of + * `\PhpSchool\PhpWorkshop\Result\FailureInterface` should be returned. + * + * Other things that could go wrong include the student's solution returning a non-zero + * exit code, or a notice/warning being exhibited. + * + * @param Input $input The command line arguments passed to the command. + * @return ResultInterface The result of the check. + */ + public function verify(Input $input) + { + return $this->exercise->verify(); + } + + /** + * Run a solution to an exercise. This simply run's the student's solution with the correct input from the exercise + * (such as the CLI arguments) and prints the output directly. This allows the student to have the environment + * setup for them including getting a different set of arguments each time (if the exercise supports that). + * + * @param Input $input The command line arguments passed to the command. + * @param OutputInterface $output A wrapper around STDOUT. + * @return bool If the solution was successfully executed, eg. exit code was 0. + */ + public function run(Input $input, OutputInterface $output) + { + $message = 'Nothing to run here. This exercise does not require a code solution, '; + $message .= 'so there is nothing to execute.'; + $output->writeLine($message); + return true; + } +} diff --git a/src/ExerciseRunner/Factory/CustomRunnerFactory.php b/src/ExerciseRunner/Factory/CustomRunnerFactory.php new file mode 100644 index 00000000..0408f6e8 --- /dev/null +++ b/src/ExerciseRunner/Factory/CustomRunnerFactory.php @@ -0,0 +1,54 @@ + + */ +class CustomRunnerFactory implements ExerciseRunnerFactoryInterface +{ + /** + * @var string + */ + private static $type = ExerciseType::CUSTOM; + + /** + * Whether the factory supports this exercise type. + * + * @param ExerciseInterface $exercise + * @return bool + */ + public function supports(ExerciseInterface $exercise) + { + return $exercise->getType()->getValue() === self::$type; + } + + /** + * Add any extra required arguments to the command. + * + * @param CommandDefinition $commandDefinition + */ + public function configureInput(CommandDefinition $commandDefinition) + { + } + + /** + * Create and return an instance of the runner. + * + * @param ExerciseInterface $exercise + * @return ExerciseRunnerInterface + */ + public function create(ExerciseInterface $exercise) + { + return new CustomRunner($exercise); + } +} diff --git a/test/Asset/ExtExerciseImpl.php b/test/Asset/ExtExerciseImpl.php new file mode 100644 index 00000000..2949cd1c --- /dev/null +++ b/test/Asset/ExtExerciseImpl.php @@ -0,0 +1,55 @@ + + */ +class ExtExerciseImpl extends AbstractExercise implements ExerciseInterface, CustomExercise +{ + + /** + * Get the name of the exercise, like `Hello World!`. + * + * @return string + */ + public function getName() + { + return 'EXT exercise'; + } + + /** + * A short description of the exercise. + * + * @return string + */ + public function getDescription() + { + return 'EXT exercise'; + } + + /** + * Return the type of exercise. This is an ENUM. See `PhpSchool\PhpWorkshop\Exercise\ExerciseType`. + * + * @return ExerciseType + */ + public function getType() + { + return ExerciseType::EXT(); + } + + /** + * @return ResultInterface + */ + public function verify() + { + return new Success('success'); + } +} \ No newline at end of file diff --git a/test/ExerciseRunner/CustomRunnerTest.php b/test/ExerciseRunner/CustomRunnerTest.php new file mode 100644 index 00000000..eaae825b --- /dev/null +++ b/test/ExerciseRunner/CustomRunnerTest.php @@ -0,0 +1,54 @@ + + */ +class ExtRunnerTest extends PHPUnit_Framework_TestCase +{ + /** + * @var CustomRunner + */ + private $runner; + + /** + * @var ExtExerciseImpl + */ + private $exercise; + + public function setUp() + { + $this->exercise = new ExtExerciseImpl; + $this->runner = new CustomRunner($this->exercise); + + $this->assertEquals('External Runner', $this->runner->getName()); + } + + public function testRunOutputsErrorMessage() + { + $color = new Color; + $color->setForceStyle(true); + $output = new StdOutput($color, $this->createMock(TerminalInterface::class)); + + $exp = "Nothing to run here. This exercise does not require a code solution, "; + $exp .= "so there is nothing to execute.\n"; + + $this->expectOutputString($exp); + + $this->runner->run(new Input('app'), $output); + } + + public function testVerifyProxiesToExercise() + { + self::assertEquals($this->exercise->verify(), $this->runner->verify(new Input('app'))); + } +} \ No newline at end of file diff --git a/test/ExerciseRunner/Factory/CustomRunnerFactoryTest.php b/test/ExerciseRunner/Factory/CustomRunnerFactoryTest.php new file mode 100644 index 00000000..2453adcd --- /dev/null +++ b/test/ExerciseRunner/Factory/CustomRunnerFactoryTest.php @@ -0,0 +1,58 @@ + + */ +class CustomRunnerFactoryTest extends PHPUnit_Framework_TestCase +{ + /** + * @var CustomRunnerFactory + */ + private $factory; + + public function setUp() + { + $this->factory = new CustomRunnerFactory; + } + + public function testSupports() + { + $exercise1 = $this->prophesize(ExerciseInterface::class); + $exercise2 = $this->prophesize(ExerciseInterface::class); + $exercise3 = $this->prophesize(ExerciseInterface::class); + + $exercise1->getType()->willReturn(ExerciseType::CLI()); + $exercise2->getType()->willReturn(ExerciseType::CGI()); + $exercise3->getType()->willReturn(ExerciseType::CUSTOM()); + + $this->assertFalse($this->factory->supports($exercise1->reveal())); + $this->assertFalse($this->factory->supports($exercise2->reveal())); + $this->assertTrue($this->factory->supports($exercise3->reveal())); + } + + public function testConfigureInputAddsNoArgument() + { + $command = new CommandDefinition('my-command', [], 'var_dump'); + + $this->factory->configureInput($command); + $this->assertCount(0, $command->getRequiredArgs()); + } + + public function testCreateReturnsRunner() + { + $exercise = new ExtExerciseImpl; + $this->assertInstanceOf(CustomRunner::class, $this->factory->create($exercise)); + } +} From 2b789d81fb4c741c607543ab6bd3ef31cefb30c0 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Fri, 25 Nov 2016 18:07:59 +0100 Subject: [PATCH 2/7] cs --- test/Asset/ExtExerciseImpl.php | 2 +- test/ExerciseRunner/CustomRunnerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Asset/ExtExerciseImpl.php b/test/Asset/ExtExerciseImpl.php index 2949cd1c..a8021d83 100644 --- a/test/Asset/ExtExerciseImpl.php +++ b/test/Asset/ExtExerciseImpl.php @@ -52,4 +52,4 @@ public function verify() { return new Success('success'); } -} \ No newline at end of file +} diff --git a/test/ExerciseRunner/CustomRunnerTest.php b/test/ExerciseRunner/CustomRunnerTest.php index eaae825b..dbdad2cc 100644 --- a/test/ExerciseRunner/CustomRunnerTest.php +++ b/test/ExerciseRunner/CustomRunnerTest.php @@ -51,4 +51,4 @@ public function testVerifyProxiesToExercise() { self::assertEquals($this->exercise->verify(), $this->runner->verify(new Input('app'))); } -} \ No newline at end of file +} From 20c81838fe37f4c86efde2269ddc0fa208a3d449 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Sun, 27 Nov 2016 20:51:49 +0100 Subject: [PATCH 3/7] Rename custom runner --- ...Exercise.php => CustomVerifyingExercise.php} | 2 +- src/Exercise/ExerciseType.php | 2 +- ...stomRunner.php => CustomVerifyingRunner.php} | 12 ++++++------ ...ory.php => CustomVerifyingRunnerFactory.php} | 9 +++------ ...Impl.php => CustomVerifyingExerciseImpl.php} | 10 +++++----- ...erTest.php => CustomVerifyingRunnerTest.php} | 15 +++++++-------- .../Factory/CliRunnerFactoryTest.php | 2 -- ...php => CustomVerifyingRunnerFactoryTest.php} | 17 ++++++++--------- 8 files changed, 31 insertions(+), 38 deletions(-) rename src/Exercise/{CustomExercise.php => CustomVerifyingExercise.php} (87%) rename src/ExerciseRunner/{CustomRunner.php => CustomVerifyingRunner.php} (88%) rename src/ExerciseRunner/Factory/{CustomRunnerFactory.php => CustomVerifyingRunnerFactory.php} (78%) rename test/Asset/{ExtExerciseImpl.php => CustomVerifyingExerciseImpl.php} (76%) rename test/ExerciseRunner/{CustomRunnerTest.php => CustomVerifyingRunnerTest.php} (69%) rename test/ExerciseRunner/Factory/{CustomRunnerFactoryTest.php => CustomVerifyingRunnerFactoryTest.php} (73%) diff --git a/src/Exercise/CustomExercise.php b/src/Exercise/CustomVerifyingExercise.php similarity index 87% rename from src/Exercise/CustomExercise.php rename to src/Exercise/CustomVerifyingExercise.php index de16ea01..a3d4cbfc 100644 --- a/src/Exercise/CustomExercise.php +++ b/src/Exercise/CustomVerifyingExercise.php @@ -7,7 +7,7 @@ /** * @author Aydin Hassan */ -interface CustomExercise +interface CustomVerifyingExercise { /** * @return ResultInterface diff --git a/src/Exercise/ExerciseType.php b/src/Exercise/ExerciseType.php index e4e56591..d01575f6 100644 --- a/src/Exercise/ExerciseType.php +++ b/src/Exercise/ExerciseType.php @@ -32,7 +32,7 @@ class ExerciseType extends Enum private static $exerciseTypeToExerciseInterfaceMap = [ self::CLI => CliExercise::class, self::CGI => CgiExercise::class, - self::CUSTOM => CustomExercise::class, + self::CUSTOM => CustomVerifyingExercise::class, ]; /** diff --git a/src/ExerciseRunner/CustomRunner.php b/src/ExerciseRunner/CustomVerifyingRunner.php similarity index 88% rename from src/ExerciseRunner/CustomRunner.php rename to src/ExerciseRunner/CustomVerifyingRunner.php index 5977bedf..fc429b8a 100644 --- a/src/ExerciseRunner/CustomRunner.php +++ b/src/ExerciseRunner/CustomVerifyingRunner.php @@ -2,7 +2,7 @@ namespace PhpSchool\PhpWorkshop\ExerciseRunner; -use PhpSchool\PhpWorkshop\Exercise\CustomExercise; +use PhpSchool\PhpWorkshop\Exercise\CustomVerifyingExercise; use PhpSchool\PhpWorkshop\Input\Input; use PhpSchool\PhpWorkshop\Output\OutputInterface; use PhpSchool\PhpWorkshop\Result\ResultInterface; @@ -10,17 +10,17 @@ /** * @author Aydin Hassan */ -class CustomRunner implements ExerciseRunnerInterface +class CustomVerifyingRunner implements ExerciseRunnerInterface { /** - * @var CustomExercise + * @var CustomVerifyingExercise */ private $exercise; /** - * @param CustomExercise $exercise + * @param CustomVerifyingExercise $exercise */ - public function __construct(CustomExercise $exercise) + public function __construct(CustomVerifyingExercise $exercise) { $this->exercise = $exercise; } @@ -32,7 +32,7 @@ public function __construct(CustomExercise $exercise) */ public function getName() { - return 'External Runner'; + return 'Custom Verifying Runner'; } /** diff --git a/src/ExerciseRunner/Factory/CustomRunnerFactory.php b/src/ExerciseRunner/Factory/CustomVerifyingRunnerFactory.php similarity index 78% rename from src/ExerciseRunner/Factory/CustomRunnerFactory.php rename to src/ExerciseRunner/Factory/CustomVerifyingRunnerFactory.php index 0408f6e8..3645de7a 100644 --- a/src/ExerciseRunner/Factory/CustomRunnerFactory.php +++ b/src/ExerciseRunner/Factory/CustomVerifyingRunnerFactory.php @@ -2,19 +2,16 @@ namespace PhpSchool\PhpWorkshop\ExerciseRunner\Factory; -use PhpSchool\PhpWorkshop\CommandArgument; use PhpSchool\PhpWorkshop\CommandDefinition; -use PhpSchool\PhpWorkshop\Event\EventDispatcher; use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; use PhpSchool\PhpWorkshop\Exercise\ExerciseType; -use PhpSchool\PhpWorkshop\ExerciseRunner\CgiRunner; -use PhpSchool\PhpWorkshop\ExerciseRunner\CustomRunner; +use PhpSchool\PhpWorkshop\ExerciseRunner\CustomVerifyingRunner; use PhpSchool\PhpWorkshop\ExerciseRunner\ExerciseRunnerInterface; /** * @author Aydin Hassan */ -class CustomRunnerFactory implements ExerciseRunnerFactoryInterface +class CustomVerifyingRunnerFactory implements ExerciseRunnerFactoryInterface { /** * @var string @@ -49,6 +46,6 @@ public function configureInput(CommandDefinition $commandDefinition) */ public function create(ExerciseInterface $exercise) { - return new CustomRunner($exercise); + return new CustomVerifyingRunner($exercise); } } diff --git a/test/Asset/ExtExerciseImpl.php b/test/Asset/CustomVerifyingExerciseImpl.php similarity index 76% rename from test/Asset/ExtExerciseImpl.php rename to test/Asset/CustomVerifyingExerciseImpl.php index a8021d83..a715311b 100644 --- a/test/Asset/ExtExerciseImpl.php +++ b/test/Asset/CustomVerifyingExerciseImpl.php @@ -5,14 +5,14 @@ use PhpSchool\PhpWorkshop\Exercise\AbstractExercise; use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; use PhpSchool\PhpWorkshop\Exercise\ExerciseType; -use PhpSchool\PhpWorkshop\Exercise\CustomExercise; +use PhpSchool\PhpWorkshop\Exercise\CustomVerifyingExercise; use PhpSchool\PhpWorkshop\Result\ResultInterface; use PhpSchool\PhpWorkshop\Result\Success; /** * @author Aydin Hassan */ -class ExtExerciseImpl extends AbstractExercise implements ExerciseInterface, CustomExercise +class CustomVerifyingExerciseImpl extends AbstractExercise implements ExerciseInterface, CustomVerifyingExercise { /** @@ -22,7 +22,7 @@ class ExtExerciseImpl extends AbstractExercise implements ExerciseInterface, Cus */ public function getName() { - return 'EXT exercise'; + return 'Custom Verifying exercise'; } /** @@ -32,7 +32,7 @@ public function getName() */ public function getDescription() { - return 'EXT exercise'; + return 'Custom Verifying exercise'; } /** @@ -42,7 +42,7 @@ public function getDescription() */ public function getType() { - return ExerciseType::EXT(); + return ExerciseType::CUSTOM(); } /** diff --git a/test/ExerciseRunner/CustomRunnerTest.php b/test/ExerciseRunner/CustomVerifyingRunnerTest.php similarity index 69% rename from test/ExerciseRunner/CustomRunnerTest.php rename to test/ExerciseRunner/CustomVerifyingRunnerTest.php index dbdad2cc..fb9639f9 100644 --- a/test/ExerciseRunner/CustomRunnerTest.php +++ b/test/ExerciseRunner/CustomVerifyingRunnerTest.php @@ -4,10 +4,9 @@ use Colors\Color; use PhpSchool\CliMenu\Terminal\TerminalInterface; -use PhpSchool\PhpWorkshop\ExerciseDispatcher; use PhpSchool\PhpWorkshop\Input\Input; use PhpSchool\PhpWorkshop\Output\StdOutput; -use PhpSchool\PhpWorkshopTest\Asset\ExtExerciseImpl; +use PhpSchool\PhpWorkshopTest\Asset\CustomVerifyingExerciseImpl; use PHPUnit_Framework_TestCase; /** @@ -16,21 +15,21 @@ class ExtRunnerTest extends PHPUnit_Framework_TestCase { /** - * @var CustomRunner + * @var CustomVerifyingRunner */ private $runner; /** - * @var ExtExerciseImpl + * @var CustomVerifyingExerciseImpl */ private $exercise; public function setUp() { - $this->exercise = new ExtExerciseImpl; - $this->runner = new CustomRunner($this->exercise); + $this->exercise = new CustomVerifyingExerciseImpl; + $this->runner = new CustomVerifyingRunner($this->exercise); - $this->assertEquals('External Runner', $this->runner->getName()); + $this->assertEquals('Custom Verifying Runner', $this->runner->getName()); } public function testRunOutputsErrorMessage() @@ -39,7 +38,7 @@ public function testRunOutputsErrorMessage() $color->setForceStyle(true); $output = new StdOutput($color, $this->createMock(TerminalInterface::class)); - $exp = "Nothing to run here. This exercise does not require a code solution, "; + $exp = 'Nothing to run here. This exercise does not require a code solution, '; $exp .= "so there is nothing to execute.\n"; $this->expectOutputString($exp); diff --git a/test/ExerciseRunner/Factory/CliRunnerFactoryTest.php b/test/ExerciseRunner/Factory/CliRunnerFactoryTest.php index f6469cc6..bff2134c 100644 --- a/test/ExerciseRunner/Factory/CliRunnerFactoryTest.php +++ b/test/ExerciseRunner/Factory/CliRunnerFactoryTest.php @@ -4,13 +4,11 @@ use PhpSchool\PhpWorkshop\CommandDefinition; use PhpSchool\PhpWorkshop\Event\EventDispatcher; -use PhpSchool\PhpWorkshop\Exercise\CliExercise; use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; use PhpSchool\PhpWorkshop\Exercise\ExerciseType; use PhpSchool\PhpWorkshop\ExerciseRunner\CliRunner; use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CliRunnerFactory; use PhpSchool\PhpWorkshopTest\Asset\CliExerciseImpl; -use PhpSchool\PhpWorkshopTest\Asset\CliExerciseInterface; use PHPUnit_Framework_TestCase; /** diff --git a/test/ExerciseRunner/Factory/CustomRunnerFactoryTest.php b/test/ExerciseRunner/Factory/CustomVerifyingRunnerFactoryTest.php similarity index 73% rename from test/ExerciseRunner/Factory/CustomRunnerFactoryTest.php rename to test/ExerciseRunner/Factory/CustomVerifyingRunnerFactoryTest.php index 2453adcd..ce5d8405 100644 --- a/test/ExerciseRunner/Factory/CustomRunnerFactoryTest.php +++ b/test/ExerciseRunner/Factory/CustomVerifyingRunnerFactoryTest.php @@ -3,13 +3,12 @@ namespace PhpSchool\PhpWorkshopTest\ExerciseRunner\Factory; use PhpSchool\PhpWorkshop\CommandDefinition; -use PhpSchool\PhpWorkshop\Event\EventDispatcher; -use PhpSchool\PhpWorkshop\Exercise\CustomExercise; +use PhpSchool\PhpWorkshop\Exercise\CustomVerifyingExercise; use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; use PhpSchool\PhpWorkshop\Exercise\ExerciseType; -use PhpSchool\PhpWorkshop\ExerciseRunner\CustomRunner; -use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CustomRunnerFactory; -use PhpSchool\PhpWorkshopTest\Asset\ExtExerciseImpl; +use PhpSchool\PhpWorkshop\ExerciseRunner\CustomVerifyingRunner; +use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CustomVerifyingRunnerFactory; +use PhpSchool\PhpWorkshopTest\Asset\CustomVerifyingExerciseImpl; use PHPUnit_Framework_TestCase; /** @@ -18,13 +17,13 @@ class CustomRunnerFactoryTest extends PHPUnit_Framework_TestCase { /** - * @var CustomRunnerFactory + * @var CustomVerifyingRunnerFactory */ private $factory; public function setUp() { - $this->factory = new CustomRunnerFactory; + $this->factory = new CustomVerifyingRunnerFactory; } public function testSupports() @@ -52,7 +51,7 @@ public function testConfigureInputAddsNoArgument() public function testCreateReturnsRunner() { - $exercise = new ExtExerciseImpl; - $this->assertInstanceOf(CustomRunner::class, $this->factory->create($exercise)); + $exercise = new CustomVerifyingExerciseImpl; + $this->assertInstanceOf(CustomVerifyingRunner::class, $this->factory->create($exercise)); } } From 2746dd34a0cfa6052f485a2d19a6cadb58df5bb1 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Sun, 27 Nov 2016 21:01:02 +0100 Subject: [PATCH 4/7] Fix config --- app/config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/config.php b/app/config.php index 92ce942b..c9430338 100644 --- a/app/config.php +++ b/app/config.php @@ -22,7 +22,7 @@ use PhpSchool\PhpWorkshop\ExerciseDispatcher; use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CgiRunnerFactory; use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CliRunnerFactory; -use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CustomRunnerFactory; +use PhpSchool\PhpWorkshop\ExerciseRunner\Factory\CustomVerifyingRunnerFactory; use PhpSchool\PhpWorkshop\ExerciseRunner\RunnerManager; use PhpSchool\PhpWorkshop\Factory\EventDispatcherFactory; use PhpSchool\PhpWorkshop\Factory\MenuFactory; @@ -126,7 +126,7 @@ $manager = new RunnerManager; $manager->addFactory(new CliRunnerFactory($c->get(EventDispatcher::class))); $manager->addFactory(new CgiRunnerFactory($c->get(EventDispatcher::class))); - $manager->addFactory(new CustomRunnerFactory); + $manager->addFactory(new CustomVerifyingRunnerFactory); return $manager; }, From 2efb7d69871e4428d2c85838daece9653666cf2f Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Sun, 27 Nov 2016 21:25:56 +0100 Subject: [PATCH 5/7] Fix patch revert listener --- app/config.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/config.php b/app/config.php index c9430338..ca78d61a 100644 --- a/app/config.php +++ b/app/config.php @@ -328,25 +328,25 @@ containerListener(CodePatchListener::class, 'patch'), ], 'cli.verify.finish' => [ - containerListener(CodePatchListener::class, 'patch'), + containerListener(CodePatchListener::class, 'revert'), ], 'cli.run.start' => [ containerListener(CodePatchListener::class, 'patch'), ], 'cli.run.finish' => [ - containerListener(CodePatchListener::class, 'patch'), + containerListener(CodePatchListener::class, 'revert'), ], 'cgi.verify.start' => [ containerListener(CodePatchListener::class, 'patch'), ], 'cgi.verify.finish' => [ - containerListener(CodePatchListener::class, 'patch'), + containerListener(CodePatchListener::class, 'revert'), ], 'cgi.run.start' => [ containerListener(CodePatchListener::class, 'patch'), ], 'cgi.run.finish' => [ - containerListener(CodePatchListener::class, 'patch'), + containerListener(CodePatchListener::class, 'revert'), ], ], 'self-check' => [ From 4a83de465fa65c52349d39221f6aa973f84fd703 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Sun, 27 Nov 2016 21:33:19 +0100 Subject: [PATCH 6/7] Test getRequiredChecks --- test/ExerciseRunner/CustomVerifyingRunnerTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/ExerciseRunner/CustomVerifyingRunnerTest.php b/test/ExerciseRunner/CustomVerifyingRunnerTest.php index fb9639f9..411297c0 100644 --- a/test/ExerciseRunner/CustomVerifyingRunnerTest.php +++ b/test/ExerciseRunner/CustomVerifyingRunnerTest.php @@ -32,6 +32,11 @@ public function setUp() $this->assertEquals('Custom Verifying Runner', $this->runner->getName()); } + public function testRequiredChecks() + { + $this->assertEquals([], $this->runner->getRequiredChecks()); + } + public function testRunOutputsErrorMessage() { $color = new Color; From f8b96bfd510f673cbecf6116c8c4aa33e7999669 Mon Sep 17 00:00:00 2001 From: Aydin Hassan Date: Mon, 28 Nov 2016 21:02:23 +0100 Subject: [PATCH 7/7] Update doc blocks --- src/ExerciseRunner/CustomVerifyingRunner.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/ExerciseRunner/CustomVerifyingRunner.php b/src/ExerciseRunner/CustomVerifyingRunner.php index fc429b8a..836db2e0 100644 --- a/src/ExerciseRunner/CustomVerifyingRunner.php +++ b/src/ExerciseRunner/CustomVerifyingRunner.php @@ -46,14 +46,8 @@ public function getRequiredChecks() } /** - * Verify a solution to an exercise. Verification involves executing the reference solution - * and the student's solution and comparing their output. If the output is the same - * an instance of `PhpSchool\PhpWorkshop\Result\SuccessInterface` should be returned, if the output - * is not the same, or something else went wrong then an instance of - * `\PhpSchool\PhpWorkshop\Result\FailureInterface` should be returned. - * - * Other things that could go wrong include the student's solution returning a non-zero - * exit code, or a notice/warning being exhibited. + * Delegate to the exercise for verifying. Verifying could mean checking that a program was installed or that some + * other arbitrary task was performed. * * @param Input $input The command line arguments passed to the command. * @return ResultInterface The result of the check. @@ -64,9 +58,8 @@ public function verify(Input $input) } /** - * Run a solution to an exercise. This simply run's the student's solution with the correct input from the exercise - * (such as the CLI arguments) and prints the output directly. This allows the student to have the environment - * setup for them including getting a different set of arguments each time (if the exercise supports that). + * Running a custom verifying exercise does nothing. There is no program required, therefore there is nothing + * to run. * * @param Input $input The command line arguments passed to the command. * @param OutputInterface $output A wrapper around STDOUT.