Skip to content

Commit ca1cbdc

Browse files
authored
Merge pull request #635 from magento/MQE-2026
MQE-2026: ModuleResolver handle test module that depends on more than…
2 parents a4d08e0 + cd7fc0e commit ca1cbdc

File tree

2 files changed

+149
-20
lines changed

2 files changed

+149
-20
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Util/ModuleResolverTest.php

Lines changed: 137 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public function testGetModulePathsAlreadySet()
5757
*/
5858
public function testGetModulePathsAggregate()
5959
{
60-
6160
$this->mockForceGenerate(false);
6261
$this->setMockResolverClass(
6362
false,
@@ -89,6 +88,50 @@ public function testGetModulePathsAggregate()
8988
);
9089
}
9190

91+
/**
92+
* Validate aggregateTestModulePaths() when module path part of DEV_TESTS
93+
*
94+
* @throws \Exception
95+
*/
96+
public function testAggregateTestModulePathsDevTests()
97+
{
98+
$origin = TESTS_MODULE_PATH;
99+
$modulePath = ModuleResolver::DEV_TESTS . DIRECTORY_SEPARATOR . "Magento";
100+
putenv("TESTS_MODULE_PATH=$modulePath");
101+
102+
$this->mockForceGenerate(false);
103+
$mockResolver = $this->setMockResolverClass(
104+
true,
105+
[],
106+
null,
107+
null,
108+
[],
109+
[],
110+
[],
111+
null,
112+
null,
113+
[],
114+
[],
115+
null,
116+
function ($arg) {
117+
return $arg;
118+
},
119+
function ($arg) {
120+
return $arg;
121+
}
122+
);
123+
$resolver = ModuleResolver::getInstance();
124+
$this->setMockResolverProperties($resolver, null, null);
125+
$this->assertEquals(
126+
[],
127+
$resolver->getModulesPath()
128+
);
129+
130+
$mockResolver->verifyNeverInvoked('globRelevantPaths', [$modulePath, '']);
131+
132+
putenv("TESTS_MODULE_PATH=$origin");
133+
}
134+
92135
/**
93136
* Validate correct path locations are fed into globRelevantPaths
94137
* @throws \Exception
@@ -409,6 +452,81 @@ public function testMergeFlipAndFilterModulePathsNoForceGenerate()
409452
);
410453
}
411454

455+
/**
456+
* Validate mergeModulePaths() and flipAndSortModulePathsArray()
457+
*
458+
* @throws \Exception
459+
*/
460+
public function testMergeFlipNoSortModulePathsNoForceGenerate()
461+
{
462+
$this->mockForceGenerate(false);
463+
$this->setMockResolverClass(
464+
false,
465+
null,
466+
null,
467+
null,
468+
null,
469+
null,
470+
null,
471+
null,
472+
null,
473+
[
474+
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR
475+
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleA' =>
476+
[
477+
'Magento_ModuleA'
478+
],
479+
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR
480+
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleBC' =>
481+
[
482+
'Magento_ModuleB',
483+
'Magento_ModuleC',
484+
],
485+
],
486+
[
487+
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR
488+
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleCD' =>
489+
[
490+
'Magento_ModuleC',
491+
'Magento_ModuleD'
492+
],
493+
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR
494+
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleE' =>
495+
[
496+
'Magento_ModuleE'
497+
],
498+
],
499+
[
500+
'some' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'example' => ['Magento_Example'],
501+
'other' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'sample' => ['Magento_Sample'],
502+
]
503+
);
504+
505+
$resolver = ModuleResolver::getInstance();
506+
$this->setMockResolverProperties(
507+
$resolver,
508+
null,
509+
[
510+
0 => 'Magento_ModuleB',
511+
1 => 'Magento_ModuleC',
512+
2 => 'Magento_ModuleE',
513+
3 => 'Magento_Example',
514+
4 => 'Magento_Otherexample'
515+
]
516+
);
517+
518+
$this->assertEquals(
519+
[
520+
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
521+
. 'ModuleE',
522+
'some' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'example',
523+
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
524+
. 'ModuleBC'
525+
],
526+
$resolver->getModulesPath()
527+
);
528+
}
529+
412530
/**
413531
* Validate mergeModulePaths() and flipAndSortModulePathsArray()
414532
*
@@ -428,23 +546,27 @@ public function testMergeFlipAndSortModulePathsForceGenerate()
428546
null,
429547
null,
430548
[
431-
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'pathA' =>
549+
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR
550+
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleA' =>
432551
[
433552
'Magento_ModuleA'
434553
],
435-
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'pathB' =>
554+
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR
555+
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleBC' =>
436556
[
437557
'Magento_ModuleB',
438558
'Magento_ModuleC',
439559
],
440560
],
441561
[
442-
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'pathA' =>
562+
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR
563+
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleCD' =>
443564
[
444565
'Magento_ModuleC',
445566
'Magento_ModuleD'
446567
],
447-
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'pathB' =>
568+
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR
569+
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleD' =>
448570
[
449571
'Magento_ModuleD'
450572
],
@@ -467,14 +589,19 @@ public function testMergeFlipAndSortModulePathsForceGenerate()
467589
4 => 'Magento_Otherexample'
468590
]
469591
);
592+
470593
$this->assertEquals(
471594
[
472595
'some' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'example',
473-
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'pathA',
474-
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'pathB',
475-
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'pathA',
476-
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'pathB',
477-
'other' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'sample'
596+
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
597+
. 'ModuleA',
598+
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
599+
. 'ModuleD',
600+
'other' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'sample',
601+
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
602+
. 'ModuleBC',
603+
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
604+
. 'ModuleCD'
478605
],
479606
$resolver->getModulesPath()
480607
);

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,14 +320,16 @@ private function aggregateTestModulePaths()
320320
$modulePath = defined('TESTS_MODULE_PATH') ? TESTS_MODULE_PATH : TESTS_BP;
321321
$modulePath = FilePathFormatter::format($modulePath, false);
322322

323+
// If $modulePath is DEV_TESTS path, we don't need to search by pattern
324+
if (strpos($modulePath, self::DEV_TESTS) === false) {
325+
$codePathsToPattern[$modulePath] = '';
326+
}
327+
323328
$vendorCodePath = DIRECTORY_SEPARATOR . self::VENDOR;
324-
$appCodePath = DIRECTORY_SEPARATOR . self::APP_CODE;
329+
$codePathsToPattern[$magentoBaseCodePath . $vendorCodePath] = self::TEST_MFTF_PATTERN;
325330

326-
$codePathsToPattern = [
327-
$modulePath => '',
328-
$magentoBaseCodePath . $vendorCodePath => self::TEST_MFTF_PATTERN,
329-
$magentoBaseCodePath . $appCodePath => self::TEST_MFTF_PATTERN
330-
];
331+
$appCodePath = DIRECTORY_SEPARATOR . self::APP_CODE;
332+
$codePathsToPattern[$magentoBaseCodePath . $appCodePath] = self::TEST_MFTF_PATTERN;
331333

332334
foreach ($codePathsToPattern as $codePath => $pattern) {
333335
$allModulePaths = array_merge_recursive($allModulePaths, $this->globRelevantPaths($codePath, $pattern));
@@ -538,10 +540,10 @@ private function flipAndSortModulePathsArray($objectArray, $sort, $inFlippedArra
538540
foreach ($objectArray as $path => $modules) {
539541
if (is_array($modules) && count($modules) > 1) {
540542
// The "one path => many module names" case is designed to be strictly used when it's
541-
// impossible to write tests in dedicated modules. Due to performance consideration and there
542-
// is no real usage of this currently, we will use the first module name for the path.
543-
// TODO: consider saving all module names if this information is needed in the future.
544-
$module = $modules[0];
543+
// impossible to write tests in dedicated modules.
544+
// For now we will set module name based on path.
545+
// TODO: Consider saving all module names if this information is needed in the future.
546+
$module = $this->findVendorAndModuleNameFromPath($path);
545547
} elseif (is_array($modules)) {
546548
if (strpos($modules[0], '_') === false) {
547549
$module = $this->findVendorNameFromPath($path) . '_' . $modules[0];

0 commit comments

Comments
 (0)