@@ -91,11 +91,11 @@ class ModuleResolver
91
91
protected $ enabledModulePaths = null ;
92
92
93
93
/**
94
- * Paths for non flattened enabled modules.
94
+ * Name and path for enabled modules
95
95
*
96
96
* @var array|null
97
97
*/
98
- protected $ nonFlattenedEnabledModulePaths = null ;
98
+ protected $ enabledModuleNameAndPaths = null ;
99
99
100
100
/**
101
101
* Configuration instance.
@@ -156,7 +156,7 @@ class ModuleResolver
156
156
];
157
157
158
158
/**
159
- * Registered module list in magento instance being tested
159
+ * Registered module list in magento system under test
160
160
*
161
161
* @var array
162
162
*/
@@ -249,83 +249,50 @@ public function getEnabledModules()
249
249
/**
250
250
* Return the modules path based on which modules are enabled in the target Magento instance.
251
251
*
252
- * @param boolean $flat
252
+ * @param boolean $verbose
253
253
* @return array
254
254
*/
255
- public function getModulesPath ($ flat = true )
255
+ public function getModulesPath ($ verbose = false )
256
256
{
257
- if (isset ($ this ->enabledModulePaths ) && $ flat ) {
257
+ if (isset ($ this ->enabledModulePaths ) && ! $ verbose ) {
258
258
return $ this ->enabledModulePaths ;
259
259
}
260
260
261
- if (isset ($ this ->nonFlattenedEnabledModulePaths ) && ! $ flat ) {
262
- return $ this ->nonFlattenedEnabledModulePaths ;
261
+ if (isset ($ this ->enabledModuleNameAndPaths ) && $ verbose ) {
262
+ return $ this ->enabledModuleNameAndPaths ;
263
263
}
264
264
265
+ // Find test modules paths by searching patterns (Test/Mftf, etc)
265
266
$ allModulePaths = $ this ->aggregateTestModulePaths ();
266
267
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 ,
270
274
$ this ->aggregateTestModulePathsFromComposerInstaller ()
271
275
);
272
276
273
- $ allModulePaths = $ this ->mergeModulePaths ($ allModulePaths , $ composerBsedModulePaths );
277
+ // Merge test module paths altogether
278
+ $ allModulePaths = $ this ->mergeModulePaths ($ allModulePaths , $ composerBasedModulePaths );
274
279
280
+ // Normalize module names if we get registered module names from Magento system
275
281
$ allModulePaths = $ this ->normalizeModuleNames ($ allModulePaths );
276
282
277
283
if (MftfApplicationConfig::getConfig ()->forceGenerateEnabled ()) {
278
- $ allModulePaths = $ this ->flipAndFilterArray ($ allModulePaths );
284
+ $ allModulePaths = $ this ->flipAndFilterModulePathsArray ($ allModulePaths );
279
285
$ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ allModulePaths );
280
286
return $ this ->enabledModulePaths ;
281
287
}
282
288
283
289
$ enabledModules = array_merge ($ this ->getEnabledModules (), $ this ->getModuleWhitelist ());
284
- $ enabledDirectoryPaths = $ this ->flipAndFilterArray ($ allModulePaths , $ enabledModules );
285
-
290
+ $ enabledDirectoryPaths = $ this ->flipAndFilterModulePathsArray ($ allModulePaths , $ enabledModules );
286
291
$ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ enabledDirectoryPaths );
287
- return $ this ->enabledModulePaths ;
288
- }
289
292
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 ;
326
294
}
327
295
328
-
329
296
/**
330
297
* Sort files according module sequence.
331
298
*
@@ -422,18 +389,21 @@ private function globRelevantPaths($testPath, $pattern)
422
389
}
423
390
}
424
391
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 )) {
430
393
$ deprecatedPath = self ::DEPRECATED_DEV_TESTS ;
431
394
$ 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
+ }
436
405
}
406
+
437
407
return $ modulePaths ;
438
408
}
439
409
@@ -458,16 +428,16 @@ private static function globRelevantWrapper($testPath, $pattern)
458
428
}
459
429
460
430
/**
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
462
432
*
463
433
* @return array
464
434
*/
465
435
private function aggregateTestModulePathsFromComposerJson ()
466
436
{
467
- // Define the Module paths from magento bp
437
+ // Define the module paths
468
438
$ magentoBaseCodePath = MAGENTO_BP ;
469
439
470
- // Define the Module paths from default TESTS_MODULE_PATH
440
+ // Define the module paths from default TESTS_MODULE_PATH
471
441
$ modulePath = defined ('TESTS_MODULE_PATH ' ) ? TESTS_MODULE_PATH : TESTS_BP ;
472
442
$ modulePath = rtrim ($ modulePath , DIRECTORY_SEPARATOR );
473
443
@@ -484,7 +454,7 @@ private function aggregateTestModulePathsFromComposerJson()
484
454
}
485
455
486
456
/**
487
- * Retrieve composer json based test module paths from give $codePath
457
+ * Retrieve all module code paths that have test module composer json files
488
458
*
489
459
* @param array $codePaths
490
460
* @return array
@@ -505,21 +475,21 @@ private function getComposerJsonTestModulePaths($codePaths)
505
475
}
506
476
507
477
/**
508
- * Retrieves all module directories which might contain pertinent test code.
478
+ * Aggregate all code paths with composer installed test modules
509
479
*
510
480
* @return array
511
481
*/
512
482
private function aggregateTestModulePathsFromComposerInstaller ()
513
483
{
514
- // Define the Module paths from magento bp
484
+ // Define the module paths
515
485
$ magentoBaseCodePath = MAGENTO_BP ;
516
486
$ composerFile = $ magentoBaseCodePath . DIRECTORY_SEPARATOR . 'composer.json ' ;
517
487
518
488
return $ this ->getComposerInstalledTestModulePaths ($ composerFile );
519
489
}
520
490
521
491
/**
522
- * Retrieve composer json based test module paths from give $codePath
492
+ * Retrieve composer installed test module code paths
523
493
*
524
494
* @params string $composerFile
525
495
* @return array
@@ -539,6 +509,49 @@ private function getComposerInstalledTestModulePaths($composerFile)
539
509
return $ this ->composerInstalledModulePaths ;
540
510
}
541
511
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
+
542
555
/**
543
556
* Merge code paths
544
557
*
@@ -712,8 +725,8 @@ protected function applyCustomModuleMethods($modulesPath)
712
725
);
713
726
}, $ customModulePaths );
714
727
715
- if (!isset ($ this ->nonFlattenedEnabledModulePaths )) {
716
- $ this ->nonFlattenedEnabledModulePaths = array_merge ($ modulePathsResult , $ customModulePaths );
728
+ if (!isset ($ this ->enabledModuleNameAndPaths )) {
729
+ $ this ->enabledModuleNameAndPaths = array_merge ($ modulePathsResult , $ customModulePaths );
717
730
}
718
731
return $ this ->flattenAllModulePaths (array_merge ($ modulePathsResult , $ customModulePaths ));
719
732
}
@@ -821,24 +834,24 @@ private function getBackendUrl()
821
834
}
822
835
823
836
/**
824
- * Return possible vendor name from a path given
837
+ * Find vendor and module name from path
825
838
*
826
839
* @param string $path
827
840
* @return string
828
841
*/
829
- private function getPossibleVendorModuleName ($ path )
842
+ private function findVendorAndModuleNameFromPath ($ path )
830
843
{
831
844
$ path = str_replace (DIRECTORY_SEPARATOR . self ::TEST_MFTF_PATTERN , '' , $ path );
832
- return $ this ->getPossibleVendorName ($ path ) . '_ ' . basename ($ path );
845
+ return $ this ->findVendorNameFromPath ($ path ) . '_ ' . basename ($ path );
833
846
}
834
847
835
848
/**
836
- * Return possible vendor name from a path given
849
+ * Find vendor name from path
837
850
*
838
851
* @param string $path
839
852
* @return string
840
853
*/
841
- private function getPossibleVendorName ($ path )
854
+ private function findVendorNameFromPath ($ path )
842
855
{
843
856
$ possibleVendorName = 'UnknownVendor ' ;
844
857
$ dirPaths = [
0 commit comments