@@ -38,6 +38,11 @@ class ModuleResolver
38
38
*/
39
39
const REGISTRAR_CLASS = "\Magento\Framework\Component\ComponentRegistrar " ;
40
40
41
+ /**
42
+ * const for Test/Mftf
43
+ */
44
+ const TEST_MFTF_PATTERN = 'Test ' . DIRECTORY_SEPARATOR . 'Mftf ' ;
45
+
41
46
/**
42
47
* const for vendor
43
48
*/
@@ -267,6 +272,8 @@ public function getModulesPath($flat = true)
267
272
268
273
$ allModulePaths = $ this ->mergeModulePaths ($ allModulePaths , $ composerBsedModulePaths );
269
274
275
+ $ allModulePaths = $ this ->normalizeModuleNames ($ allModulePaths );
276
+
270
277
if (MftfApplicationConfig::getConfig ()->forceGenerateEnabled ()) {
271
278
$ allModulePaths = $ this ->flipAndFlattenArray ($ allModulePaths );
272
279
$ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ allModulePaths );
@@ -275,18 +282,18 @@ public function getModulesPath($flat = true)
275
282
276
283
$ enabledModules = array_merge ($ this ->getEnabledModules (), $ this ->getModuleWhitelist ());
277
284
//$enabledDirectoryPaths = $this->getEnabledDirectoryPaths($enabledModules, $allModulePaths);
278
- $ enabledDirectoryPaths = $ this ->flipAndFlattenArray ($ allModulePaths , $ enabledModules );
285
+ $ enabledDirectoryPaths = $ this ->flipAndFilterArray ($ allModulePaths , $ enabledModules );
279
286
280
287
$ this ->enabledModulePaths = $ this ->applyCustomModuleMethods ($ enabledDirectoryPaths );
281
288
return $ this ->enabledModulePaths ;
282
289
}
283
290
284
291
/**
285
- * @param array $targetArray
292
+ * @param array $objectArray
286
293
* @param array $filterArray
287
294
* @return array
288
295
*/
289
- private function flipAndFlattenArray ($ objectArray , $ filterArray = null )
296
+ private function flipAndFilterArray ($ objectArray , $ filterArray = null )
290
297
{
291
298
$ flippedArray = [];
292
299
foreach ($ objectArray as $ path => $ modules ) {
@@ -364,8 +371,8 @@ private function aggregateTestModulePaths()
364
371
365
372
$ codePathsToPattern = [
366
373
$ modulePath => '' ,
367
- $ magentoBaseCodePath . $ vendorCodePath => ' Test ' . DIRECTORY_SEPARATOR . ' Mftf ' ,
368
- $ magentoBaseCodePath . $ appCodePath => ' Test ' . DIRECTORY_SEPARATOR . ' Mftf ' ,
374
+ $ magentoBaseCodePath . $ vendorCodePath => self :: TEST_MFTF_PATTERN ,
375
+ $ magentoBaseCodePath . $ appCodePath => self :: TEST_MFTF_PATTERN ,
369
376
$ magentoBaseCodePath . self ::DEPRECATED_DEV_TESTS => ''
370
377
];
371
378
@@ -394,23 +401,15 @@ private function globRelevantPaths($testPath, $pattern)
394
401
$ relevantPaths = $ this ->globRelevantWrapper ($ testPath , $ pattern );
395
402
}
396
403
397
- $ allComponents = $ this ->getRegisteredModuleList ();
398
-
399
404
foreach ($ relevantPaths as $ codePath ) {
400
405
// Reduce magento/app/code/Magento/AdminGws/<pattern> to magento/app/code/Magento/AdminGws to read symlink
401
406
// Symlinks must be resolved otherwise they will not match Magento's filepath to the module
402
407
$ potentialSymlink = str_replace (DIRECTORY_SEPARATOR . $ pattern , "" , $ codePath );
403
408
if (is_link ($ potentialSymlink )) {
404
409
$ codePath = realpath ($ potentialSymlink ) . DIRECTORY_SEPARATOR . $ pattern ;
405
410
}
406
-
407
- $ mainModName = array_search ($ codePath , $ allComponents );
408
- if (!$ mainModName ) {
409
- $ mainModName = $ this ->getPossibleVendorName ($ codePath )
410
- . '_ '
411
- . basename (str_replace ($ pattern , '' , $ codePath ));
412
- }
413
- $ modulePaths [$ mainModName ][] = $ codePath ;
411
+ $ mainModName = basename (str_replace ($ pattern , '' , $ codePath ));
412
+ $ modulePaths [$ codePath ] = [$ mainModName ];
414
413
415
414
if (MftfApplicationConfig::getConfig ()->verboseEnabled ()) {
416
415
LoggingUtil::getInstance ()->getLogger (ModuleResolver::class)->debug (
@@ -423,7 +422,7 @@ private function globRelevantPaths($testPath, $pattern)
423
422
// Suppress print during unit testing
424
423
if (MftfApplicationConfig::getConfig ()->getPhase () !== MftfApplicationConfig::UNIT_TEST_PHASE
425
424
&& strpos ($ testPath , self ::DEPRECATED_DEV_TESTS ) !== false
426
- && !empty ($ module )
425
+ && !empty ($ modulePaths )
427
426
) {
428
427
$ deprecatedPath = self ::DEPRECATED_DEV_TESTS ;
429
428
$ suggestedPath = self ::DEV_TESTS . DIRECTORY_SEPARATOR . 'Vendor ' ;
@@ -538,26 +537,49 @@ private function getComposerInstalledTestModulePaths($composerFile)
538
537
}
539
538
540
539
/**
541
- * Merge an associated array in 1st argument with another flattened associated array in 2nd argument
542
- * and process duplicates
540
+ * Merge code paths
543
541
*
544
- * @param array $nameKeyedArray
545
- * @param array $pathKeyedArray
542
+ * @param array $oneToOneArray
543
+ * @param array $oneToManyArray
546
544
* @return array
547
545
*/
548
- private function mergeModulePaths ($ nameKeyedArray , $ pathKeyedArray )
546
+ private function mergeModulePaths ($ oneToOneArray , $ oneToManyArray )
549
547
{
550
- $ flippedArray = [];
551
- foreach ($ nameKeyedArray as $ name => $ path ) {
552
- $ flippedArray [$ path [0 ]] = [$ name ];
553
- }
554
- foreach ($ pathKeyedArray as $ path => $ modules ) {
548
+ $ mergedArray = $ oneToOneArray ;
549
+ foreach ($ oneToManyArray as $ path => $ modules ) {
555
550
// Do nothing when array_key_exists
556
- if (!array_key_exists ($ path , $ flippedArray )) {
557
- $ flippedArray [$ path ] = $ modules ;
551
+ if (!array_key_exists ($ path , $ oneToOneArray )) {
552
+ $ mergedArray [$ path ] = $ modules ;
558
553
}
559
554
}
560
- return $ flippedArray ;
555
+ return $ mergedArray ;
556
+ }
557
+
558
+ /**
559
+ * Normalize module name if registered module list is available
560
+ *
561
+ * @param array $codePaths
562
+ *
563
+ * @return array
564
+ */
565
+ private function normalizeModuleNames ($ codePaths )
566
+ {
567
+ $ allComponents = $ this ->getRegisteredModuleList ();
568
+ if (empty ($ allComponents )) {
569
+ return $ codePaths ;
570
+ }
571
+
572
+ $ normalizedCodePaths = [];
573
+ foreach ($ codePaths as $ path => $ moduleNames ) {
574
+ $ mainModName = array_search ($ path , $ allComponents );
575
+ if ($ mainModName ) {
576
+ $ normalizedCodePaths [$ path ] = [$ mainModName ];
577
+ } else {
578
+ $ normalizedCodePaths [$ path ] = $ moduleNames ;
579
+ }
580
+ }
581
+
582
+ return $ normalizedCodePaths ;
561
583
}
562
584
563
585
/**
@@ -800,7 +822,7 @@ private function getRegisteredModuleList()
800
822
array_walk ($ allComponents , function (&$ value ) {
801
823
// Magento stores component paths with unix DIRECTORY_SEPARATOR, need to stay uniform and convert
802
824
$ value = realpath ($ value );
803
- $ value .= ' /Test/Mftf ' ;
825
+ $ value .= DIRECTORY_SEPARATOR . self :: TEST_MFTF_PATTERN ;
804
826
});
805
827
return $ allComponents ;
806
828
} catch (TestFrameworkException $ e ) {
@@ -828,7 +850,7 @@ private function getBackendUrl()
828
850
*/
829
851
private function getPossibleVendorModuleName ($ path )
830
852
{
831
- $ path = str_replace (DIRECTORY_SEPARATOR . ' Test ' . DIRECTORY_SEPARATOR . ' Mftf ' , '' , $ path );
853
+ $ path = str_replace (DIRECTORY_SEPARATOR . self :: TEST_MFTF_PATTERN , '' , $ path );
832
854
return $ this ->getPossibleVendorName ($ path ) . '_ ' . basename ($ path );
833
855
}
834
856
0 commit comments