1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EntriesSourceTests; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_menu\EntriesSource; |
7
|
|
|
use kalanis\kw_menu\MenuException; |
8
|
|
|
use kalanis\kw_paths\PathsException; |
9
|
|
|
use kalanis\kw_storage\Storage\Key; |
10
|
|
|
use kalanis\kw_storage\Storage\Storage; |
11
|
|
|
use kalanis\kw_storage\Storage\Target; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
class StorageTest extends \CommonTestClass |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @throws MenuException |
18
|
|
|
* @throws PathsException |
19
|
|
|
*/ |
20
|
|
|
public function testGetFiles(): void |
21
|
|
|
{ |
22
|
|
|
$lib = $this->getLib(); |
23
|
|
|
$iter = $lib->getFiles([]); |
24
|
|
|
$files = iterator_to_array($iter); |
25
|
|
|
$this->assertTrue(in_array('dummy4.htm', $files)); |
26
|
|
|
$this->assertFalse(in_array('dummy5.htm', $files)); |
27
|
|
|
|
28
|
|
|
$iter2 = $lib->getFiles(['dummy3']); |
29
|
|
|
$files2 = iterator_to_array($iter2); |
30
|
|
|
$this->assertFalse(in_array('dummy4.htm', $files2)); |
31
|
|
|
$this->assertTrue(in_array('dummy5.htm', $files2)); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @throws MenuException |
36
|
|
|
* @throws PathsException |
37
|
|
|
*/ |
38
|
|
|
public function testFailedLookup(): void |
39
|
|
|
{ |
40
|
|
|
$lib = $this->getFailLib(); |
41
|
|
|
$this->expectException(MenuException::class); |
42
|
|
|
iterator_to_array($lib->getFiles([])); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
protected function getLib(): EntriesSource\Storage |
46
|
|
|
{ |
47
|
|
|
Key\DirKey::setDir($this->getTargetPath()); |
48
|
|
|
return new EntriesSource\Storage(new Storage(new Key\DirKey(), new Target\Volume())); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function getFailLib(): EntriesSource\Storage |
52
|
|
|
{ |
53
|
|
|
return new EntriesSource\Storage(new \XFailStorage(new Key\DefaultKey(), new Target\Memory())); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|