Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit efd0f90

Browse files
author
Sergii Kovalenko
committed
MAGETWO-87190: Test coverage for critical logic
1 parent fbaa3f2 commit efd0f90

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

setup/src/Magento/Setup/Model/Declaration/Schema/Diff/SchemaDiff.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@ public function __construct(
5959
$this->operationsExecutor = $operationsExecutor;
6060
}
6161

62+
/**
63+
* Create consistent table index from all tables
64+
*
65+
* All declared table names should have order, all tables exists only in db should goes after them
66+
*
67+
* @param array $tableNames
68+
* @param array $generatedTableNames
69+
* @return array
70+
*/
71+
private function createTableIndex(array $tableNames, array $generatedTableNames)
72+
{
73+
$tableNames = array_flip($tableNames);
74+
foreach ($generatedTableNames as $tableName) {
75+
//If table exists only in db
76+
if (!isset($tableNames[$tableName])) {
77+
array_push($tableNames, $tableName);
78+
}
79+
}
80+
81+
return $tableNames;
82+
}
83+
6284
/**
6385
* Create diff.
6486
*
@@ -71,10 +93,12 @@ public function diff(
7193
Schema $generatedSchema
7294
) {
7395
$generatedTables = $generatedSchema->getTables();
74-
$tableIndex = array_flip(array_keys($schema->getTables()));
96+
$tableNames = array_keys($schema->getTables());
97+
$generatedTableNames = array_keys($generatedSchema->getTables());
98+
7599
$diff = $this->diffFactory->create(
76100
[
77-
'tableIndexes' => $tableIndex,
101+
'tableIndexes' => $this->createTableIndex($tableNames, $generatedTableNames),
78102
'destructiveOperations' => $this->operationsExecutor->getDestructiveOperations()
79103
]
80104
);

0 commit comments

Comments
 (0)