1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/config project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Daikon\Test\Config; |
10
|
|
|
|
11
|
|
|
use Daikon\Config\ArrayConfigLoader; |
12
|
|
|
use Daikon\Config\ConfigProviderParams; |
13
|
|
|
use Daikon\Interop\AssertionFailedException; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
|
16
|
|
|
final class ConfigProviderParamsTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
private const LOCATIONS_FIXTURE = ['location_one', 'location_two']; |
19
|
|
|
|
20
|
|
|
private const SOURCES_FIXTURE = [ |
21
|
|
|
'core' => [ |
22
|
|
|
'project_name' => 'Generic Project', |
23
|
|
|
'project_version' => '0.4.2' |
24
|
|
|
] |
25
|
|
|
]; |
26
|
|
|
|
27
|
1 |
|
public function testHasScope(): void |
28
|
|
|
{ |
29
|
1 |
|
$provider = new ConfigProviderParams([ |
30
|
|
|
'settings' => [ |
31
|
1 |
|
'loader' => ArrayConfigLoader::class, |
32
|
1 |
|
'sources' => self::SOURCES_FIXTURE |
33
|
|
|
] |
34
|
|
|
]); |
35
|
1 |
|
$this->assertTrue($provider->hasScope('settings')); |
36
|
1 |
|
$this->assertFalse($provider->hasScope('foobar')); |
37
|
1 |
|
} |
38
|
|
|
|
39
|
1 |
|
public function testGetLoader(): void |
40
|
|
|
{ |
41
|
1 |
|
$provider = new ConfigProviderParams([ |
42
|
|
|
'settings' => [ |
43
|
1 |
|
'loader' => ArrayConfigLoader::class, |
44
|
1 |
|
'sources' => self::SOURCES_FIXTURE |
45
|
|
|
] |
46
|
|
|
]); |
47
|
1 |
|
$this->assertInstanceOf(ArrayConfigLoader::class, $provider->getLoader('settings')); |
48
|
1 |
|
} |
49
|
|
|
|
50
|
1 |
|
public function testGetSources(): void |
51
|
|
|
{ |
52
|
1 |
|
$provider = new ConfigProviderParams([ |
53
|
|
|
'settings' => [ |
54
|
1 |
|
'loader' => ArrayConfigLoader::class, |
55
|
1 |
|
'sources' => self::SOURCES_FIXTURE |
56
|
|
|
] |
57
|
|
|
]); |
58
|
1 |
|
$this->assertEquals(self::SOURCES_FIXTURE, $provider->getSources('settings')); |
59
|
1 |
|
} |
60
|
|
|
|
61
|
1 |
|
public function testGetLocations(): void |
62
|
|
|
{ |
63
|
1 |
|
$provider = new ConfigProviderParams([ |
64
|
|
|
'settings' => [ |
65
|
1 |
|
'loader' => ArrayConfigLoader::class, |
66
|
|
|
'sources' => [], |
67
|
1 |
|
'locations' => self::LOCATIONS_FIXTURE |
68
|
|
|
] |
69
|
|
|
]); |
70
|
1 |
|
$this->assertEquals(self::LOCATIONS_FIXTURE, $provider->getLocations('settings')); |
71
|
1 |
|
} |
72
|
|
|
|
73
|
1 |
|
public function testEmptyParams(): void |
74
|
|
|
{ |
75
|
1 |
|
$this->expectException(AssertionFailedException::class); |
76
|
1 |
|
new ConfigProviderParams([]); |
77
|
|
|
} |
78
|
|
|
|
79
|
1 |
|
public function testMissingSources(): void |
80
|
|
|
{ |
81
|
1 |
|
$this->expectException(AssertionFailedException::class); |
82
|
1 |
|
new ConfigProviderParams([ |
83
|
|
|
'settings' => [ |
84
|
1 |
|
'loader' => ArrayConfigLoader::class, |
85
|
|
|
'locations' => [] |
86
|
|
|
] |
87
|
|
|
]); |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
|
public function testInvalidSources(): void |
91
|
|
|
{ |
92
|
1 |
|
$this->expectException(AssertionFailedException::class); |
93
|
1 |
|
new ConfigProviderParams([ |
94
|
|
|
'settings' => [ |
95
|
1 |
|
'loader' => ArrayConfigLoader::class, |
96
|
|
|
'sources' => 'foobar' |
97
|
|
|
] |
98
|
|
|
]); |
99
|
|
|
} |
100
|
|
|
|
101
|
1 |
|
public function testInvalidLocations(): void |
102
|
|
|
{ |
103
|
1 |
|
$this->expectException(AssertionFailedException::class); |
104
|
1 |
|
new ConfigProviderParams([ |
105
|
|
|
'settings' => [ |
106
|
1 |
|
'loader' => ArrayConfigLoader::class, |
107
|
|
|
'sources' => [], |
108
|
|
|
'locations' => 'foobar' |
109
|
|
|
] |
110
|
|
|
]); |
111
|
|
|
} |
112
|
|
|
|
113
|
1 |
|
public function testMissingLoader(): void |
114
|
|
|
{ |
115
|
1 |
|
$this->expectException(AssertionFailedException::class); |
116
|
1 |
|
new ConfigProviderParams([ |
117
|
|
|
'settings' => [ |
118
|
1 |
|
'sources' => [] |
119
|
|
|
] |
120
|
|
|
]); |
121
|
|
|
} |
122
|
|
|
|
123
|
1 |
|
public function testInvalidLoader(): void |
124
|
|
|
{ |
125
|
1 |
|
$this->expectException(AssertionFailedException::class); |
126
|
1 |
|
new ConfigProviderParams([ |
127
|
|
|
'settings' => [ |
128
|
1 |
|
'loader' => 'foobar', |
129
|
|
|
'sources' => [] |
130
|
|
|
] |
131
|
|
|
]); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|