Skip to content

Commit b2896cc

Browse files
oshmyheliukshiftedreality
authored andcommitted
MAGECLOUD-3580: Env.php configs are not updated after deleting the ES service (#485)
1 parent e7d957d commit b2896cc

File tree

17 files changed

+216
-30
lines changed

17 files changed

+216
-30
lines changed

src/Config/Deploy/Writer.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ public function create(array $config)
5858
* @inheritdoc
5959
*/
6060
public function update(array $config)
61+
{
62+
$updatedConfig = array_replace($this->reader->read(), $config);
63+
64+
$this->create($updatedConfig);
65+
}
66+
67+
/**
68+
* @inheritdoc
69+
*/
70+
public function updateRecursive(array $config)
6171
{
6272
$updatedConfig = array_replace_recursive($this->reader->read(), $config);
6373

src/Config/Shared.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function all(): array
7979
public function update(array $config)
8080
{
8181
$this->reset();
82-
$this->writer->update($config);
82+
$this->writer->updateRecursive($config);
8383
}
8484

8585
/**

src/Config/Shared/Writer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,18 @@ public function create(array $config)
5959
*/
6060
public function update(array $config)
6161
{
62-
$this->create(
63-
array_replace_recursive($this->reader->read(), $config)
64-
);
62+
$updatedConfig = array_replace($this->reader->read(), $config);
63+
64+
$this->create($updatedConfig);
65+
}
66+
67+
/**
68+
* @inheritdoc
69+
*/
70+
public function updateRecursive(array $config)
71+
{
72+
$updatedConfig = array_replace_recursive($this->reader->read(), $config);
73+
74+
$this->create($updatedConfig);
6575
}
6676
}

src/Config/State.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function isInstalled(): bool
8585
return true;
8686
}
8787

88-
$this->writer->update(['install' => ['date' => date('r')]]);
88+
$this->writer->updateRecursive(['install' => ['date' => date('r')]]);
8989

9090
return true;
9191
}

src/Filesystem/Writer/WriterInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,13 @@ public function create(array $config);
2929
* @throws FileSystemException
3030
*/
3131
public function update(array $config);
32+
33+
/**
34+
* Recursively updates existence configuration.
35+
*
36+
* @param array $config
37+
* @return void
38+
* @throws FileSystemException
39+
*/
40+
public function updateRecursive(array $config);
3241
}

