Passed
Push — master ( b3ffae...cd504b )
by Petr
02:40
created

VolumeCopyTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 8 1
A tearDown() 0 15 1
A testCopy() 0 14 1
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
        $this->rmFile('other' . DIRECTORY_SEPARATOR . 'tst1');
26
        $this->rmFile('other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2');
27
        $this->rmFile('other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3');
28
        $this->rmDir('other' . DIRECTORY_SEPARATOR . 'any');
29
        $this->rmDir('other');
30
        // original
31
        $this->rmFile('some' . DIRECTORY_SEPARATOR . 'tst1');
32
        $this->rmFile('some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2');
33
        $this->rmFile('some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3');
34
        $this->rmDir('some' . DIRECTORY_SEPARATOR . 'any');
35
        $this->rmDir('some');
36
        parent::tearDown();
37
    }
38
39
    public function testCopy(): void
40
    {
41
        $volume = new XVolumeCopy();
42
        $this->assertTrue(file_exists($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'tst1'));
43
        $this->assertFalse(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'tst1'));
44
        $this->assertTrue(file_exists($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2'));
45
        $this->assertFalse(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2'));
46
        $this->assertTrue(file_exists($this->getTestDir() . 'some' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3'));
47
        $this->assertFalse(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3'));
48
        $this->assertTrue($volume->copy($this->getTestDir() . 'some', $this->getTestDir() . 'other'));
49
        $this->assertTrue(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'tst1'));
50
        $this->assertTrue(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst2'));
51
        $this->assertTrue(file_exists($this->getTestDir() . 'other' . DIRECTORY_SEPARATOR . 'any' . DIRECTORY_SEPARATOR . 'tst3'));
52
        $this->assertFalse($volume->copy($this->getTestDir() . 'unknown', $this->getTestDir() . 'target'));
53
    }
54
}
55
56
57
class XVolumeCopy
58
{
59
    use TVolumeCopy;
60
61
    public function copy(string $source, string $dest): bool
62
    {
63
        return $this->xcopy($source, $dest);
64
    }
65
}
66
67