77use PhpSchool \PhpWorkshop \Check \CodeParseCheck ;
88use PhpSchool \PhpWorkshop \Check \FileExistsCheck ;
99use PhpSchool \PhpWorkshop \Check \PhpLintCheck ;
10+ use PhpSchool \PhpWorkshop \Event \CliExecuteEvent ;
1011use PhpSchool \PhpWorkshop \Event \EventDispatcher ;
1112use PhpSchool \PhpWorkshop \Exception \SolutionExecutionException ;
1213use PhpSchool \PhpWorkshop \Exercise \ExerciseType ;
@@ -31,14 +32,20 @@ class CliRunnerTest extends PHPUnit_Framework_TestCase
3132 private $ runner ;
3233
3334 /**
34- * @var CliExerciseInterface
35+ * @var CliExerciseInterface|\PHPUnit_Framework_MockObject_MockObject
3536 */
3637 private $ exercise ;
3738
39+ /**
40+ * @var EventDispatcher
41+ */
42+ private $ eventDispatcher ;
43+
3844 public function setUp ()
3945 {
4046 $ this ->exercise = $ this ->createMock (CliExerciseInterface::class);
41- $ this ->runner = new CliRunner ($ this ->exercise , new EventDispatcher (new ResultAggregator ));
47+ $ this ->eventDispatcher = new EventDispatcher (new ResultAggregator );
48+ $ this ->runner = new CliRunner ($ this ->exercise , $ this ->eventDispatcher );
4249
4350 $ this ->exercise
4451 ->expects ($ this ->any ())
@@ -214,4 +221,30 @@ public function testRunPassesOutputAndReturnsFailureIfScriptFails()
214221 $ success = $ this ->runner ->run (new Input ('app ' , ['program ' => __DIR__ . '/../res/cli/user-error.php ' ]), $ output );
215222 $ this ->assertFalse ($ success );
216223 }
224+
225+ public function testsArgsAppendedByEventsArePassedToResults ()
226+ {
227+ $ this ->eventDispatcher ->listen (['cli.verify.student-execute.pre ' , 'cli.verify.reference-execute.pre ' ], function (CliExecuteEvent $ e ) {
228+ $ e ->appendArg ('4 ' );
229+ });
230+
231+ $ solution = SingleFileSolution::fromFile (realpath (__DIR__ . '/../res/cli/solution.php ' ));
232+ $ this ->exercise
233+ ->expects ($ this ->once ())
234+ ->method ('getSolution ' )
235+ ->will ($ this ->returnValue ($ solution ));
236+
237+ $ this ->exercise
238+ ->expects ($ this ->once ())
239+ ->method ('getArgs ' )
240+ ->will ($ this ->returnValue ([1 , 2 , 3 ]));
241+
242+ $ this ->assertInstanceOf (
243+ CliResult::class,
244+ $ res = $ this ->runner ->verify (new Input ('app ' , ['program ' => __DIR__ . '/../res/cli/user.php ' ]))
245+ );
246+
247+ $ this ->assertTrue ($ res ->isSuccessful ());
248+ $ this ->assertEquals ([1 , 2 , 3 , 4 ], $ res ->getResults ()[0 ]->getArgs ()->getArrayCopy ());
249+ }
217250}
0 commit comments