|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace StorageTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_storage\Storage\Target; |
|
8
|
|
|
use kalanis\kw_storage\StorageException; |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class VolumeDeepTest extends CommonTestClass |
|
12
|
|
|
{ |
|
13
|
|
|
public function tearDown(): void |
|
14
|
|
|
{ |
|
15
|
|
|
$this->rmFile($this->mockTestFile('', false)); |
|
16
|
|
|
$this->rmFile($this->mockTestFile('2', false)); |
|
17
|
|
|
$this->rmFile($this->mockTestFile('3', false)); |
|
18
|
|
|
$this->rmFile($this->mockTestFile('4', false)); |
|
19
|
|
|
$this->rmFile($this->mockTestFile('5', false)); |
|
20
|
|
|
$this->rmDir($this->mockTestFile('', false)); |
|
21
|
|
|
$this->rmDir('some'); |
|
22
|
|
|
parent::tearDown(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @throws StorageException |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testLookup(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$volume = new Target\VolumeTargetFlat(); |
|
31
|
|
|
$this->assertTrue($volume->check($this->getTestDir())); |
|
32
|
|
|
$testFiles = [ |
|
33
|
|
|
'dummyFile.tst' => $this->getTestDir() . 'dummyFile.tst', |
|
34
|
|
|
'dummyFile.0.tst' => $this->getTestDir() . 'dummyFile.0.tst', |
|
35
|
|
|
'dummyFile.1.tst' => $this->getTestDir() . 'dummyFile.1.tst', |
|
36
|
|
|
'dummyFile.2.tst' => $this->getTestDir() . 'dummyFile.2.tst', |
|
37
|
|
|
]; |
|
38
|
|
|
$removal = $volume->removeMulti($testFiles); |
|
39
|
|
|
$this->assertEquals([ |
|
40
|
|
|
'dummyFile.tst' => false, |
|
41
|
|
|
'dummyFile.0.tst' => false, |
|
42
|
|
|
'dummyFile.1.tst' => false, |
|
43
|
|
|
'dummyFile.2.tst' => false, |
|
44
|
|
|
], $removal); |
|
45
|
|
|
|
|
46
|
|
|
file_put_contents($this->getTestDir() . 'dummyFile.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
|
47
|
|
|
file_put_contents($this->getTestDir() . 'dummyFile.0.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
|
48
|
|
|
file_put_contents($this->getTestDir() . 'dummyFile.1.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
|
49
|
|
|
file_put_contents($this->getTestDir() . 'dummyFile.2.tst', 'asdfghjklqwertzuiopyxcvbnm'); |
|
50
|
|
|
|
|
51
|
|
|
// non-existent path |
|
52
|
|
|
$this->assertEquals(0, count(array_filter(array_filter(iterator_to_array($volume->lookup('this path does not exists'))), [$this, 'dotDirs']))); |
|
53
|
|
|
|
|
54
|
|
|
// empty path - must show everything |
|
55
|
|
|
// 5 -> + gitkeep; but here goes into exec path, so the results are environment-dependent |
|
56
|
|
|
// $this->assertEquals(5, count(array_filter(array_filter(iterator_to_array($volume->lookup(''))), [$this, 'dotDirs']))); |
|
57
|
|
|
|
|
58
|
|
|
$files = iterator_to_array($volume->lookup($this->getTestDir())); |
|
59
|
|
|
sort($files); |
|
60
|
|
|
$files = array_filter(array_filter($files), [$this, 'dotDirs']); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertEquals(count($testFiles) + 1, count($files)); // because gitkeep |
|
63
|
|
|
$this->assertEquals(DIRECTORY_SEPARATOR . '.gitkeep', reset($files)); |
|
64
|
|
|
$this->assertEquals(DIRECTORY_SEPARATOR . 'dummyFile.0.tst', next($files)); |
|
65
|
|
|
$this->assertEquals(DIRECTORY_SEPARATOR . 'dummyFile.1.tst', next($files)); |
|
66
|
|
|
$this->assertEquals(DIRECTORY_SEPARATOR . 'dummyFile.2.tst', next($files)); |
|
67
|
|
|
$this->assertEquals(DIRECTORY_SEPARATOR . 'dummyFile.tst', next($files)); |
|
68
|
|
|
|
|
69
|
|
|
$removal = $volume->removeMulti($testFiles); |
|
70
|
|
|
$this->assertFalse($volume->exists($this->getTestDir() . 'dummyFile.tst')); |
|
71
|
|
|
$this->assertFalse($volume->exists($this->getTestDir() . 'dummyFile.0.tst')); |
|
72
|
|
|
$this->assertFalse($volume->exists($this->getTestDir() . 'dummyFile.1.tst')); |
|
73
|
|
|
$this->assertFalse($volume->exists($this->getTestDir() . 'dummyFile.2.tst')); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEquals([ |
|
76
|
|
|
'dummyFile.tst' => true, |
|
77
|
|
|
'dummyFile.0.tst' => true, |
|
78
|
|
|
'dummyFile.1.tst' => true, |
|
79
|
|
|
'dummyFile.2.tst' => true, |
|
80
|
|
|
], $removal); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function dotDirs(string $path): bool |
|
84
|
|
|
{ |
|
85
|
|
|
return !in_array($path, ['.', '..', DIRECTORY_SEPARATOR . '.', DIRECTORY_SEPARATOR . '..']); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|