@@ -28,6 +28,14 @@ class LiveCodeTest extends TestCase
2828 */
2929 private static $ changeCheckDir = '' ;
3030
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+
3139 /**
3240 * Setup basics for all tests
3341 */
@@ -87,22 +95,31 @@ public function testCorrespondingGraphQlChangeExists(): void
8795 */
8896 private static function getModulesWithViewLayerChanges (): array
8997 {
90- $ whitelistFiles = PHPCodeTest::getWhitelist (['php ' ], '' , '' , '/_files/whitelist/graphql.txt ' );
98+ $ whitelistFiles = PHPCodeTest::getWhitelist (
99+ ['php ' ],
100+ '' ,
101+ '' ,
102+ '/_files/whitelist/graphql.txt '
103+ );
91104
92105 $ affectedModules = [];
93106 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+ }
106123 }
107124 }
108125 return $ affectedModules ;
@@ -115,16 +132,23 @@ private static function getModulesWithViewLayerChanges(): array
115132 */
116133 private static function getChangedGraphQlModules (): array
117134 {
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+ );
119141
120142 $ affectedModules = [];
121143 foreach ($ whitelistFiles as $ whitelistFile ) {
122- $ changedModule = self ::getChangedModuleName ($ whitelistFile );
144+ $ PathParts = self ::getFileReferencePathParts ($ whitelistFile );
123145
124- $ isGraphQlModule = str_ends_with ($ changedModule [1 ], 'GraphQl ' );
146+ if (array_key_exists (1 , $ PathParts )) {
147+ $ isGraphQlModule = str_ends_with ($ PathParts [1 ], 'GraphQl ' );
125148
126- if ($ isGraphQlModule ) {
127- $ affectedModules [] = $ changedModule [1 ];
149+ if ($ isGraphQlModule ) {
150+ $ affectedModules [] = $ PathParts [1 ];
151+ }
128152 }
129153 }
130154 return $ affectedModules ;
@@ -134,9 +158,29 @@ private static function getChangedGraphQlModules(): array
134158 * @param string $whitelistFile
135159 * @return array
136160 */
137- private static function getChangedModuleName ( $ whitelistFile ): array
161+ private static function getFileReferencePathParts ( string $ whitelistFile ): array
138162 {
139163 $ fileName = substr ($ whitelistFile , strlen (self ::$ changeCheckDir ));
140164 return explode ('/ ' , $ fileName );
141165 }
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+ }
142186}
0 commit comments