Skip to content

Commit 9a54e80

Browse files
committed
Refactor test to use utils
1 parent ddf0c5b commit 9a54e80

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

test/ResultRenderer/ResultsRendererTest.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Kadet\Highlighter\KeyLighter;
88
use Kadet\Highlighter\Language\Php;
99
use PhpSchool\PhpWorkshopTest\Asset\CliExerciseImpl;
10+
use PhpSchool\PhpWorkshopTest\BaseTest;
1011
use PhpSchool\Terminal\Terminal;
1112
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
1213
use PhpSchool\PhpWorkshop\Exercise\ProvidesSolution;
@@ -22,7 +23,7 @@
2223
use PhpSchool\PhpWorkshop\UserState;
2324
use 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

Comments
 (0)