src/Process/Deploy/DisableCron.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(
5353
public function execute()
5454
{
5555
$this->logger->info('Disable cron');
56-
$this->writer->update(['cron' => ['enabled' => 0]]);
56+
$this->writer->updateRecursive(['cron' => ['enabled' => 0]]);
5757

5858
$this->cronProcessKill->execute();
5959
}

src/Process/Deploy/InstallUpdate/ConfigUpdate/DocumentRoot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public function __construct(
4242
public function execute()
4343
{
4444
$this->logger->info('The value of the property \'directories/document_root_is_pub\' set as \'true\'');
45-
$this->configWriter->update(['directories' => ['document_root_is_pub' => true]]);
45+
$this->configWriter->updateRecursive(['directories' => ['document_root_is_pub' => true]]);
4646
}
4747
}

src/Process/Deploy/InstallUpdate/Update/SetAdminUrl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function execute()
6464
$config['backend']['frontName'] = $adminUrl;
6565

6666
try {
67-
$this->configWriter->update($config);
67+
$this->configWriter->updateRecursive($config);
6868
} catch (FileSystemException $exception) {
6969
throw new ProcessException($exception->getMessage(), $exception->getCode(), $exception);
7070
}

src/Process/Deploy/SetCryptKey.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function execute()
7979
$config['crypt']['key'] = $key;
8080

8181
try {
82-
$this->configWriter->update($config);
82+
$this->configWriter->updateRecursive($config);
8383
} catch (FileSystemException $exception) {
8484
throw new ProcessException($exception->getMessage(), $exception->getCode(), $exception);
8585
}

src/Test/Unit/Config/Deploy/WriterTest.php

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,69 @@ public function createDataProvider()
9696
* @param array $config
9797
* @param array $currentConfig
9898
* @param string $updatedConfig
99-
* @dataProvider readDataProvider
99+
* @dataProvider getUpdateRecursiveDataProvider
100+
*/
101+
public function testUpdateRecursive(array $config, array $currentConfig, $updatedConfig)
102+
{
103+
$filePath = '/path/to/file';
104+
$this->fileListMock->expects($this->once())
105+
->method('getEnv')
106+
->willReturn($filePath);
107+
$this->readerMock->expects($this->once())
108+
->method('read')
109+
->willReturn($currentConfig);
110+
$this->fileMock->expects($this->once())
111+
->method('filePutContents')
112+
->with($filePath, $updatedConfig);
113+
114+
$this->writer->updateRecursive($config);
115+
}
116+
117+
/**
118+
* @return array
119+
*/
120+
public function getUpdateRecursiveDataProvider()
121+
{
122+
return [
123+
[
124+
[],
125+
[],
126+
"<?php\nreturn array (\n);",
127+
],
128+
[
129+
['key' => 'value'],
130+
['key1' => 'value1'],
131+
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key' => 'value',\n);",
132+
],
133+
[
134+
['key1' => 'value1', 'key2' => 'value2'],
135+
['key1' => 'value0', 'key3' => 'value3'],
136+
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key3' => 'value3',\n 'key2' => 'value2',\n);",
137+
],
138+
[
139+
[
140+
'key1' => [
141+
'key12' => 'value2new',
142+
'key13' => 'value3new',
143+
]
144+
],
145+
[
146+
'key1' => [
147+
'key11' => 'value1',
148+
'key12' => 'value2',
149+
]
150+
],
151+
"<?php\nreturn array (\n 'key1' => \n array (\n 'key11' => 'value1',\n" .
152+
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
153+
],
154+
];
155+
}
156+
157+
/**
158+
* @param array $config
159+
* @param array $currentConfig
160+
* @param string $updatedConfig
161+
* @dataProvider getUpdateDataProvider
100162
*/
101163
public function testUpdate(array $config, array $currentConfig, $updatedConfig)
102164
{
@@ -117,7 +179,7 @@ public function testUpdate(array $config, array $currentConfig, $updatedConfig)
117179
/**
118180
* @return array
119181
*/
120-
public function readDataProvider()
182+
public function getUpdateDataProvider()
121183
{
122184
return [
123185
[
@@ -135,6 +197,22 @@ public function readDataProvider()
135197
['key1' => 'value0', 'key3' => 'value3'],
136198
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key3' => 'value3',\n 'key2' => 'value2',\n);",
137199
],
200+
[
201+
[
202+
'key1' => [
203+
'key12' => 'value2new',
204+
'key13' => 'value3new',
205+
]
206+
],
207+
[
208+
'key1' => [
209+
'key11' => 'value1',
210+
'key12' => 'value2',
211+
]
212+
],
213+
"<?php\nreturn array (\n 'key1' => \n array (\n" .
214+
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
215+
]
138216
];
139217
}
140218
}

src/Test/Unit/Config/Shared/WriterTest.php

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,69 @@ public function createDataProvider(): array
9696
* @param array $config
9797
* @param array $currentConfig
9898
* @param string $updatedConfig
99-
* @dataProvider updateDataProvider
99+
* @dataProvider updateRecursiveDataProvider
100+
*/
101+
public function testUpdateRecursive(array $config, array $currentConfig, $updatedConfig)
102+
{
103+
$filePath = '/path/to/file';
104+
$this->fileListMock->expects($this->once())
105+
->method('getConfig')
106+
->willReturn($filePath);
107+
$this->readerMock->expects($this->once())
108+
->method('read')
109+
->willReturn($currentConfig);
110+
$this->fileMock->expects($this->once())
111+
->method('filePutContents')
112+
->with($filePath, $updatedConfig);
113+
114+
$this->writer->updateRecursive($config);
115+
}
116+
117+
/**
118+
* @return array
119+
*/
120+
public function updateRecursiveDataProvider(): array
121+
{
122+
return [
123+
[
124+
[],
125+
[],
126+
"<?php\nreturn array (\n);",
127+
],
128+
[
129+
['key' => 'value'],
130+
['key1' => 'value1'],
131+
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key' => 'value',\n);",
132+
],
133+
[
134+
['key1' => 'value1', 'key2' => 'value2'],
135+
['key1' => 'value0', 'key3' => 'value3'],
136+
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key3' => 'value3',\n 'key2' => 'value2',\n);",
137+
],
138+
[
139+
[
140+
'key1' => [
141+
'key12' => 'value2new',
142+
'key13' => 'value3new',
143+
]
144+
],
145+
[
146+
'key1' => [
147+
'key11' => 'value1',
148+
'key12' => 'value2',
149+
]
150+
],
151+
"<?php\nreturn array (\n 'key1' => \n array (\n 'key11' => 'value1',\n" .
152+
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
153+
],
154+
];
155+
}
156+
157+
/**
158+
* @param array $config
159+
* @param array $currentConfig
160+
* @param string $updatedConfig
161+
* @dataProvider getUpdateDataProvider
100162
*/
101163
public function testUpdate(array $config, array $currentConfig, $updatedConfig)
102164
{
@@ -117,7 +179,7 @@ public function testUpdate(array $config, array $currentConfig, $updatedConfig)
117179
/**
118180
* @return array
119181
*/
120-
public function updateDataProvider(): array
182+
public function getUpdateDataProvider()
121183
{
122184
return [
123185
[
@@ -135,6 +197,22 @@ public function updateDataProvider(): array
135197
['key1' => 'value0', 'key3' => 'value3'],
136198
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key3' => 'value3',\n 'key2' => 'value2',\n);",
137199
],
200+
[
201+
[
202+
'key1' => [
203+
'key12' => 'value2new',
204+
'key13' => 'value3new',
205+
]
206+
],
207+
[
208+
'key1' => [
209+
'key11' => 'value1',
210+
'key12' => 'value2',
211+
]
212+
],
213+
"<?php\nreturn array (\n 'key1' => \n array (\n" .
214+
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
215+
]
138216
];
139217
}
140218
}

src/Test/Unit/Config/SharedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function testReset()
129129
public function testUpdate()
130130
{
131131
$this->writerMock->expects($this->once())
132-
->method('update')
132+
->method('updateRecursive')
133133
->with(['some' => 'config']);
134134

135135
$this->shared->update(['some' => 'config']);

src/Test/Unit/Config/StateTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testIsInstalledTablesCount($tables)
7878
->method('listTables')
7979
->willReturn($tables);
8080
$this->writerMock->expects($this->never())
81-
->method('update');
81+
->method('updateRecursive');
8282

8383
$this->assertFalse($this->state->isInstalled());
8484
}
@@ -105,7 +105,7 @@ public function testIsInstalledTablesWithException($tables)
105105
->method('listTables')
106106
->willReturn($tables);
107107
$this->writerMock->expects($this->never())
108-
->method('update');
108+
->method('updateRecursive');
109109

110110
$this->state->isInstalled();
111111
}
@@ -137,7 +137,7 @@ public function testIsInstalledConfigFileIsNotExistsOrEmpty()
137137
->method('read')
138138
->willReturn([]);
139139
$this->writerMock->expects($this->once())
140-
->method('update')
140+
->method('updateRecursive')
141141
->with($config);
142142

