Skip to content

Commit b09c78a

Browse files
authored
MCLOUD-9486: Ece-tools should keep id_salt in cache configuration for graphql (#102)
1 parent 79f9c1b commit b09c78a

File tree

2 files changed

+154
-9
lines changed

2 files changed

+154
-9
lines changed

src/Step/Deploy/PreDeploy/ConfigUpdate/Cache.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public function execute()
7676
try {
7777
$config = $this->configReader->read();
7878
$cacheConfig = $this->cacheConfig->get();
79+
$graphqlConfig = $config['cache']['graphql'] ?? [];
7980

8081
if (isset($cacheConfig['frontend'])) {
8182
$cacheConfig['frontend'] = array_filter($cacheConfig['frontend'], function ($cacheFrontend) {
@@ -108,6 +109,10 @@ public function execute()
108109
$config['cache'] = $cacheConfig;
109110
}
110111

112+
if (!empty($graphqlConfig)) {
113+
$config['cache']['graphql'] = $graphqlConfig;
114+
}
115+
111116
$this->configWriter->create($config);
112117
} catch (FileSystemException $e) {
113118
throw new StepException($e->getMessage(), Error::DEPLOY_ENV_PHP_IS_NOT_WRITABLE);

src/Test/Unit/Step/Deploy/PreDeploy/ConfigUpdate/CacheTest.php

Lines changed: 149 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,28 +106,36 @@ protected function setUp(): void
106106
}
107107

108108
/**
109+
* @param array $configFromFile
109110
* @param array $config
111+
* @param array $finalConfig
110112
* @param bool $isGreaterOrEqual
111113
* @param string $address
112114
* @param int $port
113115
* @throws StepException
114116
* @dataProvider executeDataProvider
115117
*/
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+
) {
118126
$this->magentoVersion->expects($this->any())
119127
->method('isGreaterOrEqual')
120128
->with('2.3.0')
121129
->willReturn($isGreaterOrEqual);
122130
$this->configReaderMock->expects($this->once())
123131
->method('read')
124-
->willReturn([]);
132+
->willReturn($configFromFile);
125133
$this->cacheConfigMock->expects($this->once())
126134
->method('get')
127135
->willReturn($config);
128136
$this->configWriterMock->expects($this->once())
129137
->method('create')
130-
->with(['cache' => $config]);
138+
->with($finalConfig);
131139
$this->loggerMock->expects($this->once())
132140
->method('info')
133141
->with('Updating cache configuration.');
@@ -145,10 +153,51 @@ public function testExecute(array $config, bool $isGreaterOrEqual, $address, $po
145153
$this->step->execute();
146154
}
147155

156+
/**
157+
* @return array[]
158+
*
159+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
160+
*/
148161
public function executeDataProvider(): array
149162
{
150163
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+
],
151199
'backend model without remote_backend_options' => [
200+
'configFromFile' => [],
152201
'config' => [
153202
'frontend' => [
154203
'frontName' => [
@@ -160,11 +209,25 @@ public function executeDataProvider(): array
160209
],
161210
],
162211
],
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+
],
163225
'isGreaterOrEqual' => false,
164226
'address' => 'localhost',
165227
'port' => 6370
166228
],
167229
'backend model with remote_backend_options' => [
230+
'configFromFile' => [],
168231
'config' => [
169232
'frontend' => [
170233
'frontName' => [
@@ -178,11 +241,27 @@ public function executeDataProvider(): array
178241
],
179242
],
180243
],
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+
],
181259
'isGreaterOrEqual' => true,
182260
'address' => 'localhost',
183261
'port' => 6370
184262
],
185263
'Server contains port data' => [
264+
'configFromFile' => [],
186265
'config' => [
187266
'frontend' => [
188267
'frontName' => [
@@ -195,11 +274,26 @@ public function executeDataProvider(): array
195274
],
196275
],
197276
],
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+
],
198291
'isGreaterOrEqual' => true,
199292
'address' => '127.0.0.1',
200293
'port' => 6371
201294
],
202295
'Server contains protocol and port data' => [
296+
'configFromFile' => [],
203297
'config' => [
204298
'frontend' => [
205299
'frontName' => [
@@ -212,26 +306,45 @@ public function executeDataProvider(): array
212306
],
213307
],
214308
],
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+
],
215323
'isGreaterOrEqual' => true,
216324
'address' => 'localhost',
217325
'port' => 6379
218326
],
219327
];
220328
}
221329

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
223338
{
224339
$this->configReaderMock->expects($this->once())
225340
->method('read')
226-
->willReturn(['cache' => [
227-
'frontend' => ['frontName' => ['backend' => 'cacheDriver']],
228-
]]);
341+
->willReturn($cacheConfig);
229342
$this->cacheConfigMock->expects($this->once())
230343
->method('get')
231344
->willReturn([]);
232345
$this->configWriterMock->expects($this->once())
233346
->method('create')
234-
->with([]);
347+
->with($finalConfig);
235348
$this->loggerMock->expects($this->once())
236349
->method('info')
237350
->with('Cache configuration was not found. Removing cache configuration.');
@@ -243,6 +356,33 @@ public function testExecuteEmptyConfig()
243356
$this->step->execute();
244357
}
245358

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+
246386
public function testExecuteRedisService()
247387
{
248388
$this->prepareMocks();

0 commit comments

Comments
 (0)