Completed
Push — master ( 4a880d...b27be8 )
by Zach
10:27 queued 09:16
created

BaseTestCase::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
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