143143
$dateMock = $this->getFunctionMock('Magento\MagentoCloud\Config', 'date');
@@ -166,7 +166,7 @@ public function testIsInstalledConfigFileWithDate()
166166
->method('read')
167167
->willReturn($config);
168168
$this->writerMock->expects($this->never())
169-
->method('update');
169+
->method('updateRecursive');
170170

171171
$this->assertTrue($this->state->isInstalled());
172172
}

src/Test/Unit/Process/Deploy/DisableCronTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testExecute()
6060
->method('info')
6161
->with('Disable cron');
6262
$this->writerMock->expects($this->once())
63-
->method('update')
63+
->method('updateRecursive')
6464
->with($config);
6565
$this->cronProcessKillMock->expects($this->once())
6666
->method('execute');

src/Test/Unit/Process/Deploy/InstallUpdate/ConfigUpdate/DocumentRootTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testExecute()
5454
->method('info')
5555
->with('The value of the property \'directories/document_root_is_pub\' set as \'true\'');
5656
$this->configWriterMock->expects($this->once())
57-
->method('update')
57+
->method('updateRecursive')
5858
->with(['directories' => ['document_root_is_pub' => true]]);
5959

6060
$this->process->execute();

src/Test/Unit/Process/Deploy/InstallUpdate/Update/SetAdminUrlTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testExecute()
6666
->method('getAdminUrl')
6767
->willReturn($frontName);
6868
$this->configWriterMock->expects($this->once())
69-
->method('update')
69+
->method('updateRecursive')
7070
->with(['backend' => ['frontName' => $frontName]]);
7171

7272
$this->setAdminUrl->execute();
@@ -84,7 +84,7 @@ public function testExecuteNoChange()
8484
->method('info')
8585
->with('Not updating env.php backend front name. (ADMIN_URL not set)');
8686
$this->configWriterMock->expects($this->never())
87-
->method('update');
87+
->method('updateRecursive');
8888

8989
$this->setAdminUrl->execute();
9090
}

0 commit comments

Comments
 (0)