Skip to content

Commit 086d6e8

Browse files
authored
MCLOUD-5939: Failed deploy with missed env.php (magento#728)
1 parent ce86fc6 commit 086d6e8

File tree

2 files changed

+57
-20
lines changed

2 files changed

+57
-20
lines changed

src/Step/Deploy/InstallUpdate/ConfigUpdate/DbConnection.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,14 @@ private function slaveIsAvailable(): bool
382382
*/
383383
private function getMageSplitConnectionsConfig(): array
384384
{
385-
return array_intersect_key(
386-
$this->getMageConfigData()[DbConfig::KEY_DB][DbConfig::KEY_CONNECTION],
387-
array_flip(DbConfig::SPLIT_CONNECTIONS)
388-
);
385+
$existedSplitConnections = [];
386+
$mageConfig = $this->getMageConfigData();
387+
if (isset($mageConfig[DbConfig::KEY_DB][DbConfig::KEY_CONNECTION])) {
388+
$existedSplitConnections = array_intersect_key(
389+
$mageConfig[DbConfig::KEY_DB][DbConfig::KEY_CONNECTION],
390+
array_flip(DbConfig::SPLIT_CONNECTIONS)
391+
);
392+
}
393+
return $existedSplitConnections;
389394
}
390395
}

src/Test/Unit/Step/Deploy/InstallUpdate/ConfigUpdate/DbConnectionTest.php

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -178,31 +178,28 @@ public function testExecuteWithoutDbConfigInEnvironment()
178178

179179
/**
180180
* Case when slave connections and split database are not used
181+
*
182+
* @param $mageConfig array
183+
* @param $envConfig array
184+
* @param $expectedResult array
185+
* @dataProvider executeWithoutSplitAndSlaveConfigDataProvider
181186
*/
182-
public function testExecuteWithoutSplitAndSlaveConfig()
187+
public function testExecuteWithoutSplitAndSlaveConfig(array $mageConfig, array $envConfig, array $expectedResult)
183188
{
184189
$resourceConfig = [
185190
'default_setup' => self::RESOURCE_DEFAULT_SETUP,
186191
];
192+
$expectedResult['resource'] = $resourceConfig;
187193

188-
$dbConfig = [
189-
'connection' => [
190-
'default' => self::DEFAULT_CONNECTION,
191-
'indexer' => self::DEFAULT_CONNECTION,
192-
]
193-
];
194194
$this->dbConfigMock->expects($this->once())
195195
->method('get')
196-
->willReturn($dbConfig);
196+
->willReturn($envConfig);
197197
$this->loggerMock->expects($this->once())
198198
->method('info')
199199
->with('Updating env.php DB connection configuration.');
200200
$this->configReaderMock->expects($this->once())
201201
->method('read')
202-
->willReturn([
203-
'db' => $dbConfig,
204-
'resource' => $resourceConfig
205-
]);
202+
->willReturn($mageConfig);
206203
$this->resourceConfigMock->expects($this->once())
207204
->method('get')
208205
->willReturn($resourceConfig);
@@ -212,16 +209,51 @@ public function testExecuteWithoutSplitAndSlaveConfig()
212209
->willReturnOnConsecutiveCalls(false, []);
213210
$this->configWriterMock->expects($this->once())
214211
->method('create')
215-
->with([
216-
'db' => $dbConfig,
217-
'resource' => $resourceConfig
218-
]);
212+
->with($expectedResult);
219213
$this->flagManagerMock->expects($this->never())
220214
->method('set');
221215

222216
$this->step->execute();
223217
}
224218

219+
/**
220+
* @return array
221+
*/
222+
public function executeWithoutSplitAndSlaveConfigDataProvider()
223+
{
224+
$dbConfig = [
225+
'connection' => [
226+
'default' => self::DEFAULT_CONNECTION,
227+
'indexer' => self::DEFAULT_CONNECTION,
228+
]
229+
];
230+
$newConnection = array_merge(self::DEFAULT_CONNECTION, ['host' => 'host2']);
231+
$newBbConfig = [
232+
'connection' => [
233+
'default' => $newConnection,
234+
'indexer' => $newConnection,
235+
]
236+
];
237+
238+
return [
239+
[
240+
['db' => $dbConfig],
241+
$dbConfig,
242+
['db' => $dbConfig],
243+
],
244+
'changed connection' => [
245+
['db' => $dbConfig],
246+
$newBbConfig,
247+
['db' => $newBbConfig],
248+
],
249+
'no data before' => [
250+
[],
251+
$dbConfig,
252+
['db' => $dbConfig],
253+
],
254+
];
255+
}
256+
225257
/**
226258
* Case with slave connections and without split config
227259
*/

0 commit comments

Comments
 (0)