77use Kadet \Highlighter \KeyLighter ;
88use Kadet \Highlighter \Language \Php ;
99use PhpSchool \PhpWorkshopTest \Asset \CliExerciseImpl ;
10+ use PhpSchool \PhpWorkshopTest \BaseTest ;
1011use PhpSchool \Terminal \Terminal ;
1112use PhpSchool \PhpWorkshop \Exercise \ExerciseInterface ;
1213use PhpSchool \PhpWorkshop \Exercise \ProvidesSolution ;
2223use PhpSchool \PhpWorkshop \UserState ;
2324use PHPUnit \Framework \TestCase ;
2425
25- class ResultsRendererTest extends TestCase
26+ class ResultsRendererTest extends BaseTest
2627{
2728 public function testRenderIndividualResult (): void
2829 {
@@ -118,9 +119,7 @@ public function testRenderSuccessWithSolution(): void
118119 $ exerciseRepo = $ this ->createMock (ExerciseRepository::class);
119120 $ exerciseRepo ->method ('count ' )->willReturn (2 );
120121
121- $ tmpFile = sprintf ('%s/%s/some-file ' , sys_get_temp_dir (), $ this ->getName ());
122- mkdir (dirname ($ tmpFile ));
123- file_put_contents ($ tmpFile , 'FILE CONTENTS ' );
122+ $ tmpFile = $ this ->getTemporaryFile ('some-file ' , 'FILE CONTENTS ' );
124123
125124 $ exercise = new CliExerciseImpl ();
126125 $ exercise ->setSolution (new SingleFileSolution ($ tmpFile ));
@@ -146,9 +145,6 @@ public function testRenderSuccessWithSolution(): void
146145 new UserState (['exercise1 ' ]),
147146 new StdOutput ($ color , $ terminal )
148147 );
149-
150- unlink ($ tmpFile );
151- rmdir (dirname ($ tmpFile ));
152148 }
153149
154150 public function testRenderSuccessWithPhpSolutionFileIsSyntaxHighlighted (): void
@@ -164,9 +160,7 @@ public function testRenderSuccessWithPhpSolutionFileIsSyntaxHighlighted(): void
164160 $ exerciseRepo = $ this ->createMock (ExerciseRepository::class);
165161 $ exerciseRepo ->method ('count ' )->willReturn (2 );
166162
167- $ tmpFile = sprintf ('%s/%s/some-file.php ' , sys_get_temp_dir (), $ this ->getName ());
168- mkdir (dirname ($ tmpFile ));
169- file_put_contents ($ tmpFile , 'FILE CONTENTS ' );
163+ $ tmpFile = $ this ->getTemporaryFile ('some-file.php ' , 'FILE CONTENTS ' );
170164
171165 $ exercise = new CliExerciseImpl ();
172166 $ exercise ->setSolution (new SingleFileSolution ($ tmpFile ));
@@ -200,9 +194,6 @@ public function testRenderSuccessWithPhpSolutionFileIsSyntaxHighlighted(): void
200194 new UserState (['exercise1 ' ]),
201195 new StdOutput ($ color , $ terminal )
202196 );
203-
204- unlink ($ tmpFile );
205- rmdir (dirname ($ tmpFile ));
206197 }
207198
208199 public function testRenderSuccessAndFailure (): void
0 commit comments