|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AccessTests; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use CommonTestClass; |
|
7
|
|
|
use kalanis\kw_files\Access\CompositeAdapter; |
|
8
|
|
|
use kalanis\kw_files\Access\Factory; |
|
9
|
|
|
use kalanis\kw_files\FilesException; |
|
10
|
|
|
use kalanis\kw_paths\PathsException; |
|
11
|
|
|
use kalanis\kw_storage\Storage\Key\DefaultKey; |
|
12
|
|
|
use kalanis\kw_storage\Storage\Storage; |
|
13
|
|
|
use kalanis\kw_storage\Storage\Target\Memory; |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
class FactoryTest extends CommonTestClass |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @param $param |
|
20
|
|
|
* @throws FilesException |
|
21
|
|
|
* @throws PathsException |
|
22
|
|
|
* @dataProvider passProvider |
|
23
|
|
|
*/ |
|
24
|
|
|
public function testPass($param): void |
|
25
|
|
|
{ |
|
26
|
|
|
$lib = new Factory(); |
|
27
|
|
|
$this->assertInstanceOf(CompositeAdapter::class, $lib->getClass($param)); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function passProvider(): array |
|
31
|
|
|
{ |
|
32
|
|
|
$storage = new Storage(new DefaultKey(), new Memory()); |
|
33
|
|
|
return [ |
|
34
|
|
|
['somewhere'], |
|
35
|
|
|
[__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'tree'], |
|
36
|
|
|
[['path' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'tree']], |
|
37
|
|
|
[['source' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'tree']], |
|
38
|
|
|
[$storage], |
|
39
|
|
|
[['source' => $storage]], |
|
40
|
|
|
]; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param mixed $param |
|
45
|
|
|
* @throws PathsException |
|
46
|
|
|
* @throws FilesException |
|
47
|
|
|
* @dataProvider failProvider |
|
48
|
|
|
*/ |
|
49
|
|
|
public function testFail($param): void |
|
50
|
|
|
{ |
|
51
|
|
|
$lib = new Factory(); |
|
52
|
|
|
$this->expectException(FilesException::class); |
|
53
|
|
|
$lib->getClass($param); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function failProvider(): array |
|
57
|
|
|
{ |
|
58
|
|
|
return [ |
|
59
|
|
|
[true], |
|
60
|
|
|
[false], |
|
61
|
|
|
[null], |
|
62
|
|
|
[new \stdClass()], |
|
63
|
|
|
[['what' => 'irrelevant']], |
|
64
|
|
|
[['path' => []]], |
|
65
|
|
|
[['path' => null]], |
|
66
|
|
|
[['path' => new \stdClass()]], |
|
67
|
|
|
[['source' => []]], |
|
68
|
|
|
[['source' => null]], |
|
69
|
|
|
[['source' => new \stdClass()]], |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|