Skip to content

Commit

Permalink
Merge pull request #149 from php-school/exercise-runner-events
Browse files Browse the repository at this point in the history
Use more specific events
  • Loading branch information
AydinHassan authored Dec 10, 2016
2 parents 04405d4 + 7677a23 commit 11c72ff
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/ExerciseDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpSchool\PhpWorkshop\Check\SimpleCheckInterface;
use PhpSchool\PhpWorkshop\Event\Event;
use PhpSchool\PhpWorkshop\Event\EventDispatcher;
use PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent;
use PhpSchool\PhpWorkshop\Exception\CheckNotApplicableException;
use PhpSchool\PhpWorkshop\Exception\ExerciseNotConfiguredException;
use PhpSchool\PhpWorkshop\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -136,7 +137,7 @@ public function verify(ExerciseInterface $exercise, Input $input)
$this->requireCheck($requiredCheck);
}

$this->eventDispatcher->dispatch(new Event('verify.start', compact('exercise', 'input')));
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.start', $exercise, $input));

$this->validateChecks($this->checksToRunBefore, $exercise);
$this->validateChecks($this->checksToRunAfter, $exercise);
Expand All @@ -149,22 +150,22 @@ public function verify(ExerciseInterface $exercise, Input $input)
}
}

$this->eventDispatcher->dispatch(new Event('verify.pre.execute', compact('exercise', 'input')));
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.pre.execute', $exercise, $input));

try {
$this->results->add($runner->verify($input));
} finally {
$this->eventDispatcher->dispatch(new Event('verify.post.execute', compact('exercise', 'input')));
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.post.execute', $exercise, $input));
}

foreach ($this->checksToRunAfter as $check) {
$this->results->add($check->check($exercise, $input));
}

$this->eventDispatcher->dispatch(new Event('verify.post.check', compact('exercise', 'input')));
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.post.check', $exercise, $input));
$exercise->tearDown();

$this->eventDispatcher->dispatch(new Event('verify.finish', compact('exercise', 'input')));
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.finish', $exercise, $input));
return $this->results;
}

Expand All @@ -181,14 +182,14 @@ public function verify(ExerciseInterface $exercise, Input $input)
public function run(ExerciseInterface $exercise, Input $input, OutputInterface $output)
{
$exercise->configure($this);
$this->eventDispatcher->dispatch(new Event('run.start', compact('exercise', 'input')));
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('run.start', $exercise, $input));

try {
$exitStatus = $this->runnerManager
->getRunner($exercise)
->run($input, $output);
} finally {
$this->eventDispatcher->dispatch(new Event('run.finish', compact('exercise', 'input')));
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('run.finish', $exercise, $input));
}

return $exitStatus;
Expand Down

0 comments on commit 11c72ff

Please sign in to comment.