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
|
|
|
use kalanis\kw_storage\Translations; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class StorageTest extends CommonTestClass |
13
|
|
|
{ |
14
|
|
|
public function tearDown(): void |
15
|
|
|
{ |
16
|
|
|
$this->rmFile($this->mockTestFile('', false)); |
17
|
|
|
$this->rmDir($this->mockTestFile('', false)); |
18
|
|
|
parent::tearDown(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param string $what |
23
|
|
|
* @param mixed $in |
24
|
|
|
* @throws StorageException |
25
|
|
|
* @dataProvider factoryFillProvider |
26
|
|
|
*/ |
27
|
|
|
public function testFactoryFill(string $what, $in): void |
28
|
|
|
{ |
29
|
|
|
$factory = new Target\Factory(); |
30
|
|
|
$this->assertInstanceOf($what, $factory->getStorage($in)); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function factoryFillProvider(): array |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
|
|
[\TargetMock::class, new \TargetMock()], |
37
|
|
|
[Target\Memory::class, ['storage' => 'mem']], |
38
|
|
|
[Target\Memory::class, ['storage' => 'memory']], |
39
|
|
|
[Target\Memory::class, ['storage' => new Target\Memory()]], |
40
|
|
|
[Target\Memory::class, ['storage' => 'memory', 'lang' => new Translations()]], |
41
|
|
|
[Target\Volume::class, ['storage' => 'vol']], |
42
|
|
|
[Target\Volume::class, ['storage' => 'volume']], |
43
|
|
|
[Target\Volume::class, ['storage' => 'local']], |
44
|
|
|
[Target\Volume::class, ['storage' => 'drive']], |
45
|
|
|
[Target\VolumeTargetFlat::class, ['storage' => 'volume::flat']], |
46
|
|
|
[Target\VolumeTargetFlat::class, ['storage' => 'local::flat']], |
47
|
|
|
[Target\VolumeTargetFlat::class, ['storage' => 'drive::flat']], |
48
|
|
|
[Target\VolumeStream::class, ['storage' => 'volume::stream']], |
49
|
|
|
[Target\VolumeStream::class, ['storage' => 'local::stream']], |
50
|
|
|
[Target\VolumeStream::class, ['storage' => 'drive::stream']], |
51
|
|
|
[Target\Memory::class, 'mem'], |
52
|
|
|
[Target\Memory::class, 'memory'], |
53
|
|
|
[Target\Volume::class, 'vol'], |
54
|
|
|
[Target\Volume::class, 'volume'], |
55
|
|
|
[Target\Volume::class, 'local'], |
56
|
|
|
[Target\Volume::class, 'drive'], |
57
|
|
|
[Target\VolumeTargetFlat::class, 'volume::flat'], |
58
|
|
|
[Target\VolumeTargetFlat::class, 'local::flat'], |
59
|
|
|
[Target\VolumeTargetFlat::class, 'drive::flat'], |
60
|
|
|
[Target\VolumeStream::class, 'volume::stream'], |
61
|
|
|
[Target\VolumeStream::class, 'local::stream'], |
62
|
|
|
[Target\VolumeStream::class, 'drive::stream'], |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param mixed $in |
68
|
|
|
* @throws StorageException |
69
|
|
|
* @dataProvider factoryEmptyProvider |
70
|
|
|
*/ |
71
|
|
|
public function testFactoryEmpty($in): void |
72
|
|
|
{ |
73
|
|
|
$factory = new Target\Factory(); |
74
|
|
|
$this->assertEmpty($factory->getStorage($in)); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function factoryEmptyProvider(): array |
78
|
|
|
{ |
79
|
|
|
return [ |
80
|
|
|
[[]], |
81
|
|
|
[['storage' => 'none']], |
82
|
|
|
[['storage' => new Translations()]], // not a storage |
83
|
|
|
['none'], |
84
|
|
|
['what'], |
85
|
|
|
[null], |
86
|
|
|
[false], |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @throws StorageException |
92
|
|
|
*/ |
93
|
|
|
public function testFactoryNotExists(): void |
94
|
|
|
{ |
95
|
|
|
$factory = new XFactory(); |
96
|
|
|
$this->expectException(StorageException::class); |
97
|
|
|
$factory->getStorage('not-exists'); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
class XFactory extends Target\Factory |
103
|
|
|
{ |
104
|
|
|
protected static $pairs = [ |
105
|
|
|
'memory' => Target\Memory::class, |
106
|
|
|
'none' => null, |
107
|
|
|
'not-exists' => 'this-class-does-not-exists', |
108
|
|
|
]; |
109
|
|
|
} |
110
|
|
|
|