Skip to content

Commit a6d4f42

Browse files
committed
MQE-844: Support for Extension Tests
- add glob for new patterns
1 parent 82fca1b commit a6d4f42

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,41 +222,59 @@ public function getModulesPath()
222222
private function aggregateTestModulePaths()
223223
{
224224
$allModulePaths = [];
225-
$appCodeTestPaths = [];
226-
$testModuleCodePaths = [];
227225

226+
// TODO update these paths when we switch a composer based pathing
228227
// Define the Module paths from app/code
229228
$appCodePath = dirname(dirname(dirname(PROJECT_ROOT)))
230229
. DIRECTORY_SEPARATOR
231230
. 'app' . DIRECTORY_SEPARATOR
232-
. 'code' . DIRECTORY_SEPARATOR
233-
. 'Magento';
231+
. 'code' . DIRECTORY_SEPARATOR;
234232

235-
// Define the Module paths from defualt TESTS_MODULE_PATH
233+
// Define the Module paths from default TESTS_MODULE_PATH
236234
$modulePath = defined('TESTS_MODULE_PATH') ? TESTS_MODULE_PATH : TESTS_BP;
237235

238-
if (file_exists($appCodePath)) {
239-
$appCodeTestPaths = glob($appCodePath . '*/*/Test/Acceptance');
240-
}
236+
// Define the Module paths from vendor modules
237+
$vendorCodePath = dirname(dirname(dirname(PROJECT_ROOT)))
238+
. DIRECTORY_SEPARATOR
239+
. 'vendor' . DIRECTORY_SEPARATOR;
240+
241+
$codePathsToPattern = [
242+
$appCodePath => '/Test/Acceptance',
243+
$modulePath => '',
244+
$vendorCodePath => '/Test/Acceptance'
245+
];
241246

242-
// Build an associative array of module name to existing module filepaths based on app/code path
243-
foreach ($appCodeTestPaths as $appCodePath) {
244-
$mainModName = basename(str_replace('/Test/Acceptance', '', $appCodePath));
245-
$allModulePaths[$mainModName][] = $appCodePath;
247+
foreach ($codePathsToPattern as $codePath => $pattern) {
248+
$allModulePaths = array_merge_recursive($allModulePaths, $this->globRelevantPaths($codePath, $pattern));
246249
}
247250

248-
// TODO IMPROVE THIS TO ONLY GREP RELEVANT .XML FILES
249-
if (file_exists($modulePath)) {
250-
$testModuleCodePaths = glob($modulePath . '*/*');
251+
return $allModulePaths;
252+
}
253+
254+
/**
255+
* Function which takes a code path and a pattern and determines if there are any matching subdir paths. Matches
256+
* are returned as an associative array keyed by basename (the last dir excluding pattern) to an array containing
257+
* the matching path.
258+
*
259+
* @param string $testPath
260+
* @param string $pattern
261+
* @return array
262+
*/
263+
private function globRelevantPaths($testPath, $pattern)
264+
{
265+
$modulePaths = [];
266+
$relevantPaths = [];
267+
268+
if (file_exists($testPath)) {
269+
$relevantPaths = glob($testPath . '*/*' . $pattern);
251270
}
252271

253-
// Add to associative array of module name to existing module filepaths based on defined TEST MODULE PATH
254-
foreach ($testModuleCodePaths as $modPath) {
255-
$modName = basename($modPath);
256-
$allModulePaths[$modName][] = $modPath;
272+
foreach ($relevantPaths as $codePath) {
273+
$mainModName = basename(trim($codePath, $pattern));
274+
$modulePaths[$mainModName][] = $codePath;
257275
}
258276

259-
return $allModulePaths;
277+
return $modulePaths;
260278
}
261279

262280
/**

0 commit comments

Comments
 (0)