diff --git a/src/Exception/CouldNotRunException.php b/src/Exception/CouldNotRunException.php new file mode 100644 index 00000000..3a4b3c25 --- /dev/null +++ b/src/Exception/CouldNotRunException.php @@ -0,0 +1,28 @@ +failure = $failure; + parent::__construct('Could not run exercise'); + } + + public static function fromFailure(FailureInterface $failure): self + { + return new self($failure); + } + + public function getFailure(): FailureInterface + { + return $this->failure; + } +} diff --git a/src/ExerciseDispatcher.php b/src/ExerciseDispatcher.php index 4dbc6d3c..6d9348a6 100644 --- a/src/ExerciseDispatcher.php +++ b/src/ExerciseDispatcher.php @@ -6,6 +6,7 @@ use PhpSchool\PhpWorkshop\Check\CheckRepository; use PhpSchool\PhpWorkshop\Check\ListenableCheckInterface; +use PhpSchool\PhpWorkshop\Check\PhpLintCheck; use PhpSchool\PhpWorkshop\Check\SimpleCheckInterface; use PhpSchool\PhpWorkshop\Event\EventDispatcher; use PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent; @@ -16,6 +17,8 @@ use PhpSchool\PhpWorkshop\ExerciseRunner\RunnerManager; use PhpSchool\PhpWorkshop\Input\Input; use PhpSchool\PhpWorkshop\Output\OutputInterface; +use PhpSchool\PhpWorkshop\Result\FailureInterface; +use PhpSchool\PhpWorkshop\Exception\CouldNotRunException; /** * This class is used to verify/run a student's solution to an exercise. It routes to the correct @@ -179,6 +182,15 @@ public function verify(ExerciseInterface $exercise, Input $input): ResultAggrega public function run(ExerciseInterface $exercise, Input $input, OutputInterface $output): bool { $exercise->configure($this); + + /** @var PhpLintCheck $lint */ + $lint = $this->checkRepository->getByClass(PhpLintCheck::class); + $result = $lint->check($exercise, $input); + + if ($result instanceof FailureInterface) { + throw CouldNotRunException::fromFailure($result); + } + $this->eventDispatcher->dispatch(new ExerciseRunnerEvent('run.start', $exercise, $input)); try { diff --git a/test/ExerciseDispatcherTest.php b/test/ExerciseDispatcherTest.php index 019fa786..bab752ea 100644 --- a/test/ExerciseDispatcherTest.php +++ b/test/ExerciseDispatcherTest.php @@ -5,6 +5,7 @@ use PhpSchool\PhpWorkshop\Check\CheckInterface; use PhpSchool\PhpWorkshop\Check\CheckRepository; use PhpSchool\PhpWorkshop\Check\ListenableCheckInterface; +use PhpSchool\PhpWorkshop\Check\PhpLintCheck; use PhpSchool\PhpWorkshop\Check\SimpleCheckInterface; use PhpSchool\PhpWorkshop\Event\EventDispatcher; use PhpSchool\PhpWorkshop\Event\EventInterface; @@ -538,7 +539,7 @@ public function testRun(): void $runnerManager, new ResultAggregator(), new EventDispatcher(new ResultAggregator()), - new CheckRepository() + new CheckRepository([new PhpLintCheck()]) ); $this->assertTrue($exerciseDispatcher->run($exercise, $input, $output));