From 23e95a94ac2cdaf98441563e2a53a2405ac653ab Mon Sep 17 00:00:00 2001 From: Ji Lu Date: Thu, 12 Mar 2020 09:22:44 -0500 Subject: [PATCH] MQE-2026: ModuleResolver handle test module that depends on more than one Magento modules --- .../Util/ModuleResolverTest.php | 147 ++++++++++++++++-- .../Util/ModuleResolver.php | 22 +-- 2 files changed, 149 insertions(+), 20 deletions(-) diff --git a/dev/tests/unit/Magento/FunctionalTestFramework/Util/ModuleResolverTest.php b/dev/tests/unit/Magento/FunctionalTestFramework/Util/ModuleResolverTest.php index ad0b1769d..5244e6995 100644 --- a/dev/tests/unit/Magento/FunctionalTestFramework/Util/ModuleResolverTest.php +++ b/dev/tests/unit/Magento/FunctionalTestFramework/Util/ModuleResolverTest.php @@ -57,7 +57,6 @@ public function testGetModulePathsAlreadySet() */ public function testGetModulePathsAggregate() { - $this->mockForceGenerate(false); $this->setMockResolverClass( false, @@ -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 @@ -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() * @@ -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' ], @@ -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() ); diff --git a/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php b/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php index d7f06306a..b24e77d9c 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php +++ b/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php @@ -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)); @@ -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];