Test Failed
Push — master ( a1b0fe...95c33d )
by Petr
10:27
created

VolumeCopyTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
namespace StorageTests;
4
5
6
use CommonTestClass;
7
use kalanis\kw_storage\Extras\TVolumeCopy;
8
9
10
class VolumeCopyTest extends CommonTestClass
11
{
12
    public function setUp(): void
13
    {
14
        parent::setUp();
15
        mkdir($this->getTestDir() . 'some');
16
        mkdir($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any');
17
        touch($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'tst1');
18
        touch($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2');
19
        touch($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3');
20
    }
21
22
    public function tearDown(): void
23
    {
24
        // copy
25
        if (is_file($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'tst1')) {
26
            unlink($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'tst1');
27
        }
28
        if (is_file($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2')) {
29
            unlink($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2');
30
        }
31
        if (is_file($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3')) {
32
            unlink($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3');
33
        }
34
        if (is_dir($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any')) {
35
            rmdir($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any');
36
        }
37
        if (is_dir($this->getTestDir() . 'other')) {
38
            rmdir($this->getTestDir() . 'other');
39
        }
40
        // original
41
        if (is_file($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'tst1')) {
42
            unlink($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'tst1');
43
        }
44
        if (is_file($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2')) {
45
            unlink($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2');
46
        }
47
        if (is_file($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3')) {
48
            unlink($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3');
49
        }
50
        if (is_dir($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any')) {
51
            rmdir($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any');
52
        }
53
        if (is_dir($this->getTestDir() . 'some')) {
54
            rmdir($this->getTestDir() . 'some');
55
        }
56
        parent::tearDown();
57
    }
58
59
    public function testCopy(): void
60
    {
61
        $volume = new XVolumeCopy();
62
        $this->assertTrue(file_exists($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'tst1'));
63
        $this->assertFalse(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'tst1'));
64
        $this->assertTrue(file_exists($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2'));
65
        $this->assertFalse(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2'));
66
        $this->assertTrue(file_exists($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3'));
67
        $this->assertFalse(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3'));
68
        $this->assertTrue($volume->copy($this->getTestDir() . 'some', $this->getTestDir() . 'other'));
69
        $this->assertTrue(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'tst1'));
70
        $this->assertTrue(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2'));
71
        $this->assertTrue(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3'));
72
        $this->assertFalse($volume->copy($this->getTestDir() . 'unknown', $this->getTestDir() . 'target'));
73
    }
74
}
75
76
77
class XVolumeCopy
78
{
79
    use TVolumeCopy;
80
81
    public function copy(string $source, string $dest): bool
82
    {
83
        return $this->xcopy($source, $dest);
84
    }
85
}
86
87