@@ -106,28 +106,36 @@ protected function setUp(): void
106
106
}
107
107
108
108
/**
109
+ * @param array $configFromFile
109
110
* @param array $config
111
+ * @param array $finalConfig
110
112
* @param bool $isGreaterOrEqual
111
113
* @param string $address
112
114
* @param int $port
113
115
* @throws StepException
114
116
* @dataProvider executeDataProvider
115
117
*/
116
- public function testExecute (array $ config , bool $ isGreaterOrEqual , $ address , $ port )
117
- {
118
+ public function testExecute (
119
+ array $ configFromFile ,
120
+ array $ config ,
121
+ array $ finalConfig ,
122
+ bool $ isGreaterOrEqual ,
123
+ $ address ,
124
+ $ port
125
+ ) {
118
126
$ this ->magentoVersion ->expects ($ this ->any ())
119
127
->method ('isGreaterOrEqual ' )
120
128
->with ('2.3.0 ' )
121
129
->willReturn ($ isGreaterOrEqual );
122
130
$ this ->configReaderMock ->expects ($ this ->once ())
123
131
->method ('read ' )
124
- ->willReturn ([] );
132
+ ->willReturn ($ configFromFile );
125
133
$ this ->cacheConfigMock ->expects ($ this ->once ())
126
134
->method ('get ' )
127
135
->willReturn ($ config );
128
136
$ this ->configWriterMock ->expects ($ this ->once ())
129
137
->method ('create ' )
130
- ->with ([ ' cache ' => $ config ] );
138
+ ->with ($ finalConfig );
131
139
$ this ->loggerMock ->expects ($ this ->once ())
132
140
->method ('info ' )
133
141
->with ('Updating cache configuration. ' );
@@ -145,10 +153,51 @@ public function testExecute(array $config, bool $isGreaterOrEqual, $address, $po
145
153
$ this ->step ->execute ();
146
154
}
147
155
156
+ /**
157
+ * @return array[]
158
+ *
159
+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
160
+ */
148
161
public function executeDataProvider (): array
149
162
{
150
163
return [
164
+ 'with qraphql config in file ' => [
165
+ 'configFromFile ' => [
166
+ 'cache ' => ['graphql ' => ['id_salt ' => 'some salt ' ]],
167
+ ],
168
+ 'config ' => [
169
+ 'frontend ' => [
170
+ 'frontName ' => [
171
+ 'backend ' => CacheFactory::REDIS_BACKEND_CM_CACHE ,
172
+ 'backend_options ' => [
173
+ 'server ' => 'localhost ' ,
174
+ 'port ' => 6370 ,
175
+ ],
176
+ ],
177
+ ],
178
+ ],
179
+ 'finalConfig ' => [
180
+ 'cache ' => [
181
+ 'frontend ' => [
182
+ 'frontName ' => [
183
+ 'backend ' => CacheFactory::REDIS_BACKEND_CM_CACHE ,
184
+ 'backend_options ' => [
185
+ 'server ' => 'localhost ' ,
186
+ 'port ' => 6370 ,
187
+ ],
188
+ ],
189
+ ],
190
+ 'graphql ' => [
191
+ 'id_salt ' => 'some salt ' ,
192
+ ],
193
+ ],
194
+ ],
195
+ 'isGreaterOrEqual ' => false ,
196
+ 'address ' => 'localhost ' ,
197
+ 'port ' => 6370
198
+ ],
151
199
'backend model without remote_backend_options ' => [
200
+ 'configFromFile ' => [],
152
201
'config ' => [
153
202
'frontend ' => [
154
203
'frontName ' => [
@@ -160,11 +209,25 @@ public function executeDataProvider(): array
160
209
],
161
210
],
162
211
],
212
+ 'finalConfig ' => [
213
+ 'cache ' => [
214
+ 'frontend ' => [
215
+ 'frontName ' => [
216
+ 'backend ' => CacheFactory::REDIS_BACKEND_CM_CACHE ,
217
+ 'backend_options ' => [
218
+ 'server ' => 'localhost ' ,
219
+ 'port ' => 6370 ,
220
+ ],
221
+ ],
222
+ ],
223
+ ],
224
+ ],
163
225
'isGreaterOrEqual ' => false ,
164
226
'address ' => 'localhost ' ,
165
227
'port ' => 6370
166
228
],
167
229
'backend model with remote_backend_options ' => [
230
+ 'configFromFile ' => [],
168
231
'config ' => [
169
232
'frontend ' => [
170
233
'frontName ' => [
@@ -178,11 +241,27 @@ public function executeDataProvider(): array
178
241
],
179
242
],
180
243
],
244
+ 'finalConfig ' => [
245
+ 'cache ' => [
246
+ 'frontend ' => [
247
+ 'frontName ' => [
248
+ 'backend ' => CacheFactory::REDIS_BACKEND_REMOTE_SYNCHRONIZED_CACHE ,
249
+ 'backend_options ' => [
250
+ 'remote_backend_options ' => [
251
+ 'server ' => 'localhost ' ,
252
+ 'port ' => 6370 ,
253
+ ],
254
+ ],
255
+ ],
256
+ ],
257
+ ],
258
+ ],
181
259
'isGreaterOrEqual ' => true ,
182
260
'address ' => 'localhost ' ,
183
261
'port ' => 6370
184
262
],
185
263
'Server contains port data ' => [
264
+ 'configFromFile ' => [],
186
265
'config ' => [
187
266
'frontend ' => [
188
267
'frontName ' => [
@@ -195,11 +274,26 @@ public function executeDataProvider(): array
195
274
],
196
275
],
197
276
],
277
+ 'finalConfig ' => [
278
+ 'cache ' => [
279
+ 'frontend ' => [
280
+ 'frontName ' => [
281
+ 'backend ' => CacheFactory::REDIS_BACKEND_REMOTE_SYNCHRONIZED_CACHE ,
282
+ 'backend_options ' => [
283
+ 'remote_backend_options ' => [
284
+ 'server ' => '127.0.0.1:6371 ' ,
285
+ ],
286
+ ],
287
+ ],
288
+ ],
289
+ ],
290
+ ],
198
291
'isGreaterOrEqual ' => true ,
199
292
'address ' => '127.0.0.1 ' ,
200
293
'port ' => 6371
201
294
],
202
295
'Server contains protocol and port data ' => [
296
+ 'configFromFile ' => [],
203
297
'config ' => [
204
298
'frontend ' => [
205
299
'frontName ' => [
@@ -212,26 +306,45 @@ public function executeDataProvider(): array
212
306
],
213
307
],
214
308
],
309
+ 'finalConfig ' => [
310
+ 'cache ' => [
311
+ 'frontend ' => [
312
+ 'frontName ' => [
313
+ 'backend ' => CacheFactory::REDIS_BACKEND_REMOTE_SYNCHRONIZED_CACHE ,
314
+ 'backend_options ' => [
315
+ 'remote_backend_options ' => [
316
+ 'server ' => 'tcp://localhost:6379 ' ,
317
+ ],
318
+ ],
319
+ ],
320
+ ],
321
+ ],
322
+ ],
215
323
'isGreaterOrEqual ' => true ,
216
324
'address ' => 'localhost ' ,
217
325
'port ' => 6379
218
326
],
219
327
];
220
328
}
221
329
222
- public function testExecuteEmptyConfig ()
330
+ /**
331
+ * @param array $cacheConfig
332
+ * @param array $finalConfig
333
+ * @return void
334
+ * @throws StepException
335
+ * @dataProvider executeEmptyConfig
336
+ */
337
+ public function testExecuteEmptyConfig (array $ cacheConfig , array $ finalConfig ): void
223
338
{
224
339
$ this ->configReaderMock ->expects ($ this ->once ())
225
340
->method ('read ' )
226
- ->willReturn (['cache ' => [
227
- 'frontend ' => ['frontName ' => ['backend ' => 'cacheDriver ' ]],
228
- ]]);
341
+ ->willReturn ($ cacheConfig );
229
342
$ this ->cacheConfigMock ->expects ($ this ->once ())
230
343
->method ('get ' )
231
344
->willReturn ([]);
232
345
$ this ->configWriterMock ->expects ($ this ->once ())
233
346
->method ('create ' )
234
- ->with ([] );
347
+ ->with ($ finalConfig );
235
348
$ this ->loggerMock ->expects ($ this ->once ())
236
349
->method ('info ' )
237
350
->with ('Cache configuration was not found. Removing cache configuration. ' );
@@ -243,6 +356,33 @@ public function testExecuteEmptyConfig()
243
356
$ this ->step ->execute ();
244
357
}
245
358
359
+ public function executeEmptyConfig (): array
360
+ {
361
+ return [
362
+ 'without graphql in config ' => [
363
+ 'cacheConfig ' => [
364
+ 'cache ' => [
365
+ 'frontend ' => ['frontName ' => ['backend ' => 'cacheDriver ' ]],
366
+ ],
367
+ ],
368
+ 'finalConfig ' => [],
369
+ ],
370
+ 'with graphql in config ' => [
371
+ 'cacheConfig ' => [
372
+ 'cache ' => [
373
+ 'frontend ' => ['frontName ' => ['backend ' => 'cacheDriver ' ]],
374
+ 'graphql ' => ['id_salt ' => 'some salt ' ],
375
+ ],
376
+ ],
377
+ 'finalConfig ' => [
378
+ 'cache ' => [
379
+ 'graphql ' => ['id_salt ' => 'some salt ' ],
380
+ ],
381
+ ],
382
+ ],
383
+ ];
384
+ }
385
+
246
386
public function testExecuteRedisService ()
247
387
{
248
388
$ this ->prepareMocks ();
0 commit comments