Passed
Branch master (b27be8)
by Zach
01:12
created

BaseTestCase   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 9
1
<?php
2
3
namespace Tests;
4
5
use PHPUnit\Framework\TestCase;
6
7
class BaseTestCase extends TestCase
8
{
9
    /**
10
     * Files created during tests that should be unlinked during tear down.
11
     *
12
     * @var array
13
     */
14
    protected $createdFiles = [];
15
16
    /**
17
     * Register a created file that should be unlinked during treardown.
18
     *
19
     * @param string $path
20
     *
21
     * @return void
22
     */
23
    protected function registerCreatedFile($path)
24
    {
25
        $this->createdFiles[] = $path;
26
    }
27
28
    /**
29
     * Unlink all registered files.
30
     *
31
     * @return void
32
     */
33
    protected function removeRegisteredFiles()
34
    {
35
        foreach ($this->createdFiles as $path) {
36
            if (is_dir($path)) {
37
                $dir = new \DirectoryIterator($path);
38
39
                foreach ($dir as $file) {
40
                    if (!$file->isDot()) {
41
                        unlink($file->getPathname());
42
                    }
43
                }
44
45
                rmdir($path);
46
            } elseif (file_exists($path)) {
47
                unlink($path);
48
            }
49
        }
50
    }
51
}
52