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
|
|
|
|