|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use kalanis\kw_storage\Interfaces; |
|
4
|
|
|
use kalanis\kw_storage\Storage; |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class CommonTestClass extends \PHPUnit\Framework\TestCase |
|
8
|
|
|
{ |
|
9
|
|
|
protected function rmDir(string $path): void |
|
10
|
|
|
{ |
|
11
|
|
|
if (is_dir($this->getTestDir() . $path)) { |
|
12
|
|
|
rmdir($this->getTestDir() . $path); |
|
13
|
|
|
} |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
protected function rmFile(string $path): void |
|
17
|
|
|
{ |
|
18
|
|
|
if (is_file($this->getTestDir() . $path)) { |
|
19
|
|
|
unlink($this->getTestDir() . $path); |
|
20
|
|
|
} |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
protected function mockTestFile(string $pos = '', bool $pre = true): string |
|
24
|
|
|
{ |
|
25
|
|
|
return ($pre ? $this->getTestDir() : '') . 'testingFile' . $pos . '.txt'; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
protected function getTestDir(): string |
|
29
|
|
|
{ |
|
30
|
|
|
return implode(DIRECTORY_SEPARATOR, [__DIR__, 'tmp', '']); |
|
31
|
|
|
} |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
class TargetMock implements \kalanis\kw_storage\Interfaces\IStorage |
|
36
|
|
|
{ |
|
37
|
|
|
public function check(string $key): bool |
|
38
|
|
|
{ |
|
39
|
|
|
return true; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function exists(string $key): bool |
|
43
|
|
|
{ |
|
44
|
|
|
return false; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function load(string $key) |
|
48
|
|
|
{ |
|
49
|
|
|
return 'dummy mock'; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function save(string $key, $data, ?int $timeout = null): bool |
|
53
|
|
|
{ |
|
54
|
|
|
return empty($timeout); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function remove(string $key): bool |
|
58
|
|
|
{ |
|
59
|
|
|
return false; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function lookup(string $path): \Traversable |
|
63
|
|
|
{ |
|
64
|
|
|
yield from []; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function increment(string $key): bool |
|
68
|
|
|
{ |
|
69
|
|
|
return true; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function decrement(string $key): bool |
|
73
|
|
|
{ |
|
74
|
|
|
return false; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function removeMulti(array $keys): array |
|
78
|
|
|
{ |
|
79
|
|
|
return []; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
class MockKey implements \kalanis\kw_storage\Interfaces\IKey |
|
85
|
|
|
{ |
|
86
|
|
|
public function fromSharedKey(string $key): string |
|
87
|
|
|
{ |
|
88
|
|
|
return implode(DIRECTORY_SEPARATOR, [__DIR__, 'tmp', $key]); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
class MockKeyFactory extends Storage\Key\Factory |
|
94
|
|
|
{ |
|
95
|
|
|
public function getKey(Interfaces\IStorage $storage): Interfaces\IKey |
|
96
|
|
|
{ |
|
97
|
|
|
return new MockKey(); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
|
|
102
|
|
|
class MockTargetFactory extends Storage\Target\Factory |
|
103
|
|
|
{ |
|
104
|
|
|
public function getStorage($params): Interfaces\IStorage |
|
105
|
|
|
{ |
|
106
|
|
|
return new \TargetMock(); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|