1
1
<?php
2
+
2
3
/**
3
4
* Copyright © Magento, Inc. All rights reserved.
4
5
* See COPYING.txt for license details.
5
6
*/
7
+
6
8
declare (strict_types=1 );
7
9
8
10
namespace Magento \Framework \App \Test \Unit ;
@@ -20,12 +22,12 @@ class DeploymentConfigTest extends TestCase
20
22
*/
21
23
private static $ fixture
22
24
= [
23
- 'configData1 ' => 'scalar_value ' ,
24
- 'configData2 ' => [
25
+ 'configData1 ' => 'scalar_value ' ,
26
+ 'configData2 ' => [
25
27
'foo ' => 1 ,
26
28
'bar ' => ['baz ' => 2 ],
27
29
],
28
- 'configData3 ' => null ,
30
+ 'configData3 ' => null ,
29
31
'test_override ' => 'original ' ,
30
32
];
31
33
@@ -34,16 +36,16 @@ class DeploymentConfigTest extends TestCase
34
36
*/
35
37
private static $ flattenedFixture
36
38
= [
37
- 'configData1 ' => 'scalar_value ' ,
38
- 'configData2 ' => [
39
+ 'configData1 ' => 'scalar_value ' ,
40
+ 'configData2 ' => [
39
41
'foo ' => 1 ,
40
42
'bar ' => ['baz ' => 2 ],
41
43
],
42
- 'configData2/foo ' => 1 ,
43
- 'configData2/bar ' => ['baz ' => 2 ],
44
+ 'configData2/foo ' => 1 ,
45
+ 'configData2/bar ' => ['baz ' => 2 ],
44
46
'configData2/bar/baz ' => 2 ,
45
- 'configData3 ' => null ,
46
- 'test_override ' => 'overridden ' ,
47
+ 'configData3 ' => null ,
48
+ 'test_override ' => 'overridden ' ,
47
49
];
48
50
49
51
/**
@@ -69,32 +71,30 @@ class DeploymentConfigTest extends TestCase
69
71
/**
70
72
* @var MockObject
71
73
*/
72
- private $ reader ;
74
+ private $ readerMock ;
73
75
74
76
public static function setUpBeforeClass (): void
75
77
{
76
- self ::$ fixtureConfig = require __DIR__ . '/_files/config.php ' ;
78
+ self ::$ fixtureConfig = require __DIR__ . '/_files/config.php ' ;
77
79
self ::$ fixtureConfigMerged = require __DIR__ . '/_files/other/local_developer_merged.php ' ;
78
80
}
79
81
80
82
protected function setUp (): void
81
83
{
82
- $ this ->reader = $ this ->createMock (Reader::class);
83
- $ this ->_deploymentConfig = new DeploymentConfig (
84
- $ this ->reader ,
84
+ $ this ->readerMock = $ this ->createMock (Reader::class);
85
+ $ this ->_deploymentConfig = new DeploymentConfig (
86
+ $ this ->readerMock ,
85
87
['test_override ' => 'overridden ' ]
86
88
);
87
89
$ this ->_deploymentConfigMerged = new DeploymentConfig (
88
- $ this ->reader ,
90
+ $ this ->readerMock ,
89
91
require __DIR__ . '/_files/other/local_developer.php '
90
92
);
91
93
}
92
94
93
95
public function testGetters (): void
94
96
{
95
- $ this ->reader ->expects ($ this ->once ())->method ('load ' )->willReturn (self ::$ fixture );
96
- $ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
97
- // second time to ensure loader will be invoked only once
97
+ $ this ->readerMock ->expects ($ this ->any ())->method ('load ' )->willReturn (self ::$ fixture );
98
98
$ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
99
99
$ this ->assertSame ('scalar_value ' , $ this ->_deploymentConfig ->getConfigData ('configData1 ' ));
100
100
$ this ->assertSame (self ::$ fixture ['configData2 ' ], $ this ->_deploymentConfig ->getConfigData ('configData2 ' ));
@@ -107,19 +107,19 @@ public function testGetters(): void
107
107
108
108
public function testIsAvailable (): void
109
109
{
110
- $ this ->reader ->expects ($ this ->once ())->method ('load ' )->willReturn (
110
+ $ this ->readerMock ->expects ($ this ->once ())->method ('load ' )->willReturn (
111
111
[
112
112
ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE => 1 ,
113
113
]
114
114
);
115
- $ object = new DeploymentConfig ($ this ->reader );
115
+ $ object = new DeploymentConfig ($ this ->readerMock );
116
116
$ this ->assertTrue ($ object ->isAvailable ());
117
117
}
118
118
119
119
public function testNotAvailable (): void
120
120
{
121
- $ this ->reader ->expects ($ this ->once ())->method ('load ' )->willReturn ([]);
122
- $ object = new DeploymentConfig ($ this ->reader );
121
+ $ this ->readerMock ->expects ($ this ->once ())->method ('load ' )->willReturn ([]);
122
+ $ object = new DeploymentConfig ($ this ->readerMock );
123
123
$ this ->assertFalse ($ object ->isAvailable ());
124
124
}
125
125
@@ -128,8 +128,8 @@ public function testNotAvailable(): void
128
128
*/
129
129
public function testNotAvailableThenAvailable (): void
130
130
{
131
- $ this ->reader ->expects ($ this ->once ())->method ('load ' )->willReturn (['Test ' ]);
132
- $ object = new DeploymentConfig ($ this ->reader );
131
+ $ this ->readerMock ->expects ($ this ->once ())->method ('load ' )->willReturn (['Test ' ]);
132
+ $ object = new DeploymentConfig ($ this ->readerMock );
133
133
$ this ->assertFalse ($ object ->isAvailable ());
134
134
$ this ->assertFalse ($ object ->isAvailable ());
135
135
}
@@ -142,8 +142,8 @@ public function testKeyCollision(array $data): void
142
142
{
143
143
$ this ->expectException ('Exception ' );
144
144
$ this ->expectExceptionMessage ('Key collision ' );
145
- $ this ->reader ->expects ($ this ->once ())->method ('load ' )->willReturn ($ data );
146
- $ object = new DeploymentConfig ($ this ->reader );
145
+ $ this ->readerMock ->expects ($ this ->once ())->method ('load ' )->willReturn ($ data );
146
+ $ object = new DeploymentConfig ($ this ->readerMock );
147
147
$ object ->get ();
148
148
}
149
149
@@ -163,7 +163,7 @@ public function keyCollisionDataProvider(): array
163
163
164
164
public function testResetData (): void
165
165
{
166
- $ this ->reader ->expects ($ this ->exactly (2 ))->method ('load ' )->willReturn (self ::$ fixture );
166
+ $ this ->readerMock ->expects ($ this ->exactly (2 ))->method ('load ' )->willReturn (self ::$ fixture );
167
167
$ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
168
168
$ this ->_deploymentConfig ->resetData ();
169
169
// second time to ensure loader will be invoked only once after reset
@@ -173,9 +173,17 @@ public function testResetData(): void
173
173
174
174
public function testIsDbAvailable (): void
175
175
{
176
- $ this ->reader ->expects ($ this ->exactly (2 ))->method ('load ' )->willReturnOnConsecutiveCalls ([], ['db ' => []]);
176
+ $ this ->readerMock ->expects ($ this ->exactly (2 ))->method ('load ' )->willReturnOnConsecutiveCalls ([], ['db ' => []]);
177
177
$ this ->assertFalse ($ this ->_deploymentConfig ->isDbAvailable ());
178
178
$ this ->_deploymentConfig ->resetData ();
179
179
$ this ->assertTrue ($ this ->_deploymentConfig ->isDbAvailable ());
180
180
}
181
+
182
+ public function testReloadDataOnMissingConfig (): void
183
+ {
184
+ $ this ->readerMock ->expects ($ this ->exactly (2 ))->method ('load ' )->willReturn (self ::$ fixture );
185
+ $ defaultValue = 'some_default_value ' ;
186
+ $ result = $ this ->_deploymentConfig ->get ('missing/key ' , $ defaultValue );
187
+ $ this ->assertEquals ($ defaultValue , $ result );
188
+ }
181
189
}
0 commit comments