@@ -91,11 +91,11 @@ class ModuleResolver
9191 protected $ enabledModulePaths = null ;
9292
9393 /**
94- * Paths for non flattened enabled modules.
94+ * Name and path for enabled modules
9595 *
9696 * @var array|null
9797 */
98- protected $ nonFlattenedEnabledModulePaths = null ;
98+ protected $ enabledModuleNameAndPaths = null ;
9999
100100 /**
101101 * Configuration instance.
@@ -156,7 +156,7 @@ class ModuleResolver
156156 ];
157157
158158 /**
159- * Registered module list in magento instance being tested
159+ * Registered module list in magento system under test
160160 *
161161 * @var array
162162 */
@@ -249,83 +249,50 @@ public function getEnabledModules()
249249 /**
250250 * Return the modules path based on which modules are enabled in the target Magento instance.
251251 *
252- * @param boolean $flat
252+ * @param boolean $verbose
253253 * @return array
254254 */
255- public function getModulesPath ($ flat = true )
255+ public function getModulesPath ($ verbose = false )
256256 {
257- if (isset ($ this ->enabledModulePaths ) && $ flat ) {
257+ if (isset ($ this ->enabledModulePaths ) && ! $ verbose ) {
258258 return $ this ->enabledModulePaths ;
259259 }
260260
261- if (isset ($ this ->nonFlattenedEnabledModulePaths ) && ! $ flat ) {
262- return $ this ->nonFlattenedEnabledModulePaths ;
261+ if (isset ($ this ->enabledModuleNameAndPaths ) && $ verbose ) {
262+ return $ this ->enabledModuleNameAndPaths ;
263263 }
264264
265+ // Find test modules paths by searching patterns (Test/Mftf, etc)
265266 $ allModulePaths = $ this ->aggregateTestModulePaths ();
266267
267- $ composerBsedModulePaths = $ this ->aggregateTestModulePathsFromComposerJson ();
268- $ composerBsedModulePaths = array_merge (
269- $ composerBsedModulePaths ,
268+ // Find test modules paths by searching test composer.json files
269+ $ composerBasedModulePaths = $ this ->aggregateTestModulePathsFromComposerJson ();
270+
271+ // Find test modules paths by querying composer installed packages
272+ $ composerBasedModulePaths = array_merge (
273+ $ composerBasedModulePaths ,
270274 $ this ->aggregateTestModulePathsFromComposerInstaller ()
271275 );
272276
273- $ allModulePaths = $ this ->mergeModulePaths ($ allModulePaths , $ composerBsedModulePaths );
277+ // Merge test module paths altogether
278+ $ allModulePaths = $ this ->mergeModulePaths ($ allModulePaths , $ composerBasedModulePaths );
274279
280+ // Normalize module names if we get registered module names from Magento system
275281 $ allModulePaths = $ this ->normalizeModuleNames ($ allModulePaths );
276282
277283 if (MftfApplicationConfig::getConfig ()->forceGenerateEnabled ()) {
278- $ allModulePaths = $ this ->flipAndFilterArray ($ allModulePaths );
284+ $ allModulePaths = $ this ->flipAndFilterModulePathsArray ($ allModulePaths );
279285 $ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ allModulePaths );
280286 return $ this ->enabledModulePaths ;
281287 }
282288
283289 $ enabledModules = array_merge ($ this ->getEnabledModules (), $ this ->getModuleWhitelist ());
284- $ enabledDirectoryPaths = $ this ->flipAndFilterArray ($ allModulePaths , $ enabledModules );
285-
290+ $ enabledDirectoryPaths = $ this ->flipAndFilterModulePathsArray ($ allModulePaths , $ enabledModules );
286291 $ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ enabledDirectoryPaths );
287- return $ this ->enabledModulePaths ;
288- }
289292
290- /**
291- * @param array $objectArray
292- * @param array $filterArray
293- * @return array
294- */
295- private function flipAndFilterArray ($ objectArray , $ filterArray = null )
296- {
297- $ flippedArray = [];
298- foreach ($ objectArray as $ path => $ modules ) {
299- if (count ($ modules ) == 1 ) {
300- if (!is_array ($ filterArray )
301- || (is_array ($ filterArray ) && in_array ($ modules [0 ], $ filterArray ))
302- || isset ($ this ->knownDirectories [$ modules [0 ]])) {
303- if (strpos ($ modules [0 ], '_ ' ) === false ) {
304- $ modules [0 ] = $ this ->getPossibleVendorName ($ path ) . '_ ' . $ modules [0 ];
305- }
306- $ flippedArray [$ modules [0 ]] = $ path ;
307- }
308- } else {
309- if (!is_array ($ filterArray )) {
310- $ flippedArray [$ this ->getPossibleVendorModuleName ($ path )] = $ path ;
311- } else {
312- $ skip = false ;
313- foreach ($ modules as $ module ) {
314- if (!in_array ($ module , $ filterArray )) {
315- $ skip = true ;
316- break ;
317- }
318- }
319- if (!$ skip ) {
320- $ flippedArray [$ this ->getPossibleVendorModuleName ($ path )] = $ path ;
321- }
322- }
323- }
324- }
325- return $ flippedArray ;
293+ return $ this ->enabledModulePaths ;
326294 }
327295
328-
329296 /**
330297 * Sort files according module sequence.
331298 *
@@ -422,18 +389,21 @@ private function globRelevantPaths($testPath, $pattern)
422389 }
423390 }
424391
425- // Suppress print during unit testing
426- if (MftfApplicationConfig::getConfig ()->getPhase () !== MftfApplicationConfig::UNIT_TEST_PHASE
427- && strpos ($ testPath , self ::DEPRECATED_DEV_TESTS ) !== false
428- && !empty ($ modulePaths )
429- ) {
392+ if (strpos ($ testPath , self ::DEPRECATED_DEV_TESTS ) !== false && !empty ($ modulePaths )) {
430393 $ deprecatedPath = self ::DEPRECATED_DEV_TESTS ;
431394 $ suggestedPath = self ::DEV_TESTS . DIRECTORY_SEPARATOR . 'Magento ' ;
432- LoggingUtil::getInstance ()->getLogger (ModuleResolver::class)->warning (
433- "DEPRECATION: $ deprecatedPath is deprecated! Please move mftf test modules to $ suggestedPath "
434- );
435- print ("\nDEPRECATION: $ deprecatedPath is deprecated! Please move mftf tests to $ suggestedPath \n\n" );
395+ $ message = "DEPRECATION: Found MFTF test modules in the deprecated path: $ deprecatedPath. "
396+ . " Move these test modules to $ suggestedPath. " ;
397+
398+ if (MftfApplicationConfig::getConfig ()->verboseEnabled ()) {
399+ LoggingUtil::getInstance ()->getLogger (ModuleResolver::class)->warning ($ message );
400+ }
401+ // Suppress print during unit testing
402+ if (MftfApplicationConfig::getConfig ()->getPhase () !== MftfApplicationConfig::UNIT_TEST_PHASE ) {
403+ print ("\n$ message \n\n" );
404+ }
436405 }
406+
437407 return $ modulePaths ;
438408 }
439409
@@ -458,16 +428,16 @@ private static function globRelevantWrapper($testPath, $pattern)
458428 }
459429
460430 /**
461- * Retrieves all code paths by searching composer json where might contain pertinent test modules
431+ * Aggregate all code paths with test module composer json files
462432 *
463433 * @return array
464434 */
465435 private function aggregateTestModulePathsFromComposerJson ()
466436 {
467- // Define the Module paths from magento bp
437+ // Define the module paths
468438 $ magentoBaseCodePath = MAGENTO_BP ;
469439
470- // Define the Module paths from default TESTS_MODULE_PATH
440+ // Define the module paths from default TESTS_MODULE_PATH
471441 $ modulePath = defined ('TESTS_MODULE_PATH ' ) ? TESTS_MODULE_PATH : TESTS_BP ;
472442 $ modulePath = rtrim ($ modulePath , DIRECTORY_SEPARATOR );
473443
@@ -484,7 +454,7 @@ private function aggregateTestModulePathsFromComposerJson()
484454 }
485455
486456 /**
487- * Retrieve composer json based test module paths from give $codePath
457+ * Retrieve all module code paths that have test module composer json files
488458 *
489459 * @param array $codePaths
490460 * @return array
@@ -505,21 +475,21 @@ private function getComposerJsonTestModulePaths($codePaths)
505475 }
506476
507477 /**
508- * Retrieves all module directories which might contain pertinent test code.
478+ * Aggregate all code paths with composer installed test modules
509479 *
510480 * @return array
511481 */
512482 private function aggregateTestModulePathsFromComposerInstaller ()
513483 {
514- // Define the Module paths from magento bp
484+ // Define the module paths
515485 $ magentoBaseCodePath = MAGENTO_BP ;
516486 $ composerFile = $ magentoBaseCodePath . DIRECTORY_SEPARATOR . 'composer.json ' ;
517487
518488 return $ this ->getComposerInstalledTestModulePaths ($ composerFile );
519489 }
520490
521491 /**
522- * Retrieve composer json based test module paths from give $codePath
492+ * Retrieve composer installed test module code paths
523493 *
524494 * @params string $composerFile
525495 * @return array
@@ -539,6 +509,49 @@ private function getComposerInstalledTestModulePaths($composerFile)
539509 return $ this ->composerInstalledModulePaths ;
540510 }
541511
512+ /**
513+ * Flip and filter module code paths
514+ * when
515+ *
516+ * @param array $objectArray
517+ * @param array $filterArray
518+ * @return array
519+ */
520+ private function flipAndFilterModulePathsArray ($ objectArray , $ filterArray = null )
521+ {
522+ $ flippedArray = [];
523+ foreach ($ objectArray as $ path => $ modules ) {
524+ // One path maps to one module
525+ if (count ($ modules ) == 1 ) {
526+ if (!is_array ($ filterArray )
527+ || (is_array ($ filterArray ) && in_array ($ modules [0 ], $ filterArray ))
528+ || isset ($ this ->knownDirectories [$ modules [0 ]])) {
529+ if (strpos ($ modules [0 ], '_ ' ) === false ) {
530+ $ modules [0 ] = $ this ->findVendorNameFromPath ($ path ) . '_ ' . $ modules [0 ];
531+ }
532+ $ flippedArray [$ modules [0 ]] = $ path ;
533+ }
534+ } else {
535+ // One path maps to multiple modules
536+ if (!is_array ($ filterArray )) {
537+ $ flippedArray [$ this ->findVendorAndModuleNameFromPath ($ path )] = $ path ;
538+ } else {
539+ $ skip = false ;
540+ foreach ($ modules as $ module ) {
541+ if (!in_array ($ module , $ filterArray )) {
542+ $ skip = true ;
543+ break ;
544+ }
545+ }
546+ if (!$ skip ) {
547+ $ flippedArray [$ this ->findVendorAndModuleNameFromPath ($ path )] = $ path ;
548+ }
549+ }
550+ }
551+ }
552+ return $ flippedArray ;
553+ }
554+
542555 /**
543556 * Merge code paths
544557 *
@@ -712,8 +725,8 @@ protected function applyCustomModuleMethods($modulesPath)
712725 );
713726 }, $ customModulePaths );
714727
715- if (!isset ($ this ->nonFlattenedEnabledModulePaths )) {
716- $ this ->nonFlattenedEnabledModulePaths = array_merge ($ modulePathsResult , $ customModulePaths );
728+ if (!isset ($ this ->enabledModuleNameAndPaths )) {
729+ $ this ->enabledModuleNameAndPaths = array_merge ($ modulePathsResult , $ customModulePaths );
717730 }
718731 return $ this ->flattenAllModulePaths (array_merge ($ modulePathsResult , $ customModulePaths ));
719732 }
@@ -821,24 +834,24 @@ private function getBackendUrl()
821834 }
822835
823836 /**
824- * Return possible vendor name from a path given
837+ * Find vendor and module name from path
825838 *
826839 * @param string $path
827840 * @return string
828841 */
829- private function getPossibleVendorModuleName ($ path )
842+ private function findVendorAndModuleNameFromPath ($ path )
830843 {
831844 $ path = str_replace (DIRECTORY_SEPARATOR . self ::TEST_MFTF_PATTERN , '' , $ path );
832- return $ this ->getPossibleVendorName ($ path ) . '_ ' . basename ($ path );
845+ return $ this ->findVendorNameFromPath ($ path ) . '_ ' . basename ($ path );
833846 }
834847
835848 /**
836- * Return possible vendor name from a path given
849+ * Find vendor name from path
837850 *
838851 * @param string $path
839852 * @return string
840853 */
841- private function getPossibleVendorName ($ path )
854+ private function findVendorNameFromPath ($ path )
842855 {
843856 $ possibleVendorName = 'UnknownVendor ' ;
844857 $ dirPaths = [
0 commit comments