Skip to content

Commit c9cda12

Browse files
committed
MQE-526: Do not depend on xml merging by filename-order
- change merging to use Module path order - add print statements around included/excluded modules
1 parent e2d5059 commit c9cda12

File tree

3 files changed

+67
-19
lines changed

3 files changed

+67
-19
lines changed

dev/tests/_bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
'includePaths' => [PROJECT_ROOT . '/src']
1616
]);
1717

18+
// force php to generate
19+
$GLOBALS['FORCE_PHP_GENERATE'] = true;
20+
1821
// Load needed framework env params
1922
$TEST_ENVS = [
2023
'MAGENTO_BASE_URL' => 'http://baseurl:8080',

src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static function validateConfigBasedVars($config)
8484
* @param string $url
8585
* @return string
8686
*/
87-
private static function sanitizeUrl($url)
87+
public static function sanitizeUrl($url)
8888
{
8989
if ($url === "") {
9090
trigger_error("MAGENTO_BASE_URL must be defined in .env", E_USER_ERROR);

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ class ModuleResolver
5858
*/
5959
protected $moduleUrl = "rest/V1/modules";
6060

61+
/**
62+
* Url for magento version information.
63+
*
64+
* @var string
65+
*/
66+
protected $versionUrl = "magento_version ";
67+
6168
/**
6269
* List of known directory that does not map to a Magento module.
6370
*
@@ -123,13 +130,15 @@ public function getEnabledModules()
123130
return $this->enabledModules;
124131
}
125132

133+
$this->printMagentoVersionInfo();
134+
126135
$token = $this->getAdminToken();
127136
if (!$token || !is_string($token)) {
128137
$this->enabledModules = [];
129138
return $this->enabledModules;
130139
}
131140

132-
$url = $_ENV['MAGENTO_BASE_URL'] . $this->moduleUrl;
141+
$url = ConfigSanitizerUtil::sanitizeUrl($_ENV['MAGENTO_BASE_URL']) . $this->moduleUrl;
133142

134143
$headers = [
135144
'Authorization: Bearer ' . $token,
@@ -175,31 +184,60 @@ public function getModulesPath()
175184
}
176185

177186
$enabledModules = $this->getEnabledModules();
187+
$forceGeneration = $GLOBALS['FORCE_PHP_GENERATE'] ?? false;
188+
189+
if (empty($enabledModules) && !$forceGeneration) {
190+
trigger_error(
191+
"Could not retrieve enabled modules from provided 'MAGENTO_BASE_URL'," .
192+
"please make sure Magento is available at this url",
193+
E_USER_ERROR
194+
);
195+
}
196+
178197
$modulePath = defined('TESTS_MODULE_PATH') ? TESTS_MODULE_PATH : TESTS_BP;
179-
$allModulePaths = glob($modulePath . '*/*');
198+
199+
// Build an associative array of module name to existing module filepaths based on defined TEST MODULE PATH
200+
$allModulePaths = [];
201+
foreach (glob($modulePath . '*/*') as $modPath) {
202+
$modName = basename($modPath);
203+
$allModulePaths[$modName] = $modPath;
204+
}
205+
180206
if (empty($enabledModules)) {
181207
$this->enabledModulePaths = $this->applyCustomModuleMethods($allModulePaths);
182208
return $this->enabledModulePaths;
183209
}
184210

185211
$enabledModules = array_merge($enabledModules, $this->getModuleWhitelist());
186-
$enabledDirectories = [];
187-
foreach ($enabledModules as $module) {
188-
$directoryName = explode('_', $module)[1];
189-
$enabledDirectories[$directoryName] = $directoryName;
190-
}
191-
192-
foreach ($allModulePaths as $index => $modulePath) {
193-
$moduleShortName = basename($modulePath);
194-
if (!isset($enabledDirectories[$moduleShortName]) && !isset($this->knownDirectories[$moduleShortName])) {
195-
unset($allModulePaths[$index]);
212+
$enabledDirectoryPaths = [];
213+
foreach ($enabledModules as $magentoModuleName) {
214+
$moduleShortName = explode('_', $magentoModuleName)[1];
215+
if (!isset($this->knownDirectories[$moduleShortName]) && !isset($allModulePaths[$moduleShortName])) {
216+
continue;
217+
} else {
218+
$enabledDirectoryPaths[$moduleShortName] = $allModulePaths[$moduleShortName];
196219
}
197220
}
198221

199-
$this->enabledModulePaths = $this->applyCustomModuleMethods($allModulePaths);
222+
$this->enabledModulePaths = $this->applyCustomModuleMethods($enabledDirectoryPaths);
200223
return $this->enabledModulePaths;
201224
}
202225

226+
/**
227+
* Executes a REST call to the supplied Magento Base Url for version information to display during generation
228+
*
229+
* @return void
230+
*/
231+
private function printMagentoVersionInfo()
232+
{
233+
$url = ConfigSanitizerUtil::sanitizeUrl($_ENV['MAGENTO_BASE_URL']) . $this->versionUrl;
234+
$ch = curl_init($url);
235+
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
236+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
237+
$response = curl_exec($ch);
238+
print "Version Information: {$response}\n";
239+
}
240+
203241
/**
204242
* Get the API token for admin.
205243
*
@@ -213,7 +251,7 @@ protected function getAdminToken()
213251
return false;
214252
}
215253

216-
$url = $_ENV['MAGENTO_BASE_URL'] . $this->adminTokenUrl;
254+
$url = ConfigSanitizerUtil::sanitizeUrl($_ENV['MAGENTO_BASE_URL']) . $this->adminTokenUrl;
217255
$data = [
218256
'username' => $login,
219257
'password' => $password
@@ -255,7 +293,13 @@ public function sortFilesByModuleSequence(array $files)
255293
protected function applyCustomModuleMethods($modulesPath)
256294
{
257295
$modulePathsResult = $this->removeBlacklistModules($modulesPath);
258-
return array_merge($modulePathsResult, $this->getCustomModulePaths());
296+
$customModulePaths = $this->getCustomModulePaths();
297+
298+
array_map(function ($value) {
299+
print "Including module path: {$value}\n";
300+
}, $customModulePaths);
301+
302+
return array_merge($modulePathsResult, $customModulePaths);
259303
}
260304

261305
/**
@@ -267,9 +311,10 @@ protected function applyCustomModuleMethods($modulesPath)
267311
private function removeBlacklistModules($modulePaths)
268312
{
269313
$modulePathsResult = $modulePaths;
270-
foreach ($modulePathsResult as $index => $modulePath) {
271-
if (in_array(basename($modulePath), $this->getModuleBlacklist())) {
272-
unset($modulePathsResult[$index]);
314+
foreach ($modulePathsResult as $moduleName => $modulePath) {
315+
if (in_array($moduleName, $this->getModuleBlacklist())) {
316+
unset($modulePathsResult[$moduleName]);
317+
print "Excluding module: {$moduleName}\n";
273318
}
274319
}
275320

0 commit comments

Comments
 (0)