@@ -14,27 +14,33 @@ class DeploymentConfigTest extends \PHPUnit\Framework\TestCase
14
14
/**
15
15
* @var array
16
16
*/
17
- private static $ fixture = [
18
- 'configData1 ' => 'scalar_value ' ,
19
- 'configData2 ' => [
20
- 'foo ' => 1 ,
21
- 'bar ' => ['baz ' => 2 ],
22
- ],
23
- ];
17
+ private static $ fixture
18
+ = [
19
+ 'configData1 ' => 'scalar_value ' ,
20
+ 'configData2 ' => [
21
+ 'foo ' => 1 ,
22
+ 'bar ' => ['baz ' => 2 ],
23
+ ],
24
+ 'configData3 ' => null ,
25
+ 'test_override ' => 'original ' ,
26
+ ];
24
27
25
28
/**
26
29
* @var array
27
30
*/
28
- private static $ flattenedFixture = [
29
- 'configData1 ' => 'scalar_value ' ,
30
- 'configData2 ' => [
31
- 'foo ' => 1 ,
32
- 'bar ' => ['baz ' => 2 ],
33
- ],
34
- 'configData2/foo ' => 1 ,
35
- 'configData2/bar ' => ['baz ' => 2 ],
36
- 'configData2/bar/baz ' => 2 ,
37
- ];
31
+ private static $ flattenedFixture
32
+ = [
33
+ 'configData1 ' => 'scalar_value ' ,
34
+ 'configData2 ' => [
35
+ 'foo ' => 1 ,
36
+ 'bar ' => ['baz ' => 2 ],
37
+ ],
38
+ 'configData2/foo ' => 1 ,
39
+ 'configData2/bar ' => ['baz ' => 2 ],
40
+ 'configData2/bar/baz ' => 2 ,
41
+ 'configData3 ' => null ,
42
+ 'test_override ' => 'overridden ' ,
43
+ ];
38
44
39
45
/**
40
46
* @var array
@@ -63,55 +69,65 @@ class DeploymentConfigTest extends \PHPUnit\Framework\TestCase
63
69
64
70
public static function setUpBeforeClass ()
65
71
{
66
- self ::$ fixtureConfig = require __DIR__ . '/_files/config.php ' ;
67
- self ::$ fixtureConfigMerged = require __DIR__ . '/_files/other/local_developer_merged.php ' ;
72
+ self ::$ fixtureConfig = require __DIR__ . '/_files/config.php ' ;
73
+ self ::$ fixtureConfigMerged = require __DIR__ . '/_files/other/local_developer_merged.php ' ;
68
74
}
69
75
70
76
protected function setUp ()
71
77
{
72
- $ this ->reader = $ this ->createMock (\Magento \Framework \App \DeploymentConfig \Reader::class);
73
- $ this ->_deploymentConfig = new \Magento \Framework \App \DeploymentConfig ($ this ->reader , []);
78
+ $ this ->reader = $ this ->createMock (\Magento \Framework \App \DeploymentConfig \Reader::class);
79
+ $ this ->_deploymentConfig = new \Magento \Framework \App \DeploymentConfig (
80
+ $ this ->reader ,
81
+ ['test_override ' => 'overridden ' ]
82
+ );
74
83
$ this ->_deploymentConfigMerged = new \Magento \Framework \App \DeploymentConfig (
75
84
$ this ->reader ,
76
- require __DIR__ . '/_files/other/local_developer.php '
85
+ require __DIR__ . '/_files/other/local_developer.php '
77
86
);
78
87
}
79
88
80
- public function testGetters ()
89
+ public function testGetters (): void
81
90
{
82
91
$ this ->reader ->expects ($ this ->once ())->method ('load ' )->willReturn (self ::$ fixture );
83
92
$ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
84
93
// second time to ensure loader will be invoked only once
85
94
$ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
86
95
$ this ->assertSame ('scalar_value ' , $ this ->_deploymentConfig ->getConfigData ('configData1 ' ));
87
96
$ this ->assertSame (self ::$ fixture ['configData2 ' ], $ this ->_deploymentConfig ->getConfigData ('configData2 ' ));
97
+ $ this ->assertSame (self ::$ fixture ['configData3 ' ], $ this ->_deploymentConfig ->getConfigData ('configData3 ' ));
98
+ $ this ->assertSame ('' , $ this ->_deploymentConfig ->get ('configData3 ' ));
99
+ $ this ->assertSame ('defaultValue ' , $ this ->_deploymentConfig ->get ('invalid_key ' , 'defaultValue ' ));
100
+ $ this ->assertNull ($ this ->_deploymentConfig ->getConfigData ('invalid_key ' ));
101
+ $ this ->assertSame ('overridden ' , $ this ->_deploymentConfig ->get ('test_override ' ));
88
102
}
89
103
90
- public function testIsAvailable ()
104
+ public function testIsAvailable (): void
91
105
{
92
- $ this ->reader ->expects ($ this ->once ())->method ('load ' )->willReturn ([
93
- ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE => 1
94
- ]);
106
+ $ this ->reader ->expects ($ this ->once ())->method ('load ' )->willReturn (
107
+ [
108
+ ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE => 1 ,
109
+ ]
110
+ );
95
111
$ object = new DeploymentConfig ($ this ->reader );
96
112
$ this ->assertTrue ($ object ->isAvailable ());
97
113
}
98
114
99
- public function testNotAvailable ()
115
+ public function testNotAvailable (): void
100
116
{
101
117
$ this ->reader ->expects ($ this ->once ())->method ('load ' )->willReturn ([]);
102
118
$ object = new DeploymentConfig ($ this ->reader );
103
119
$ this ->assertFalse ($ object ->isAvailable ());
104
120
}
105
121
106
- public function testNotAvailableThenAvailable ()
122
+ /**
123
+ * test if the configuration changes during the same request, the configuration remain the same
124
+ */
125
+ public function testNotAvailableThenAvailable (): void
107
126
{
108
- $ this ->reader ->expects ($ this ->at (0 ))->method ('load ' )->willReturn ([]);
109
- $ this ->reader ->expects ($ this ->at (1 ))->method ('load ' )->willReturn ([
110
- ConfigOptionsListConstants::CONFIG_PATH_INSTALL_DATE => 1
111
- ]);
127
+ $ this ->reader ->expects ($ this ->once ())->method ('load ' )->willReturn ([]);
112
128
$ object = new DeploymentConfig ($ this ->reader );
113
129
$ this ->assertFalse ($ object ->isAvailable ());
114
- $ this ->assertTrue ($ object ->isAvailable ());
130
+ $ this ->assertFalse ($ object ->isAvailable ());
115
131
}
116
132
117
133
/**
@@ -120,7 +136,7 @@ public function testNotAvailableThenAvailable()
120
136
* @expectedExceptionMessage Key collision
121
137
* @dataProvider keyCollisionDataProvider
122
138
*/
123
- public function testKeyCollision (array $ data )
139
+ public function testKeyCollision (array $ data ): void
124
140
{
125
141
$ this ->reader ->expects ($ this ->once ())->method ('load ' )->willReturn ($ data );
126
142
$ object = new DeploymentConfig ($ this ->reader );
@@ -130,14 +146,32 @@ public function testKeyCollision(array $data)
130
146
/**
131
147
* @return array
132
148
*/
133
- public function keyCollisionDataProvider ()
149
+ public function keyCollisionDataProvider (): array
134
150
{
135
151
return [
136
152
[
137
153
['foo ' => ['bar ' => '1 ' ], 'foo/bar ' => '2 ' ],
138
154
['foo/bar ' => '1 ' , 'foo ' => ['bar ' => '2 ' ]],
139
155
['foo ' => ['subfoo ' => ['subbar ' => '1 ' ], 'subfoo/subbar ' => '2 ' ], 'bar ' => '3 ' ],
140
- ]
156
+ ],
141
157
];
142
158
}
159
+
160
+ public function testResetData (): void
161
+ {
162
+ $ this ->reader ->expects ($ this ->exactly (2 ))->method ('load ' )->willReturn (self ::$ fixture );
163
+ $ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
164
+ $ this ->_deploymentConfig ->resetData ();
165
+ // second time to ensure loader will be invoked only once after reset
166
+ $ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
167
+ $ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
168
+ }
169
+
170
+ public function testIsDbAvailable (): void
171
+ {
172
+ $ this ->reader ->expects ($ this ->exactly (2 ))->method ('load ' )->willReturnOnConsecutiveCalls ([], ['db ' => []]);
173
+ $ this ->assertFalse ($ this ->_deploymentConfig ->isDbAvailable ());
174
+ $ this ->_deploymentConfig ->resetData ();
175
+ $ this ->assertTrue ($ this ->_deploymentConfig ->isDbAvailable ());
176
+ }
143
177
}
0 commit comments