-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBaseTest.php
More file actions
51 lines (39 loc) 路 1.21 KB
/
Copy pathBaseTest.php
File metadata and controls
51 lines (39 loc) 路 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace PhpSchool\PhpWorkshopTest;
use PhpSchool\PhpWorkshop\Utils\Path;
use PhpSchool\PhpWorkshop\Utils\System;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Filesystem\Filesystem;
abstract class BaseTest extends TestCase
{
private $tempDirectory;
public function getTemporaryDirectory(): string
{
if (!$this->tempDirectory) {
$this->tempDirectory = System::tempDir($this->getName());
mkdir($this->tempDirectory, 0777, true);
}
return $this->tempDirectory;
}
public function getTemporaryFile(string $filename, string $content = null): string
{
$file = Path::join($this->getTemporaryDirectory(), $filename);
if (file_exists($file)) {
return $file;
}
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0777, true);
}
$content !== null
? file_put_contents($file, $content)
: touch($file);
return $file;
}
public function tearDown(): void
{
if (file_exists(System::tempDir($this->getName()))) {
(new Filesystem())->remove(System::tempDir($this->getName()));
}
}
}