Skip to content

Commit 97fe09b

Browse files
committed
MQE-1650: Update MFTF configuration to read Test entities from new location
1 parent 3a424de commit 97fe09b

File tree

2 files changed

+55
-43
lines changed

2 files changed

+55
-43
lines changed

src/Magento/FunctionalTestingFramework/Util/ComposerModuleResolver.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616
*/
1717
class ComposerModuleResolver
1818
{
19-
/**#@+
20-
* Test module array keys
21-
*/
22-
const KEY_DEPENDS_ON = 'dependsOn';
23-
/**#@-*/
24-
2519
/**
2620
* Code path array from composer json search
2721
*
@@ -68,9 +62,7 @@ public function getComposerInstalledTestModules($rootComposerFile)
6862
foreach ($composerInstaller->getInstalledTestPackages() as $packageName => $packageData) {
6963
$suggestedModuleNames = $packageData[ComposerInstaller::KEY_PACKAGE_SUGGESTED_MAGENTO_MODULES];
7064
$path = $packageData[ComposerInstaller::KEY_PACKAGE_INSTALLEDPATH];
71-
$this->installedTestModules[$path] = [
72-
self::KEY_DEPENDS_ON => $suggestedModuleNames
73-
];
65+
$this->installedTestModules[$path] = $suggestedModuleNames;
7466
}
7567
return $this->installedTestModules;
7668
}
@@ -129,9 +121,7 @@ private function getTestModules($directory)
129121
$file
130122
);
131123
$suggestedMagentoModuleNames = $composerInfo->getSuggestedMagentoModules();
132-
$module[$modulePath] = [
133-
self::KEY_DEPENDS_ON => $suggestedMagentoModuleNames
134-
];
124+
$module[$modulePath] = $suggestedMagentoModuleNames;
135125
$modules = array_merge_recursive($modules, $module);
136126
}
137127
}

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class ModuleResolver
3838
*/
3939
const REGISTRAR_CLASS = "\Magento\Framework\Component\ComponentRegistrar";
4040

41+
/**
42+
* const for Test/Mftf
43+
*/
44+
const TEST_MFTF_PATTERN = 'Test' . DIRECTORY_SEPARATOR . 'Mftf';
45+
4146
/**
4247
* const for vendor
4348
*/
@@ -267,6 +272,8 @@ public function getModulesPath($flat = true)
267272

268273
$allModulePaths = $this->mergeModulePaths($allModulePaths, $composerBsedModulePaths);
269274

275+
$allModulePaths = $this->normalizeModuleNames($allModulePaths);
276+
270277
if (MftfApplicationConfig::getConfig()->forceGenerateEnabled()) {
271278
$allModulePaths = $this->flipAndFlattenArray($allModulePaths);
272279
$this->enabledModulePaths = $this->applyCustomModuleMethods($allModulePaths);
@@ -275,18 +282,18 @@ public function getModulesPath($flat = true)
275282

276283
$enabledModules = array_merge($this->getEnabledModules(), $this->getModuleWhitelist());
277284
//$enabledDirectoryPaths = $this->getEnabledDirectoryPaths($enabledModules, $allModulePaths);
278-
$enabledDirectoryPaths = $this->flipAndFlattenArray($allModulePaths, $enabledModules);
285+
$enabledDirectoryPaths = $this->flipAndFilterArray($allModulePaths, $enabledModules);
279286

280287
$this->enabledModulePaths = $this->applyCustomModuleMethods($enabledDirectoryPaths);
281288
return $this->enabledModulePaths;
282289
}
283290

284291
/**
285-
* @param array $targetArray
292+
* @param array $objectArray
286293
* @param array $filterArray
287294
* @return array
288295
*/
289-
private function flipAndFlattenArray($objectArray, $filterArray = null)
296+
private function flipAndFilterArray($objectArray, $filterArray = null)
290297
{
291298
$flippedArray = [];
292299
foreach ($objectArray as $path => $modules) {
@@ -364,8 +371,8 @@ private function aggregateTestModulePaths()
364371

365372
$codePathsToPattern = [
366373
$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,
369376
$magentoBaseCodePath . self::DEPRECATED_DEV_TESTS => ''
370377
];
371378

@@ -394,23 +401,15 @@ private function globRelevantPaths($testPath, $pattern)
394401
$relevantPaths = $this->globRelevantWrapper($testPath, $pattern);
395402
}
396403

397-
$allComponents = $this->getRegisteredModuleList();
398-
399404
foreach ($relevantPaths as $codePath) {
400405
// Reduce magento/app/code/Magento/AdminGws/<pattern> to magento/app/code/Magento/AdminGws to read symlink
401406
// Symlinks must be resolved otherwise they will not match Magento's filepath to the module
402407
$potentialSymlink = str_replace(DIRECTORY_SEPARATOR . $pattern, "", $codePath);
403408
if (is_link($potentialSymlink)) {
404409
$codePath = realpath($potentialSymlink) . DIRECTORY_SEPARATOR . $pattern;
405410
}
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];
414413

415414
if (MftfApplicationConfig::getConfig()->verboseEnabled()) {
416415
LoggingUtil::getInstance()->getLogger(ModuleResolver::class)->debug(
@@ -423,7 +422,7 @@ private function globRelevantPaths($testPath, $pattern)
423422
// Suppress print during unit testing
424423
if (MftfApplicationConfig::getConfig()->getPhase() !== MftfApplicationConfig::UNIT_TEST_PHASE
425424
&& strpos($testPath, self::DEPRECATED_DEV_TESTS) !== false
426-
&& !empty($module)
425+
&& !empty($modulePaths)
427426
) {
428427
$deprecatedPath = self::DEPRECATED_DEV_TESTS;
429428
$suggestedPath = self::DEV_TESTS . DIRECTORY_SEPARATOR . 'Vendor';
@@ -538,26 +537,49 @@ private function getComposerInstalledTestModulePaths($composerFile)
538537
}
539538

540539
/**
541-
* Merge an associated array in 1st argument with another flattened associated array in 2nd argument
542-
* and process duplicates
540+
* Merge code paths
543541
*
544-
* @param array $nameKeyedArray
545-
* @param array $pathKeyedArray
542+
* @param array $oneToOneArray
543+
* @param array $oneToManyArray
546544
* @return array
547545
*/
548-
private function mergeModulePaths($nameKeyedArray, $pathKeyedArray)
546+
private function mergeModulePaths($oneToOneArray, $oneToManyArray)
549547
{
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) {
555550
// 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;
558553
}
559554
}
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;
561583
}
562584

563585
/**
@@ -800,7 +822,7 @@ private function getRegisteredModuleList()
800822
array_walk($allComponents, function (&$value) {
801823
// Magento stores component paths with unix DIRECTORY_SEPARATOR, need to stay uniform and convert
802824
$value = realpath($value);
803-
$value .= '/Test/Mftf';
825+
$value .= DIRECTORY_SEPARATOR . self::TEST_MFTF_PATTERN;
804826
});
805827
return $allComponents;
806828
} catch (TestFrameworkException $e) {
@@ -828,7 +850,7 @@ private function getBackendUrl()
828850
*/
829851
private function getPossibleVendorModuleName($path)
830852
{
831-
$path = str_replace(DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR . 'Mftf', '', $path);
853+
$path = str_replace(DIRECTORY_SEPARATOR . self::TEST_MFTF_PATTERN, '', $path);
832854
return $this->getPossibleVendorName($path) . '_' . basename($path);
833855
}
834856

0 commit comments

Comments
 (0)