@@ -60,93 +60,48 @@ public function testCodeStyle(): void
6060
6161 /**
6262 * Test if there is corresponding GraphQL module change for each magento core modules
63+ *
64+ * @return void
65+ * @throws \Magento\Framework\Exception\LocalizedException
6366 */
6467 public function testCorrespondingGraphQlChangeExists (): void
6568 {
66- $ changedModules = self ::getChangedCoreModules ();
69+ $ changedModules = PHPCodeTest ::getChangedCoreModules (self :: $ changeCheckDir );
6770
6871 // Check if for each module change, a graphQL module change happened
69- foreach ($ changedModules as $ changedModule ) {
72+ foreach ($ changedModules as $ module => $ fileStat ) {
73+
74+ if (str_ends_with ($ module , 'GraphQl ' )) {
75+ continue ;
76+ }
7077
71- // get the git diff status of the module files
72- $ fileStat = self ::getGitDiff (self ::$ changeCheckDir . '/ ' . $ changedModule );
73- $ fileChanged = $ fileStat ['insertions ' ] >= 5 || $ fileStat ['deletions ' ] >= 5 ;
78+ $ fileChanged = $ fileStat ['filesChanged ' ] ||
79+ $ fileStat ['insertions ' ] ||
80+ $ fileStat ['deletions ' ] ||
81+ $ fileStat ['paramsChanged ' ];
7482
7583 // check if there is a reasonable change happened in the module
7684 if ($ fileChanged ) {
77- // get the git diff status of the graphQL module files
78- $ graphQlFileStat = self ::getGitDiff (self ::$ changeCheckDir . '/ ' . $ changedModule . 'GraphQl ' );
79-
80- // assert if there is change in graphql module
81- $ this ->assertTrue (
82- $ graphQlFileStat ['insertions ' ] >= 1 || $ graphQlFileStat ['deletions ' ] >= 1 ,
83- $ changedModule . "'s corresponding GraphQl module change is missing "
85+ $ this ->assertArrayHasKey (
86+ $ module . 'GraphQl ' ,
87+ $ changedModules ,
88+ $ module . "'s corresponding GraphQl module change is missing "
8489 );
85- }
86- }
87- }
88-
89- /**
90- * returns a multi array with the list of core and graphql modules names
91- *
92- * @return array
93- * @throws \Magento\Framework\Exception\LocalizedException
94- */
95- private static function getChangedCoreModules (): array
96- {
97- $ whitelistFiles = PHPCodeTest::getWhitelist (['php ' , 'graphqls ' ], '' , '' , '/_files/whitelist/graphql.txt ' );
98-
99- $ changedModules = [];
100- foreach ($ whitelistFiles as $ whitelistFile ) {
101- $ fileName = substr ($ whitelistFile , strlen (self ::$ changeCheckDir ));
102- $ changedModule = explode ('/ ' , $ fileName );
10390
104- $ isGraphQlModule = str_ends_with ($ changedModule [1 ], 'GraphQl ' );
105- $ isGraphQlModuleExists = file_exists (self ::$ changeCheckDir . '/ ' . $ changedModule [1 ] . 'GraphQl ' );
106-
107- if (!$ isGraphQlModule && $ isGraphQlModuleExists &&
108- (
109- in_array ($ changedModule [2 ], ["Controller " , "Model " , "Block " ]) ||
110- (($ changedModule [2 ] == "Ui " ) && in_array ($ changedModule [3 ], ["Component " , "DataProvider " ]))
111- )
112- ) {
113- $ changedModules [] = $ changedModule [1 ];
91+ if (isset ($ changedModules [$ module . 'GraphQl ' ])) {
92+
93+ // assert if there is change in graphql module
94+ $ this ->assertTrue (
95+ (
96+ $ changedModules [$ module . 'GraphQl ' ]['filesChanged ' ] ||
97+ $ changedModules [$ module . 'GraphQl ' ]['insertions ' ] ||
98+ $ changedModules [$ module . 'GraphQl ' ]['deletions ' ] ||
99+ $ changedModules [$ module . 'GraphQl ' ]['paramsChanged ' ]
100+ ),
101+ $ module . "'s corresponding GraphQl module change is missing "
102+ );
103+ }
114104 }
115105 }
116-
117- return array_unique ($ changedModules );
118- }
119-
120- /**
121- * @param string $directory
122- * @return array
123- * @throws \Magento\Framework\Exception\LocalizedException
124- */
125- private static function getGitDiff ($ directory = '' ): array
126- {
127- $ shell = new \Magento \Framework \Shell (
128- new \Magento \Framework \Shell \CommandRenderer ()
129- );
130-
131- $ fileStat = explode (
132- PHP_EOL ,
133- $ shell ->execute ('git diff --stat ' . $ directory )
134- );
135-
136- $ insertions = 0 ;
137- $ deletions = 0 ;
138- $ fileChanges = 0 ;
139- if (array_key_exists (3 , $ fileStat )) {
140- list ($ fileChanges , $ insertions , $ deletions ) = explode (", " , $ fileStat [3 ]);
141- $ fileChanges = intval ($ fileChanges );
142- $ insertions = intval ($ insertions );
143- $ deletions = intval ($ deletions );
144- }
145-
146- return [
147- 'fileChanges ' => $ fileChanges ,
148- 'insertions ' => $ insertions ,
149- 'deletions ' => $ deletions
150- ];
151106 }
152107}
0 commit comments