@@ -200,14 +200,7 @@ public function getModulesPath()
200200 );
201201 }
202202
203- $ modulePath = defined ('TESTS_MODULE_PATH ' ) ? TESTS_MODULE_PATH : TESTS_BP ;
204-
205- // Build an associative array of module name to existing module filepaths based on defined TEST MODULE PATH
206- $ allModulePaths = [];
207- foreach (glob ($ modulePath . '*/* ' ) as $ modPath ) {
208- $ modName = basename ($ modPath );
209- $ allModulePaths [$ modName ] = $ modPath ;
210- }
203+ $ allModulePaths = $ this ->aggregateTestModulePaths ();
211204
212205 if (empty ($ enabledModules )) {
213206 $ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ allModulePaths );
@@ -221,6 +214,69 @@ public function getModulesPath()
221214 return $ this ->enabledModulePaths ;
222215 }
223216
217+ /**
218+ * Retrieves all module directories which might contain pertinent test code.
219+ *
220+ * @return array
221+ */
222+ private function aggregateTestModulePaths ()
223+ {
224+ $ allModulePaths = [];
225+ $ appCodeTestPaths = [];
226+ $ testModuleCodePaths = [];
227+
228+ // Define the Module paths from app/code
229+ $ appCodePath = dirname (dirname (dirname (PROJECT_ROOT )))
230+ . DIRECTORY_SEPARATOR
231+ . 'app ' . DIRECTORY_SEPARATOR
232+ . 'code ' . DIRECTORY_SEPARATOR
233+ . 'Magento ' ;
234+
235+ // Define the Module paths from defualt TESTS_MODULE_PATH
236+ $ modulePath = defined ('TESTS_MODULE_PATH ' ) ? TESTS_MODULE_PATH : TESTS_BP ;
237+
238+ if (file_exists ($ appCodePath )) {
239+ $ appCodeTestPaths = glob ($ appCodePath . '*/*/Test/Acceptance ' );
240+ }
241+
242+ // Build an associative array of module name to existing module filepaths based on app/code path
243+ foreach ($ appCodeTestPaths as $ appCodePath ) {
244+ $ mainModName = basename (str_replace ('/Test/Acceptance ' , '' , $ appCodePath ));
245+ $ allModulePaths [$ mainModName ][] = $ appCodePath ;
246+ }
247+
248+ // TODO IMPROVE THIS TO ONLY GREP RELEVANT .XML FILES
249+ if (file_exists ($ modulePath )) {
250+ $ testModuleCodePaths = glob ($ modulePath . '*/* ' );
251+ }
252+
253+ // Add to associative array of module name to existing module filepaths based on defined TEST MODULE PATH
254+ foreach ($ testModuleCodePaths as $ modPath ) {
255+ $ modName = basename ($ modPath );
256+ $ allModulePaths [$ modName ][] = $ modPath ;
257+ }
258+
259+ return $ allModulePaths ;
260+ }
261+
262+ /**
263+ * Takes a multidimensional array of module paths and flattens to return a one dimensional array of test paths
264+ *
265+ * @param array $modulePaths
266+ * @return array
267+ */
268+ private function flattenAllModulePaths ($ modulePaths )
269+ {
270+ $ it = new \RecursiveIteratorIterator (new \RecursiveArrayIterator ($ modulePaths ));
271+ $ resultArray = [];
272+
273+ foreach ($ it as $ value ) {
274+ $ resultArray [] = $ value ;
275+ }
276+
277+ return $ resultArray ;
278+ }
279+
224280 /**
225281 * Runs through enabled modules and maps them known module paths by name.
226282 * @param array $enabledModules
@@ -325,7 +381,7 @@ protected function applyCustomModuleMethods($modulesPath)
325381 print "Including module path: {$ value }\n" ;
326382 }, $ customModulePaths );
327383
328- return array_merge ($ modulePathsResult , $ customModulePaths );
384+ return $ this -> flattenAllModulePaths ( array_merge ($ modulePathsResult , $ customModulePaths) );
329385 }
330386
331387 /**
0 commit comments