Skip to content

Commit 1983538

Browse files
committed
MQE-1124: [Github Issue] Allow running tests for modules installed in Magento instance via vendor directory. #162
- Adjusted Module Resolver to look Recursively from Project Root, Magento BP and dev/tests - Updated Module Resolver Unit Tests to reflect changes
1 parent 66b6ecd commit 1983538

File tree

2 files changed

+21
-29
lines changed

2 files changed

+21
-29
lines changed

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

+5-16
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ public function testGetModulePathsAggregate()
6262
$this->setMockResolverProperties($resolver, null, [0 => "Magento_example"]);
6363
$this->assertEquals(
6464
[
65-
"example" . DIRECTORY_SEPARATOR . "paths",
66-
"example" . DIRECTORY_SEPARATOR . "paths",
6765
"example" . DIRECTORY_SEPARATOR . "paths"
6866
],
6967
$resolver->getModulesPath()
@@ -88,35 +86,28 @@ public function testGetModulePathsLocations()
8886
$this->setMockResolverProperties($resolver, null, null);
8987
$this->assertEquals(
9088
[
91-
"example" . DIRECTORY_SEPARATOR . "paths",
92-
"example" . DIRECTORY_SEPARATOR . "paths",
9389
"example" . DIRECTORY_SEPARATOR . "paths"
9490
],
9591
$resolver->getModulesPath()
9692
);
9793

9894
// Define the Module paths from app/code
99-
$appCodePath = MAGENTO_BP
100-
. DIRECTORY_SEPARATOR
101-
. 'app' . DIRECTORY_SEPARATOR
102-
. 'code' . DIRECTORY_SEPARATOR;
95+
$magentoBaseCodePath = MAGENTO_BP;
10396

10497
// Define the Module paths from default TESTS_MODULE_PATH
10598
$modulePath = defined('TESTS_MODULE_PATH') ? TESTS_MODULE_PATH : TESTS_BP;
10699

107100
// Define the Module paths from vendor modules
108-
$vendorCodePath = PROJECT_ROOT
109-
. DIRECTORY_SEPARATOR
110-
. 'vendor' . DIRECTORY_SEPARATOR;
101+
$projectRootCodePath = PROJECT_ROOT;
111102

112103
$mockResolver->verifyInvoked('globRelevantPaths', [$modulePath, '']);
113104
$mockResolver->verifyInvoked(
114105
'globRelevantPaths',
115-
[$appCodePath, DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR .'Mftf']
106+
[$magentoBaseCodePath, 'Test' . DIRECTORY_SEPARATOR .'Mftf']
116107
);
117108
$mockResolver->verifyInvoked(
118109
'globRelevantPaths',
119-
[$vendorCodePath, DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR .'Mftf']
110+
[$projectRootCodePath, 'Test' . DIRECTORY_SEPARATOR .'Mftf']
120111
);
121112
}
122113

@@ -151,8 +142,6 @@ public function testGetModulePathsBlacklist()
151142
function ($arg1, $arg2) {
152143
if ($arg2 === "") {
153144
$mockValue = ["somePath" => "somePath"];
154-
} elseif (strpos($arg1, "app")) {
155-
$mockValue = ["otherPath" => "otherPath"];
156145
} else {
157146
$mockValue = ["lastPath" => "lastPath"];
158147
}
@@ -161,7 +150,7 @@ function ($arg1, $arg2) {
161150
);
162151
$resolver = ModuleResolver::getInstance();
163152
$this->setMockResolverProperties($resolver, null, null, ["somePath"]);
164-
$this->assertEquals(["otherPath", "lastPath"], $resolver->getModulesPath());
153+
$this->assertEquals(["lastPath"], $resolver->getModulesPath());
165154
TestLoggingUtil::getInstance()->validateMockLogStatement(
166155
'info',
167156
'excluding module',

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

+16-13
Original file line numberDiff line numberDiff line change
@@ -218,29 +218,24 @@ private function aggregateTestModulePaths()
218218
{
219219
$allModulePaths = [];
220220

221-
// Define the Module paths from app/code
222-
$appCodePath = MAGENTO_BP
223-
. DIRECTORY_SEPARATOR
224-
. 'app' . DIRECTORY_SEPARATOR
225-
. 'code' . DIRECTORY_SEPARATOR;
221+
// Define the Module paths from magento bp
222+
$magentoBaseCodePath = MAGENTO_BP;
226223

227224
// Define the Module paths from default TESTS_MODULE_PATH
228225
$modulePath = defined('TESTS_MODULE_PATH') ? TESTS_MODULE_PATH : TESTS_BP;
229226
$modulePath = rtrim($modulePath, DIRECTORY_SEPARATOR);
230227

231-
// Define the Module paths from vendor modules
232-
$vendorCodePath = PROJECT_ROOT
233-
. DIRECTORY_SEPARATOR
234-
. 'vendor' . DIRECTORY_SEPARATOR;
228+
// Define the Module paths from project root
229+
$projectRootCodePath = PROJECT_ROOT;
235230

236231
$codePathsToPattern = [
237232
$modulePath => '',
238-
$appCodePath => DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR . 'Mftf',
239-
$vendorCodePath => DIRECTORY_SEPARATOR . 'Test' . DIRECTORY_SEPARATOR . 'Mftf'
233+
$magentoBaseCodePath => 'Test' . DIRECTORY_SEPARATOR . 'Mftf',
234+
$projectRootCodePath => 'Test' . DIRECTORY_SEPARATOR . 'Mftf'
240235
];
241236

242237
foreach ($codePathsToPattern as $codePath => $pattern) {
243-
$allModulePaths = array_merge_recursive($allModulePaths, $this->globRelevantPaths($codePath, $pattern));
238+
$allModulePaths = array_merge($allModulePaths, $this->globRelevantPaths($codePath, $pattern));
244239
}
245240

246241
return $allModulePaths;
@@ -288,7 +283,15 @@ private function globRelevantPaths($testPath, $pattern)
288283
*/
289284
private static function globRelevantWrapper($testPath, $pattern)
290285
{
291-
return glob($testPath . '*' . DIRECTORY_SEPARATOR . '*' . $pattern);
286+
if ($pattern == "") {
287+
return glob($testPath . '*' . DIRECTORY_SEPARATOR . '*' . $pattern);
288+
}
289+
$subDirectory = "*" . DIRECTORY_SEPARATOR;
290+
$directories = glob($testPath . $subDirectory . $pattern, GLOB_ONLYDIR);
291+
foreach (glob($testPath . $subDirectory, GLOB_ONLYDIR) as $dir) {
292+
$directories = array_merge($directories, self::globRelevantWrapper($dir, $pattern));
293+
}
294+
return $directories;
292295
}
293296

294297
/**

0 commit comments

Comments
 (0)