Skip to content

Commit

Permalink
Merge pull request #148 from php-school/move-realpath-before-checks
Browse files Browse the repository at this point in the history
Realpath listener needs to run before checks
  • Loading branch information
AydinHassan authored Dec 10, 2016
2 parents 6a6d9e1 + bcba846 commit 04405d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
10 changes: 2 additions & 8 deletions app/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,12 @@ function (CgiResult $result) use ($c) {
'appContributors' => [],
'eventListeners' => [
'realpath-student-submission' => [
'cli.verify.start' => [
'verify.start' => [
containerListener(RealPathListener::class)
],
'cli.run.start' => [
'run.start' => [
containerListener(RealPathListener::class)
],
'cgi.verify.start' => [
containerListener(RealPathListener::class)
],
'cgi.run.start' => [
containerListener(RealPathListener::class)
]
],
'check-exercise-assigned' => [
'route.pre.resolve.args' => [
Expand Down
4 changes: 4 additions & 0 deletions src/Listener/RealPathListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class RealPathListener
*/
public function __invoke(ExerciseRunnerEvent $event)
{
if (!$event->getInput()->hasArgument('program')) {
return;
}

$program = $event->getInput()->getArgument('program');

if (file_exists($program)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace PhpSchool\PhpWorkshopTest;
namespace PhpSchool\PhpWorkshopTest\Listener;

use PhpSchool\PhpWorkshop\Event\Event;
use PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent;
Expand Down Expand Up @@ -45,11 +45,13 @@ public function testInputArgumentIsLeftUnchangedIfFileDoesNotExist()
$this->assertEquals('test-file.php', $input->getArgument('program'));
}

private function runInDir($dir, callable $callback)
public function testInputIsUnchangedIfNoProgramArgument()
{
$current = getcwd();
chdir($dir);
$callback($dir);
chdir($current);
$exercise = new CliExerciseImpl;
$input = new Input('app', ['some-arg' => 'some-value']);
$listener = new RealPathListener;
$listener->__invoke(new ExerciseRunnerEvent('some.event', $exercise, $input));

$this->assertEquals('some-value', $input->getArgument('some-arg'));
}
}

0 comments on commit 04405d4

Please sign in to comment.