Skip to content

Commit 0626112

Browse files
committed
B2B-1671: Detect Missing Primary Key in Table Schema Test
1 parent c310852 commit 0626112

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

dev/tests/static/testsuite/Magento/Test/Integrity/DBSchema/PrimaryKeyTest.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testMissingPrimaryKey()
3636
$errorMessage = '';
3737
$failedTableCtr = 0;
3838
foreach ($tablesSchemaDeclaration as $tableName => $tableSchemaDeclaration) {
39-
if (!isset($tableSchemaDeclaration['constraint']['PRIMARY'])) {
39+
if (!$this->hasPrimaryKey($tableSchemaDeclaration)) {
4040
$message = '';
4141
if (!empty($tableSchemaDeclaration['modules'])) {
4242
$message = "It is declared in the following modules: \n" . implode(
@@ -54,6 +54,24 @@ public function testMissingPrimaryKey()
5454
}
5555
}
5656

57+
/**
58+
* Check table schema and verify if the table has primary key defined.
59+
*
60+
* @param array $tableSchemaDeclaration
61+
* @return bool
62+
*/
63+
private function hasPrimaryKey(array $tableSchemaDeclaration): bool
64+
{
65+
if (isset($tableSchemaDeclaration['constraint'])) {
66+
foreach ($tableSchemaDeclaration['constraint'] as $constraint) {
67+
if ($constraint['type'] == 'primary') {
68+
return true;
69+
}
70+
}
71+
}
72+
return false;
73+
}
74+
5775
/**
5876
* Get database schema declaration from file.
5977
*

0 commit comments

Comments
 (0)