Skip to content

Commit

Permalink
MAGECLOUD-3580: Env.php configs are not updated after deleting the ES…
Browse files Browse the repository at this point in the history
… service (#485)
  • Loading branch information
oshmyheliuk authored and shiftedreality committed May 6, 2019
1 parent e7d957d commit b2896cc
Show file tree
Hide file tree
Showing 17 changed files with 216 additions and 30 deletions.
10 changes: 10 additions & 0 deletions src/Config/Deploy/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public function create(array $config)
* @inheritdoc
*/
public function update(array $config)
{
$updatedConfig = array_replace($this->reader->read(), $config);

$this->create($updatedConfig);
}

/**
* @inheritdoc
*/
public function updateRecursive(array $config)
{
$updatedConfig = array_replace_recursive($this->reader->read(), $config);

Expand Down
2 changes: 1 addition & 1 deletion src/Config/Shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function all(): array
public function update(array $config)
{
$this->reset();
$this->writer->update($config);
$this->writer->updateRecursive($config);
}

/**
Expand Down
16 changes: 13 additions & 3 deletions src/Config/Shared/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,18 @@ public function create(array $config)
*/
public function update(array $config)
{
$this->create(
array_replace_recursive($this->reader->read(), $config)
);
$updatedConfig = array_replace($this->reader->read(), $config);

$this->create($updatedConfig);
}

/**
* @inheritdoc
*/
public function updateRecursive(array $config)
{
$updatedConfig = array_replace_recursive($this->reader->read(), $config);

$this->create($updatedConfig);
}
}
2 changes: 1 addition & 1 deletion src/Config/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function isInstalled(): bool
return true;
}

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

return true;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Filesystem/Writer/WriterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ public function create(array $config);
* @throws FileSystemException
*/
public function update(array $config);

