1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace GacelaTest\Unit\Framework\Config; |
6
|
|
|
|
7
|
|
|
use Gacela\Framework\Config\ConfigLoader; |
8
|
|
|
use Gacela\Framework\Config\ConfigReaderInterface; |
9
|
|
|
use Gacela\Framework\Config\GacelaFileConfig\GacelaConfigFile; |
10
|
|
|
use Gacela\Framework\Config\GacelaFileConfig\GacelaConfigItem; |
11
|
|
|
use Gacela\Framework\Config\PathFinderInterface; |
12
|
|
|
use Gacela\Framework\Config\PathNormalizerInterface; |
13
|
|
|
use PHPUnit\Framework\TestCase; |
14
|
|
|
|
15
|
|
|
final class ConfigInitTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
public function test_no_config(): void |
18
|
|
|
{ |
19
|
|
|
$configInit = new ConfigLoader( |
20
|
|
|
new GacelaConfigFile(), |
21
|
|
|
$this->createMock(PathFinderInterface::class), |
22
|
|
|
$this->createMock(PathNormalizerInterface::class), |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
self::assertSame([], $configInit->loadAll()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function test_one_reader_linked_to_unsupported_type_is_ignored(): void |
29
|
|
|
{ |
30
|
|
|
$pathFinder = $this->createMock(PathFinderInterface::class); |
31
|
|
|
$pathFinder->method('matchingPattern')->willReturn(['path1']); |
32
|
|
|
|
33
|
|
|
$configInit = new ConfigLoader( |
34
|
|
|
new GacelaConfigFile(), |
35
|
|
|
$pathFinder, |
36
|
|
|
$this->createMock(PathNormalizerInterface::class), |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
self::assertSame([], $configInit->loadAll()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function test_no_readers_returns_empty_array(): void |
43
|
|
|
{ |
44
|
|
|
$pathFinder = $this->createMock(PathFinderInterface::class); |
45
|
|
|
$pathFinder->method('matchingPattern')->willReturn(['path1']); |
46
|
|
|
|
47
|
|
|
$configInit = new ConfigLoader( |
48
|
|
|
new GacelaConfigFile(), |
49
|
|
|
$pathFinder, |
50
|
|
|
$this->createMock(PathNormalizerInterface::class), |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
self::assertSame([], $configInit->loadAll()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function test_read_single_config(): void |
57
|
|
|
{ |
58
|
|
|
$reader = $this->createStub(ConfigReaderInterface::class); |
59
|
|
|
$reader->method('read')->willReturn(['key' => 'value']); |
60
|
|
|
|
61
|
|
|
$gacelaConfigFile = (new GacelaConfigFile())->setConfigItems([ |
62
|
|
|
new GacelaConfigItem('path', 'path_local', $reader), |
63
|
|
|
]); |
64
|
|
|
|
65
|
|
|
$configInit = new ConfigLoader( |
66
|
|
|
$gacelaConfigFile, |
67
|
|
|
$this->createMock(PathFinderInterface::class), |
68
|
|
|
$this->createMock(PathNormalizerInterface::class), |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
self::assertSame(['key' => 'value'], $configInit->loadAll()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function test_read_multiple_config(): void |
75
|
|
|
{ |
76
|
|
|
$reader1 = $this->createStub(ConfigReaderInterface::class); |
77
|
|
|
$reader1->method('read')->willReturn(['key1' => 'value1']); |
78
|
|
|
|
79
|
|
|
$reader2 = $this->createStub(ConfigReaderInterface::class); |
80
|
|
|
$reader2->method('read')->willReturn(['key2' => 'value2']); |
81
|
|
|
|
82
|
|
|
$gacelaConfigFile = (new GacelaConfigFile())->setConfigItems([ |
83
|
|
|
new GacelaConfigItem('path', 'path_local', $reader1), |
84
|
|
|
new GacelaConfigItem('path', 'path_local', $reader2), |
85
|
|
|
]); |
86
|
|
|
|
87
|
|
|
$configInit = new ConfigLoader( |
88
|
|
|
$gacelaConfigFile, |
89
|
|
|
$this->createMock(PathFinderInterface::class), |
90
|
|
|
$this->createMock(PathNormalizerInterface::class), |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
self::assertSame([ |
94
|
|
|
'key1' => 'value1', |
95
|
|
|
'key2' => 'value2', |
96
|
|
|
], $configInit->loadAll()); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|