Skip to content

Commit 6d3f0b7

Browse files
authored
Merge pull request #204 from php-school/base-test-improv
Add getTemporaryFile method to base test class
2 parents 70b5c6e + 1125280 commit 6d3f0b7

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

test/BaseTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpSchool\PhpWorkshopTest;
66

7+
use PhpSchool\PhpWorkshop\Utils\Path;
78
use PHPUnit\Framework\TestCase;
89
use Symfony\Component\Filesystem\Filesystem;
910

@@ -23,6 +24,20 @@ public function getTemporaryDirectory(): string
2324
return $this->tempDirectory;
2425
}
2526

27+
public function getTemporaryFile(string $filename): string
28+
{
29+
$file = Path::join($this->getTemporaryDirectory(), $filename);
30+
31+
if (file_exists($file)) {
32+
return $file;
33+
}
34+
35+
@mkdir(dirname($file), 0777, true);
36+
touch($file);
37+
38+
return $file;
39+
}
40+
2641
public function tearDown(): void
2742
{
2843
if ($this->tempDirectory) {

0 commit comments

Comments
 (0)