3
3
namespace PhpSchool \PhpWorkshopTest \Command ;
4
4
5
5
use Colors \Color ;
6
+ use PhpSchool \PhpWorkshop \Exercise \TemporaryDirectoryTrait ;
7
+ use PhpSchool \PhpWorkshopTest \BaseTest ;
6
8
use PhpSchool \Terminal \Terminal ;
7
9
use PhpSchool \PhpWorkshop \Command \RunCommand ;
8
10
use PhpSchool \PhpWorkshop \ExerciseDispatcher ;
13
15
use PhpSchool \PhpWorkshopTest \Asset \CliExerciseImpl ;
14
16
use PHPUnit \Framework \TestCase ;
15
17
16
- class RunCommandTest extends TestCase
18
+ class RunCommandTest extends BaseTest
17
19
{
18
20
public function test (): void
19
21
{
20
- $ input = new Input ('appName ' , ['program ' => 'solution.php ' ]);
22
+ $ input = new Input ('appName ' , ['program ' => $ this -> getTemporaryFile ( 'solution.php ' ) ]);
21
23
22
24
$ exercise = new CliExerciseImpl ();
23
25
$ repo = new ExerciseRepository ([$ exercise ]);
@@ -37,4 +39,28 @@ public function test(): void
37
39
$ command = new RunCommand ($ repo , $ dispatcher , $ state , $ output );
38
40
$ command ->__invoke ($ input );
39
41
}
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
+ }
40
66
}
0 commit comments