|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PhpSchool\PhpWorkshop\ExerciseRunner; |
| 4 | + |
| 5 | +use PhpSchool\PhpWorkshop\Exercise\CustomExercise; |
| 6 | +use PhpSchool\PhpWorkshop\Input\Input; |
| 7 | +use PhpSchool\PhpWorkshop\Output\OutputInterface; |
| 8 | +use PhpSchool\PhpWorkshop\Result\ResultInterface; |
| 9 | + |
| 10 | +/** |
| 11 | + * @author Aydin Hassan <aydin@hotmail.co.uk> |
| 12 | + */ |
| 13 | +class CustomRunner implements ExerciseRunnerInterface |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var CustomExercise |
| 17 | + */ |
| 18 | + private $exercise; |
| 19 | + |
| 20 | + /** |
| 21 | + * @param CustomExercise $exercise |
| 22 | + */ |
| 23 | + public function __construct(CustomExercise $exercise) |
| 24 | + { |
| 25 | + $this->exercise = $exercise; |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Get the name of the exercise runner. |
| 30 | + * |
| 31 | + * @return string |
| 32 | + */ |
| 33 | + public function getName() |
| 34 | + { |
| 35 | + return 'External Runner'; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Get an array of the class names of the required checks this runner needs. |
| 40 | + * |
| 41 | + * @return array |
| 42 | + */ |
| 43 | + public function getRequiredChecks() |
| 44 | + { |
| 45 | + return []; |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Verify a solution to an exercise. Verification involves executing the reference solution |
| 50 | + * and the student's solution and comparing their output. If the output is the same |
| 51 | + * an instance of `PhpSchool\PhpWorkshop\Result\SuccessInterface` should be returned, if the output |
| 52 | + * is not the same, or something else went wrong then an instance of |
| 53 | + * `\PhpSchool\PhpWorkshop\Result\FailureInterface` should be returned. |
| 54 | + * |
| 55 | + * Other things that could go wrong include the student's solution returning a non-zero |
| 56 | + * exit code, or a notice/warning being exhibited. |
| 57 | + * |
| 58 | + * @param Input $input The command line arguments passed to the command. |
| 59 | + * @return ResultInterface The result of the check. |
| 60 | + */ |
| 61 | + public function verify(Input $input) |
| 62 | + { |
| 63 | + return $this->exercise->verify(); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * Run a solution to an exercise. This simply run's the student's solution with the correct input from the exercise |
| 68 | + * (such as the CLI arguments) and prints the output directly. This allows the student to have the environment |
| 69 | + * setup for them including getting a different set of arguments each time (if the exercise supports that). |
| 70 | + * |
| 71 | + * @param Input $input The command line arguments passed to the command. |
| 72 | + * @param OutputInterface $output A wrapper around STDOUT. |
| 73 | + * @return bool If the solution was successfully executed, eg. exit code was 0. |
| 74 | + */ |
| 75 | + public function run(Input $input, OutputInterface $output) |
| 76 | + { |
| 77 | + $message = 'Nothing to run here. This exercise does not require a code solution, '; |
| 78 | + $message .= 'so there is nothing to execute.'; |
| 79 | + $output->writeLine($message); |
| 80 | + return true; |
| 81 | + } |
| 82 | +} |
0 commit comments