12
12
use Magento \Framework \App \DeploymentConfig ;
13
13
use Magento \Framework \App \DeploymentConfig \Reader ;
14
14
use Magento \Framework \Config \ConfigOptionsListConstants ;
15
+ use Magento \Framework \Exception \FileSystemException ;
16
+ use Magento \Framework \Exception \RuntimeException ;
15
17
use PHPUnit \Framework \MockObject \MockObject ;
16
18
use PHPUnit \Framework \TestCase ;
17
19
@@ -61,7 +63,7 @@ class DeploymentConfigTest extends TestCase
61
63
/**
62
64
* @var DeploymentConfig
63
65
*/
64
- protected $ _deploymentConfig ;
66
+ protected $ deploymentConfig ;
65
67
66
68
/**
67
69
* @var DeploymentConfig
@@ -82,7 +84,7 @@ public static function setUpBeforeClass(): void
82
84
protected function setUp (): void
83
85
{
84
86
$ this ->readerMock = $ this ->createMock (Reader::class);
85
- $ this ->_deploymentConfig = new DeploymentConfig (
87
+ $ this ->deploymentConfig = new DeploymentConfig (
86
88
$ this ->readerMock ,
87
89
['test_override ' => 'overridden ' ]
88
90
);
@@ -92,19 +94,29 @@ protected function setUp(): void
92
94
);
93
95
}
94
96
97
+ /**
98
+ * @return void
99
+ * @throws FileSystemException
100
+ * @throws RuntimeException
101
+ */
95
102
public function testGetters (): void
96
103
{
97
104
$ this ->readerMock ->expects ($ this ->any ())->method ('load ' )->willReturn (self ::$ fixture );
98
- $ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
99
- $ this ->assertSame ('scalar_value ' , $ this ->_deploymentConfig ->getConfigData ('configData1 ' ));
100
- $ this ->assertSame (self ::$ fixture ['configData2 ' ], $ this ->_deploymentConfig ->getConfigData ('configData2 ' ));
101
- $ this ->assertSame (self ::$ fixture ['configData3 ' ], $ this ->_deploymentConfig ->getConfigData ('configData3 ' ));
102
- $ this ->assertSame ('' , $ this ->_deploymentConfig ->get ('configData3 ' ));
103
- $ this ->assertSame ('defaultValue ' , $ this ->_deploymentConfig ->get ('invalid_key ' , 'defaultValue ' ));
104
- $ this ->assertNull ($ this ->_deploymentConfig ->getConfigData ('invalid_key ' ));
105
- $ this ->assertSame ('overridden ' , $ this ->_deploymentConfig ->get ('test_override ' ));
105
+ $ this ->assertSame (self ::$ flattenedFixture , $ this ->deploymentConfig ->get ());
106
+ $ this ->assertSame ('scalar_value ' , $ this ->deploymentConfig ->getConfigData ('configData1 ' ));
107
+ $ this ->assertSame (self ::$ fixture ['configData2 ' ], $ this ->deploymentConfig ->getConfigData ('configData2 ' ));
108
+ $ this ->assertSame (self ::$ fixture ['configData3 ' ], $ this ->deploymentConfig ->getConfigData ('configData3 ' ));
109
+ $ this ->assertSame ('' , $ this ->deploymentConfig ->get ('configData3 ' ));
110
+ $ this ->assertSame ('defaultValue ' , $ this ->deploymentConfig ->get ('invalid_key ' , 'defaultValue ' ));
111
+ $ this ->assertNull ($ this ->deploymentConfig ->getConfigData ('invalid_key ' ));
112
+ $ this ->assertSame ('overridden ' , $ this ->deploymentConfig ->get ('test_override ' ));
106
113
}
107
114
115
+ /**
116
+ * @return void
117
+ * @throws FileSystemException
118
+ * @throws RuntimeException
119
+ */
108
120
public function testIsAvailable (): void
109
121
{
110
122
$ this ->readerMock ->expects ($ this ->once ())->method ('load ' )->willReturn (
@@ -116,6 +128,11 @@ public function testIsAvailable(): void
116
128
$ this ->assertTrue ($ object ->isAvailable ());
117
129
}
118
130
131
+ /**
132
+ * @return void
133
+ * @throws FileSystemException
134
+ * @throws RuntimeException
135
+ */
119
136
public function testNotAvailable (): void
120
137
{
121
138
$ this ->readerMock ->expects ($ this ->once ())->method ('load ' )->willReturn ([]);
@@ -125,6 +142,10 @@ public function testNotAvailable(): void
125
142
126
143
/**
127
144
* test if the configuration changes during the same request, the configuration remain the same
145
+ *
146
+ * @return void
147
+ * @throws FileSystemException
148
+ * @throws RuntimeException
128
149
*/
129
150
public function testNotAvailableThenAvailable (): void
130
151
{
@@ -135,8 +156,10 @@ public function testNotAvailableThenAvailable(): void
135
156
}
136
157
137
158
/**
138
- * @param array $data
139
159
* @dataProvider keyCollisionDataProvider
160
+ * @param array $data
161
+ * @throws FileSystemException
162
+ * @throws RuntimeException
140
163
*/
141
164
public function testKeyCollision (array $ data ): void
142
165
{
@@ -161,29 +184,44 @@ public function keyCollisionDataProvider(): array
161
184
];
162
185
}
163
186
187
+ /**
188
+ * @return void
189
+ * @throws FileSystemException
190
+ * @throws RuntimeException
191
+ */
164
192
public function testResetData (): void
165
193
{
166
194
$ this ->readerMock ->expects ($ this ->once ())->method ('load ' )->willReturn (self ::$ fixture );
167
- $ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
168
- $ this ->_deploymentConfig ->resetData ();
195
+ $ this ->assertSame (self ::$ flattenedFixture , $ this ->deploymentConfig ->get ());
196
+ $ this ->deploymentConfig ->resetData ();
169
197
// second time to ensure loader will be invoked only once after reset
170
- $ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
171
- $ this ->assertSame (self ::$ flattenedFixture , $ this ->_deploymentConfig ->get ());
198
+ $ this ->assertSame (self ::$ flattenedFixture , $ this ->deploymentConfig ->get ());
199
+ $ this ->assertSame (self ::$ flattenedFixture , $ this ->deploymentConfig ->get ());
172
200
}
173
201
202
+ /**
203
+ * @return void
204
+ * @throws FileSystemException
205
+ * @throws RuntimeException
206
+ */
174
207
public function testIsDbAvailable (): void
175
208
{
176
209
$ this ->readerMock ->expects ($ this ->exactly (2 ))->method ('load ' )->willReturnOnConsecutiveCalls ([], ['db ' => []]);
177
- $ this ->assertFalse ($ this ->_deploymentConfig ->isDbAvailable ());
178
- $ this ->_deploymentConfig ->resetData ();
179
- $ this ->assertTrue ($ this ->_deploymentConfig ->isDbAvailable ());
210
+ $ this ->assertFalse ($ this ->deploymentConfig ->isDbAvailable ());
211
+ $ this ->deploymentConfig ->resetData ();
212
+ $ this ->assertTrue ($ this ->deploymentConfig ->isDbAvailable ());
180
213
}
181
214
215
+ /**
216
+ * @return void
217
+ * @throws FileSystemException
218
+ * @throws RuntimeException
219
+ */
182
220
public function testResetDataOnMissingConfig (): void
183
221
{
184
222
$ this ->readerMock ->expects ($ this ->once ())->method ('load ' )->willReturn (self ::$ fixture );
185
223
$ defaultValue = 'some_default_value ' ;
186
- $ result = $ this ->_deploymentConfig ->get ('missing/key ' , $ defaultValue );
224
+ $ result = $ this ->deploymentConfig ->get ('missing/key ' , $ defaultValue );
187
225
$ this ->assertEquals ($ defaultValue , $ result );
188
226
}
189
227
}
0 commit comments