@@ -28,6 +28,14 @@ class LiveCodeTest extends TestCase
28
28
*/
29
29
private static $ changeCheckDir = '' ;
30
30
31
+ private static $ uiDataComponentInterface = [
32
+ 'Magento\Framework\Api\ExtensibleDataInterface ' ,
33
+ 'Magento\Framework\Api\CustomAttributesDataInterface ' ,
34
+ 'Magento\Framework\DataObject\IdentityInterface ' ,
35
+ 'Magento\Framework\View\Element\UiComponentInterface ' ,
36
+ 'Magento\Framework\View\Element\UiComponent\DataProvider\DataProviderInterface ' ,
37
+ ];
38
+
31
39
/**
32
40
* Setup basics for all tests
33
41
*/
@@ -87,22 +95,31 @@ public function testCorrespondingGraphQlChangeExists(): void
87
95
*/
88
96
private static function getModulesWithViewLayerChanges (): array
89
97
{
90
- $ whitelistFiles = PHPCodeTest::getWhitelist (['php ' ], '' , '' , '/_files/whitelist/graphql.txt ' );
98
+ $ whitelistFiles = PHPCodeTest::getWhitelist (
99
+ ['php ' ],
100
+ '' ,
101
+ '' ,
102
+ '/_files/whitelist/graphql.txt '
103
+ );
91
104
92
105
$ affectedModules = [];
93
106
foreach ($ whitelistFiles as $ whitelistFile ) {
94
- $ changedModule = self ::getChangedModuleName ($ whitelistFile );
95
-
96
- $ isGraphQlModule = str_ends_with ($ changedModule [1 ], 'GraphQl ' );
97
- $ isGraphQlModuleExists = file_exists (self ::$ changeCheckDir . '/ ' . $ changedModule [1 ] . 'GraphQl ' );
98
-
99
- if (!$ isGraphQlModule && $ isGraphQlModuleExists &&
100
- (
101
- in_array ($ changedModule [2 ], ["Controller " , "Model " , "Block " ]) ||
102
- (($ changedModule [2 ] == "Ui " ) && in_array ($ changedModule [3 ], ["Component " , "DataProvider " ]))
103
- )
104
- ) {
105
- $ affectedModules [] = $ changedModule [1 ];
107
+ $ PathParts = self ::getFileReferencePathParts ($ whitelistFile );
108
+
109
+ if (array_key_exists (1 , $ PathParts )) {
110
+ $ isGraphQlModule = str_ends_with ($ PathParts [1 ], 'GraphQl ' );
111
+ $ isGraphQlModuleExists = file_exists (
112
+ self ::$ changeCheckDir . '/ ' . $ PathParts [1 ] . 'GraphQl '
113
+ );
114
+
115
+ if (!$ isGraphQlModule && $ isGraphQlModuleExists &&
116
+ (
117
+ in_array ($ PathParts [2 ], ["Controller " , "Block " ]) ||
118
+ self ::checkIfImplementsUiDataInterfaces ($ whitelistFile )
119
+ )
120
+ ) {
121
+ $ affectedModules [] = $ PathParts [1 ];
122
+ }
106
123
}
107
124
}
108
125
return $ affectedModules ;
@@ -115,16 +132,23 @@ private static function getModulesWithViewLayerChanges(): array
115
132
*/
116
133
private static function getChangedGraphQlModules (): array
117
134
{
118
- $ whitelistFiles = PHPCodeTest::getWhitelist (['php ' , 'graphqls ' ], '' , '' , '/_files/whitelist/graphql.txt ' );
135
+ $ whitelistFiles = PHPCodeTest::getWhitelist (
136
+ ['php ' , 'graphqls ' ],
137
+ '' ,
138
+ '' ,
139
+ '/_files/whitelist/graphql.txt '
140
+ );
119
141
120
142
$ affectedModules = [];
121
143
foreach ($ whitelistFiles as $ whitelistFile ) {
122
- $ changedModule = self ::getChangedModuleName ($ whitelistFile );
144
+ $ PathParts = self ::getFileReferencePathParts ($ whitelistFile );
123
145
124
- $ isGraphQlModule = str_ends_with ($ changedModule [1 ], 'GraphQl ' );
146
+ if (array_key_exists (1 , $ PathParts )) {
147
+ $ isGraphQlModule = str_ends_with ($ PathParts [1 ], 'GraphQl ' );
125
148
126
- if ($ isGraphQlModule ) {
127
- $ affectedModules [] = $ changedModule [1 ];
149
+ if ($ isGraphQlModule ) {
150
+ $ affectedModules [] = $ PathParts [1 ];
151
+ }
128
152
}
129
153
}
130
154
return $ affectedModules ;
@@ -134,9 +158,29 @@ private static function getChangedGraphQlModules(): array
134
158
* @param string $whitelistFile
135
159
* @return array
136
160
*/
137
- private static function getChangedModuleName ( $ whitelistFile ): array
161
+ private static function getFileReferencePathParts ( string $ whitelistFile ): array
138
162
{
139
163
$ fileName = substr ($ whitelistFile , strlen (self ::$ changeCheckDir ));
140
164
return explode ('/ ' , $ fileName );
141
165
}
166
+
167
+ private static function checkIfImplementsUiDataInterfaces (string $ filename ): bool
168
+ {
169
+ $ classes = get_declared_classes ();
170
+ include $ filename ;
171
+ $ diff = array_diff (get_declared_classes (), $ classes );
172
+
173
+ $ interfaces = [];
174
+ if (count ($ diff )) {
175
+ $ interfaces = array_values (class_implements (array_values ($ diff )[0 ]));
176
+ }
177
+
178
+ if (
179
+ count (array_intersect ($ interfaces , self ::$ uiDataComponentInterface ))
180
+ ) {
181
+ return true ;
182
+ }
183
+
184
+ return false ;
185
+ }
142
186
}
0 commit comments