33namespace PhpSchool \PhpWorkshopTest \Command ;
44
55use Colors \Color ;
6+ use PhpSchool \PhpWorkshop \Exercise \TemporaryDirectoryTrait ;
7+ use PhpSchool \PhpWorkshopTest \BaseTest ;
68use PhpSchool \Terminal \Terminal ;
79use PhpSchool \PhpWorkshop \Command \RunCommand ;
810use PhpSchool \PhpWorkshop \ExerciseDispatcher ;
1315use PhpSchool \PhpWorkshopTest \Asset \CliExerciseImpl ;
1416use PHPUnit \Framework \TestCase ;
1517
16- class RunCommandTest extends TestCase
18+ class RunCommandTest extends BaseTest
1719{
1820 public function test (): void
1921 {
20- $ input = new Input ('appName ' , ['program ' => 'solution.php ' ]);
22+ $ input = new Input ('appName ' , ['program ' => $ this -> getTemporaryFile ( 'solution.php ' ) ]);
2123
2224 $ exercise = new CliExerciseImpl ();
2325 $ repo = new ExerciseRepository ([$ exercise ]);
@@ -37,4 +39,28 @@ public function test(): void
3739 $ command = new RunCommand ($ repo , $ dispatcher , $ state , $ output );
3840 $ command ->__invoke ($ input );
3941 }
42+
43+ public function testWithNonExistingFile (): void
44+ {
45+ $ input = new Input ('appName ' , ['program ' => 'solution.php ' ]);
46+
47+ $ exercise = new CliExerciseImpl ();
48+ $ repo = new ExerciseRepository ([$ exercise ]);
49+
50+ $ state = new UserState ();
51+ $ state ->setCurrentExercise ('my-exercise ' );
52+ $ color = new Color ();
53+ $ color ->setForceStyle (true );
54+ $ output = new StdOutput ($ color , $ this ->createMock (Terminal::class));
55+
56+ $ dispatcher = $ this ->createMock (ExerciseDispatcher::class);
57+ $ dispatcher
58+ ->expects ($ this ->never ())
59+ ->method ('run ' );
60+
61+ $ this ->expectOutputString (file_get_contents (__DIR__ . '/../res/app-run-missing-solution-expected.txt ' ));
62+
63+ $ command = new RunCommand ($ repo , $ dispatcher , $ state , $ output );
64+ $ command ->__invoke ($ input );
65+ }
4066}
0 commit comments