Skip to content

MQE-2026: ModuleResolver handle test module that depends on more than… #635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function testGetModulePathsAlreadySet()
*/
public function testGetModulePathsAggregate()
{

$this->mockForceGenerate(false);
$this->setMockResolverClass(
false,
Expand Down Expand Up @@ -89,6 +88,50 @@ public function testGetModulePathsAggregate()
);
}

/**
* Validate aggregateTestModulePaths() when module path part of DEV_TESTS
*
* @throws \Exception
*/
public function testAggregateTestModulePathsDevTests()
{
$origin = TESTS_MODULE_PATH;
$modulePath = ModuleResolver::DEV_TESTS . DIRECTORY_SEPARATOR . "Magento";
putenv("TESTS_MODULE_PATH=$modulePath");

$this->mockForceGenerate(false);
$mockResolver = $this->setMockResolverClass(
true,
[],
null,
null,
[],
[],
[],
null,
null,
[],
[],
null,
function ($arg) {
return $arg;
},
function ($arg) {
return $arg;
}
);
$resolver = ModuleResolver::getInstance();
$this->setMockResolverProperties($resolver, null, null);
$this->assertEquals(
[],
$resolver->getModulesPath()
);

$mockResolver->verifyNeverInvoked('globRelevantPaths', [$modulePath, '']);

putenv("TESTS_MODULE_PATH=$origin");
}

/**
* Validate correct path locations are fed into globRelevantPaths
* @throws \Exception
Expand Down Expand Up @@ -409,6 +452,81 @@ public function testMergeFlipAndFilterModulePathsNoForceGenerate()
);
}

/**
* Validate mergeModulePaths() and flipAndSortModulePathsArray()
*
* @throws \Exception
*/
public function testMergeFlipNoSortModulePathsNoForceGenerate()
{
$this->mockForceGenerate(false);
$this->setMockResolverClass(
false,
null,
null,
null,
null,
null,
null,
null,
null,
[
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleA' =>
[
'Magento_ModuleA'
],
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleBC' =>
[
'Magento_ModuleB',
'Magento_ModuleC',
],
],
[
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleCD' =>
[
'Magento_ModuleC',
'Magento_ModuleD'
],
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleE' =>
[
'Magento_ModuleE'
],
],
[
'some' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'example' => ['Magento_Example'],
'other' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'sample' => ['Magento_Sample'],
]
);

$resolver = ModuleResolver::getInstance();
$this->setMockResolverProperties(
$resolver,
null,
[
0 => 'Magento_ModuleB',
1 => 'Magento_ModuleC',
2 => 'Magento_ModuleE',
3 => 'Magento_Example',
4 => 'Magento_Otherexample'
]
);

$this->assertEquals(
[
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
. 'ModuleE',
'some' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'example',
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
. 'ModuleBC'
],
$resolver->getModulesPath()
);
}

/**
* Validate mergeModulePaths() and flipAndSortModulePathsArray()
*
Expand All @@ -428,23 +546,27 @@ public function testMergeFlipAndSortModulePathsForceGenerate()
null,
null,
[
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'pathA' =>
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleA' =>
[
'Magento_ModuleA'
],
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'pathB' =>
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleBC' =>
[
'Magento_ModuleB',
'Magento_ModuleC',
],
],
[
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'pathA' =>
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleCD' =>
[
'Magento_ModuleC',
'Magento_ModuleD'
],
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'pathB' =>
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR
. 'Magento' . DIRECTORY_SEPARATOR . 'ModuleD' =>
[
'Magento_ModuleD'
],
Expand All @@ -467,14 +589,19 @@ public function testMergeFlipAndSortModulePathsForceGenerate()
4 => 'Magento_Otherexample'
]
);

$this->assertEquals(
[
'some' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'example',
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'pathA',
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'pathB',
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'pathA',
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'pathB',
'other' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'sample'
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
. 'ModuleA',
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
. 'ModuleD',
'other' . DIRECTORY_SEPARATOR . 'path' . DIRECTORY_SEPARATOR . 'sample',
'composer' . DIRECTORY_SEPARATOR . 'json' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
. 'ModuleBC',
'composer' . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'Magento' . DIRECTORY_SEPARATOR
. 'ModuleCD'
],
$resolver->getModulesPath()
);
Expand Down
22 changes: 12 additions & 10 deletions src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,16 @@ private function aggregateTestModulePaths()
$modulePath = defined('TESTS_MODULE_PATH') ? TESTS_MODULE_PATH : TESTS_BP;
$modulePath = FilePathFormatter::format($modulePath, false);

// If $modulePath is DEV_TESTS path, we don't need to search by pattern
if (strpos($modulePath, self::DEV_TESTS) === false) {
$codePathsToPattern[$modulePath] = '';
}

$vendorCodePath = DIRECTORY_SEPARATOR . self::VENDOR;
$appCodePath = DIRECTORY_SEPARATOR . self::APP_CODE;
$codePathsToPattern[$magentoBaseCodePath . $vendorCodePath] = self::TEST_MFTF_PATTERN;

$codePathsToPattern = [
$modulePath => '',
$magentoBaseCodePath . $vendorCodePath => self::TEST_MFTF_PATTERN,
$magentoBaseCodePath . $appCodePath => self::TEST_MFTF_PATTERN
];
$appCodePath = DIRECTORY_SEPARATOR . self::APP_CODE;
$codePathsToPattern[$magentoBaseCodePath . $appCodePath] = self::TEST_MFTF_PATTERN;

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