14
14
use PHPUnit \Framework \TestCase ;
15
15
16
16
/**
17
- * Test for existance of primary key in database tables
17
+ * Test for finding database tables missing primary key
18
18
*/
19
19
class PrimaryKeyTest extends TestCase
20
20
{
21
- private $ blockWhitelist ;
22
-
23
21
/**
24
- * Check existance of database tables' primary key
22
+ * Check missing database tables' primary key
25
23
*
26
24
* @throws LocalizedException
27
25
*/
28
26
public function testMissingPrimaryKey ()
29
27
{
30
- $ exemptionList = $ this ->getExemptionlist ();
31
- $ tablesSchemaDeclaration = $ this ->getDbSchemaDeclaration ()['table ' ];
28
+ $ exemptionList = $ this ->getExemptionList ();
29
+ $ tablesSchemaDeclaration = $ this ->getDbSchemaDeclarations ()['table ' ];
32
30
$ exemptionList = array_intersect (array_keys ($ tablesSchemaDeclaration ), $ exemptionList );
33
31
foreach ($ exemptionList as $ exemptionTableName ) {
34
32
unset($ tablesSchemaDeclaration [$ exemptionTableName ]);
@@ -91,9 +89,9 @@ private function getDbSchemaDeclarationByFile(string $filePath): array
91
89
* @return array
92
90
* @throws LocalizedException
93
91
*/
94
- private function getDbSchemaDeclaration (): array
92
+ private function getDbSchemaDeclarations (): array
95
93
{
96
- $ declaration = [];
94
+ $ declarations = [];
97
95
foreach (Files::init ()->getDbSchemaFiles () as $ filePath ) {
98
96
$ filePath = reset ($ filePath );
99
97
preg_match ('#app/code/(\w+/\w+)# ' , $ filePath , $ result );
@@ -107,23 +105,24 @@ private function getDbSchemaDeclaration(): array
107
105
array_push ($ tableDeclaration ['modules ' ], $ moduleName );
108
106
$ moduleDeclaration = array_replace_recursive (
109
107
$ moduleDeclaration ,
110
- ['table ' => [
111
- $ tableName => $ tableDeclaration ,
112
- ]
108
+ [
109
+ 'table ' => [
110
+ $ tableName => $ tableDeclaration ,
111
+ ]
113
112
]
114
113
);
115
114
}
116
- $ declaration = array_merge_recursive ($ declaration , $ moduleDeclaration );
115
+ $ declarations = array_merge_recursive ($ declarations , $ moduleDeclaration );
117
116
}
118
- return $ declaration ;
117
+ return $ declarations ;
119
118
}
120
119
121
120
/**
122
121
* Return primary key exemption tables list
123
122
*
124
123
* @return string[]
125
124
*/
126
- private function getExemptionlist (): array
125
+ private function getExemptionList (): array
127
126
{
128
127
$ exemptionListFiles = str_replace (
129
128
'\\' ,
0 commit comments