-
Notifications
You must be signed in to change notification settings - Fork 132
MQE-1124: [Github Issue] Allow running tests for modules installed in… #228
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
Changes from 5 commits
1983538
5ac6b56
985c9a7
a94b89f
4cc218c
41e332d
f63cd84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,16 @@ class ModuleResolver | |
*/ | ||
const CUSTOM_MODULE_PATHS = 'CUSTOM_MODULE_PATHS'; | ||
|
||
/** | ||
* List of path types present in Magento Component Registrar | ||
*/ | ||
const PATHS = ['module', 'library', 'theme', 'language', 'setup']; | ||
|
||
/** | ||
* Magento Registrar Class | ||
*/ | ||
const REGISTRAR_CLASS = "\Magento\Framework\Component\Registrar"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class should be |
||
|
||
/** | ||
* Enabled modules. | ||
* | ||
|
@@ -218,25 +228,20 @@ private function aggregateTestModulePaths() | |
{ | ||
$allModulePaths = []; | ||
|
||
// Define the Module paths from app/code | ||
$appCodePath = MAGENTO_BP | ||
. DIRECTORY_SEPARATOR | ||
. 'app' . DIRECTORY_SEPARATOR | ||
. 'code' . DIRECTORY_SEPARATOR; | ||
// Define the Module paths from magento bp | ||
$magentoBaseCodePath = MAGENTO_BP; | ||
|
||
// Define the Module paths from default TESTS_MODULE_PATH | ||
$modulePath = defined('TESTS_MODULE_PATH') ? TESTS_MODULE_PATH : TESTS_BP; | ||
$modulePath = rtrim($modulePath, DIRECTORY_SEPARATOR); | ||
|
||
// Define the Module paths from vendor modules | ||
$vendorCodePath = PROJECT_ROOT | ||
. DIRECTORY_SEPARATOR | ||
. 'vendor' . DIRECTORY_SEPARATOR; | ||
// Define the Module paths from project root | ||
$projectRootCodePath = PROJECT_ROOT; | ||
|
||
$codePathsToPattern = [ | ||
$modulePath => '', | ||
$appCodePath => DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR . 'Mftf', | ||
$vendorCodePath => DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR . 'Mftf' | ||
$magentoBaseCodePath => 'Test' . DIRECTORY_SEPARATOR . 'Mftf', | ||
$projectRootCodePath => 'Test' . DIRECTORY_SEPARATOR . 'Mftf' | ||
]; | ||
|
||
foreach ($codePathsToPattern as $codePath => $pattern) { | ||
|
@@ -265,7 +270,8 @@ private function globRelevantPaths($testPath, $pattern) | |
} | ||
|
||
foreach ($relevantPaths as $codePath) { | ||
$mainModName = basename(str_replace($pattern, '', $codePath)); | ||
$allComponents = $this->getRegisteredModuleList(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to do two things here:
|
||
$mainModName = array_search($codePath, $allComponents) ?: basename(str_replace($pattern, '', $codePath)); | ||
$modulePaths[$mainModName][] = $codePath; | ||
|
||
if (MftfApplicationConfig::getConfig()->verboseEnabled()) { | ||
|
@@ -288,7 +294,15 @@ private function globRelevantPaths($testPath, $pattern) | |
*/ | ||
private static function globRelevantWrapper($testPath, $pattern) | ||
{ | ||
return glob($testPath . '*' . DIRECTORY_SEPARATOR . '*' . $pattern); | ||
if ($pattern == "") { | ||
return glob($testPath . '*' . DIRECTORY_SEPARATOR . '*' . $pattern); | ||
} | ||
$subDirectory = "*" . DIRECTORY_SEPARATOR; | ||
$directories = glob($testPath . $subDirectory . $pattern, GLOB_ONLYDIR); | ||
foreach (glob($testPath . $subDirectory, GLOB_ONLYDIR) as $dir) { | ||
$directories = array_merge_recursive($directories, self::globRelevantWrapper($dir, $pattern)); | ||
} | ||
return $directories; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These directory changes seem to pick up modules under vendor just fine, but consider the following: This is going to fail to map to the module returned by our ping to Magento, |
||
} | ||
|
||
/** | ||
|
@@ -504,4 +518,33 @@ private function getModuleBlacklist() | |
{ | ||
return $this->moduleBlacklist; | ||
} | ||
|
||
/** | ||
* Calls Magento method for determining registered modules. | ||
* | ||
* @return string[] | ||
*/ | ||
private function getRegisteredModuleList() | ||
{ | ||
if (array_key_exists('MAGENTO_BP', $_ENV)) { | ||
require_once(MAGENTO_BP . "/app/autoload.php"); | ||
} | ||
|
||
try { | ||
$allComponents = []; | ||
if (!class_exists(self::REGISTRAR_CLASS)) { | ||
throw new TestFrameworkException("Magento Installation not found when loading registered modules.\n"); | ||
} | ||
$components = new \Magento\Framework\Component\ComponentRegistrar(); | ||
foreach (self::PATHS as $componentType) { | ||
$allComponents = array_merge($allComponents, $components->getPaths($componentType)); | ||
} | ||
return $allComponents; | ||
} catch (TestFrameworkException $e) { | ||
LoggingUtil::getInstance()->getLogger(ModuleResolver::class)->warning( | ||
"$e" | ||
); | ||
} | ||
return []; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to remove
setup
from PATHS.