Passed
Push — master ( 15bdaa...c2dfbc )
by Saulius
10:02
created

FilesystemTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1
1
<?php
2
/**
3
 * This file is part of the sauls/helpers package.
4
 *
5
 * @author    Saulius Vaičeliūnas <[email protected]>
6
 * @link      http://saulius.vaiceliunas.lt
7
 * @copyright 2018
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Sauls\Component\Helper;
14
15
use PHPUnit\Framework\TestCase;
16
17
class FilesystemTest extends TestCase
18
{
19
    /**
20
     * SetUp
21
     */
22
    protected function setUp()
23
    {
24
        $directory = $this->getTestDirectory();
25
26
        if (!file_exists($directory)) {
27
            mkdir($directory);
28
29
            mkdir($directory.'/test1');
30
            mkdir($directory.'/test2');
31
            touch($directory.'/test2/testfile1');
32
            touch($directory.'/test2/testfile2');
33
            mkdir($directory.'/test3');
34
            touch($directory.'/test3/testfile1');
35
        }
36
    }
37
38
    /**
39
     * TearDown
40
     */
41
    protected function tearDown()
42
    {
43
        $directory = $this->getTestDirectory();
44
45
        if (file_exists($directory)) {
46
            rrmdir($directory);
47
        }
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    protected function getTestDirectory()
54
    {
55
        return __DIR__ . '/tmp';
56
    }
57
58
    /**
59
     * @test
60
     */
61
    public function should_remove_directories()
62
    {
63
        $directory = $this->getTestDirectory();
64
        
65
        $this->assertTrue(rrmdir($directory.'/test2'));
66
        $this->assertFileExists($directory.'/test1');
67
        $this->assertFileNotExists($directory.'/test2/testfile1');
68
        $this->assertFileNotExists($directory.'/test2/testfile2');
69
        $this->assertFileNotExists($directory.'/test2');
70
        $this->assertFileExists($directory.'/test3/testfile1');
71
        $this->assertFalse(rrmdir($directory.'/test3/testfile1'));
72
        $this->assertTrue(rrmdir($directory));
73
        $this->assertFileNotExists($directory);
74
    }
75
}
76