/**
* Recursively updates existence configuration.
*
* @param array $config
* @return void
* @throws FileSystemException
*/
public function updateRecursive(array $config);
}
2 changes: 1 addition & 1 deletion src/Process/Deploy/DisableCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct(
public function execute()
{
$this->logger->info('Disable cron');
$this->writer->update(['cron' => ['enabled' => 0]]);
$this->writer->updateRecursive(['cron' => ['enabled' => 0]]);

$this->cronProcessKill->execute();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public function __construct(
public function execute()
{
$this->logger->info('The value of the property \'directories/document_root_is_pub\' set as \'true\'');
$this->configWriter->update(['directories' => ['document_root_is_pub' => true]]);
$this->configWriter->updateRecursive(['directories' => ['document_root_is_pub' => true]]);
}
}
2 changes: 1 addition & 1 deletion src/Process/Deploy/InstallUpdate/Update/SetAdminUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function execute()
$config['backend']['frontName'] = $adminUrl;

try {
$this->configWriter->update($config);
$this->configWriter->updateRecursive($config);
} catch (FileSystemException $exception) {
throw new ProcessException($exception->getMessage(), $exception->getCode(), $exception);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Process/Deploy/SetCryptKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function execute()
$config['crypt']['key'] = $key;

try {
$this->configWriter->update($config);
$this->configWriter->updateRecursive($config);
} catch (FileSystemException $exception) {
throw new ProcessException($exception->getMessage(), $exception->getCode(), $exception);
}
Expand Down
82 changes: 80 additions & 2 deletions src/Test/Unit/Config/Deploy/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,69 @@ public function createDataProvider()
* @param array $config
* @param array $currentConfig
* @param string $updatedConfig
* @dataProvider readDataProvider
* @dataProvider getUpdateRecursiveDataProvider
*/
public function testUpdateRecursive(array $config, array $currentConfig, $updatedConfig)
{
$filePath = '/path/to/file';
$this->fileListMock->expects($this->once())
->method('getEnv')
->willReturn($filePath);
$this->readerMock->expects($this->once())
->method('read')
->willReturn($currentConfig);
$this->fileMock->expects($this->once())
->method('filePutContents')
->with($filePath, $updatedConfig);

$this->writer->updateRecursive($config);
}

/**
* @return array
*/
public function getUpdateRecursiveDataProvider()
{
return [
[
[],
[],
"<?php\nreturn array (\n);",
],
[
['key' => 'value'],
['key1' => 'value1'],
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key' => 'value',\n);",
],
[
['key1' => 'value1', 'key2' => 'value2'],
['key1' => 'value0', 'key3' => 'value3'],
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key3' => 'value3',\n 'key2' => 'value2',\n);",
],
[
[
'key1' => [
'key12' => 'value2new',
'key13' => 'value3new',
]
],
[
'key1' => [
'key11' => 'value1',
'key12' => 'value2',
]
],
"<?php\nreturn array (\n 'key1' => \n array (\n 'key11' => 'value1',\n" .
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
],
];
}

/**
* @param array $config
* @param array $currentConfig
* @param string $updatedConfig
* @dataProvider getUpdateDataProvider
*/
public function testUpdate(array $config, array $currentConfig, $updatedConfig)
{
Expand All @@ -117,7 +179,7 @@ public function testUpdate(array $config, array $currentConfig, $updatedConfig)
/**
* @return array
*/
public function readDataProvider()
public function getUpdateDataProvider()
{
return [
[
Expand All @@ -135,6 +197,22 @@ public function readDataProvider()
['key1' => 'value0', 'key3' => 'value3'],
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key3' => 'value3',\n 'key2' => 'value2',\n);",
],
[
[
'key1' => [
'key12' => 'value2new',
'key13' => 'value3new',
]
],
[
'key1' => [
'key11' => 'value1',
'key12' => 'value2',
]
],
"<?php\nreturn array (\n 'key1' => \n array (\n" .
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
]
];
}
}
82 changes: 80 additions & 2 deletions src/Test/Unit/Config/Shared/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,69 @@ public function createDataProvider(): array
* @param array $config
* @param array $currentConfig
* @param string $updatedConfig
* @dataProvider updateDataProvider
* @dataProvider updateRecursiveDataProvider
*/
public function testUpdateRecursive(array $config, array $currentConfig, $updatedConfig)
{
$filePath = '/path/to/file';
$this->fileListMock->expects($this->once())
->method('getConfig')
->willReturn($filePath);
$this->readerMock->expects($this->once())
->method('read')
->willReturn($currentConfig);
$this->fileMock->expects($this->once())
->method('filePutContents')
->with($filePath, $updatedConfig);

$this->writer->updateRecursive($config);
}

/**
* @return array
*/
public function updateRecursiveDataProvider(): array
{
return [
[
[],
[],
"<?php\nreturn array (\n);",
],
[
['key' => 'value'],
['key1' => 'value1'],
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key' => 'value',\n);",
],
[
['key1' => 'value1', 'key2' => 'value2'],
['key1' => 'value0', 'key3' => 'value3'],
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key3' => 'value3',\n 'key2' => 'value2',\n);",
],
[
[
'key1' => [
'key12' => 'value2new',
'key13' => 'value3new',
]
],
[
'key1' => [
'key11' => 'value1',
'key12' => 'value2',
]
],
"<?php\nreturn array (\n 'key1' => \n array (\n 'key11' => 'value1',\n" .
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
],
];
}

/**
* @param array $config
* @param array $currentConfig
* @param string $updatedConfig
* @dataProvider getUpdateDataProvider
*/
public function testUpdate(array $config, array $currentConfig, $updatedConfig)
{
Expand All @@ -117,7 +179,7 @@ public function testUpdate(array $config, array $currentConfig, $updatedConfig)
/**
* @return array
*/
public function updateDataProvider(): array
public function getUpdateDataProvider()
{
return [
[
Expand All @@ -135,6 +197,22 @@ public function updateDataProvider(): array
['key1' => 'value0', 'key3' => 'value3'],
"<?php\nreturn array (\n 'key1' => 'value1',\n 'key3' => 'value3',\n 'key2' => 'value2',\n);",
],
[
[
'key1' => [
'key12' => 'value2new',
'key13' => 'value3new',
]
],
[
'key1' => [
'key11' => 'value1',
'key12' => 'value2',
]
],
"<?php\nreturn array (\n 'key1' => \n array (\n" .
" 'key12' => 'value2new',\n 'key13' => 'value3new',\n ),\n);"
]
];
}
}
2 changes: 1 addition & 1 deletion src/Test/Unit/Config/SharedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function testReset()
public function testUpdate()
{
$this->writerMock->expects($this->once())
->method('update')
->method('updateRecursive')
->with(['some' => 'config']);

$this->shared->update(['some' => 'config']);
Expand Down
8 changes: 4 additions & 4 deletions src/Test/Unit/Config/StateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function testIsInstalledTablesCount($tables)
->method('listTables')
->willReturn($tables);
$this->writerMock->expects($this->never())
->method('update');
->method('updateRecursive');

$this->assertFalse($this->state->isInstalled());
}
Expand All @@ -105,7 +105,7 @@ public function testIsInstalledTablesWithException($tables)
->method('listTables')
->willReturn($tables);
$this->writerMock->expects($this->never())
->method('update');
->method('updateRecursive');

$this->state->isInstalled();
}
Expand Down Expand Up @@ -137,7 +137,7 @@ public function testIsInstalledConfigFileIsNotExistsOrEmpty()
->method('read')
->willReturn([]);
$this->writerMock->expects($this->once())
->method('update')
->method('updateRecursive')
->with($config);

$dateMock = $this->getFunctionMock('Magento\MagentoCloud\Config', 'date');
Expand Down Expand Up @@ -166,7 +166,7 @@ public function testIsInstalledConfigFileWithDate()
->method('read')
->willReturn($config);
$this->writerMock->expects($this->never())
->method('update');
->method('updateRecursive');

$this->assertTrue($this->state->isInstalled());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Test/Unit/Process/Deploy/DisableCronTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testExecute()
->method('info')
->with('Disable cron');
$this->writerMock->expects($this->once())
->method('update')
->method('updateRecursive')
->with($config);
$this->cronProcessKillMock->expects($this->once())
->method('execute');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testExecute()
->method('info')
->with('The value of the property \'directories/document_root_is_pub\' set as \'true\'');
$this->configWriterMock->expects($this->once())
->method('update')
->method('updateRecursive')
->with(['directories' => ['document_root_is_pub' => true]]);

$this->process->execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testExecute()
->method('getAdminUrl')
->willReturn($frontName);
$this->configWriterMock->expects($this->once())
->method('update')
->method('updateRecursive')
->with(['backend' => ['frontName' => $frontName]]);

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

$this->setAdminUrl->execute();
}
Expand Down
Loading

0 comments on commit b2896cc

Please sign in to comment.