Skip to content

Commit 5700373

Browse files
committed
MQE-1043: MFTF force flag should ignore the magento base url even when valid
- ModuleResolver now completely ignores trying to get enabledModules if --force is set - Shuffled around exception throwing for faster failure - Fix for MQE-1017 included, exceptions are now more verbose and precise as to when they are thrown.
1 parent aff7f67 commit 5700373

File tree

2 files changed

+47
-25
lines changed

2 files changed

+47
-25
lines changed

src/Magento/FunctionalTestingFramework/Exceptions/TestFrameworkException.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\FunctionalTestingFramework\Exceptions;
88

9+
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
10+
911
/**
1012
* Class TestFrameworkException
1113
*/
@@ -14,9 +16,17 @@ class TestFrameworkException extends \Exception
1416
/**
1517
* TestFrameworkException constructor.
1618
* @param string $message
19+
* @param array $context
20+
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
1721
*/
18-
public function __construct($message)
22+
public function __construct($message, $context = [])
1923
{
24+
list($childClass, $callingClass) = debug_backtrace(false, 2);
25+
LoggingUtil::getInstance()->getLogger($callingClass['class'])->error(
26+
$message,
27+
$context
28+
);
29+
2030
parent::__construct($message);
2131
}
2232
}

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\FunctionalTestingFramework\Util;
88

99
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
10+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1011
use Magento\FunctionalTestingFramework\Util\Logger\LoggingUtil;
1112

1213
/**
@@ -138,10 +139,6 @@ public function getEnabledModules()
138139
}
139140

140141
$token = $this->getAdminToken();
141-
if (!$token || !is_string($token)) {
142-
$this->enabledModules = [];
143-
return $this->enabledModules;
144-
}
145142

146143
$url = ConfigSanitizerUtil::sanitizeUrl(getenv('MAGENTO_BASE_URL')) . $this->moduleUrl;
147144

@@ -157,10 +154,17 @@ public function getEnabledModules()
157154
$response = curl_exec($ch);
158155

159156
if (!$response) {
160-
$this->enabledModules = [];
161-
} else {
162-
$this->enabledModules = json_decode($response);
157+
$message = "Could not retrieve Modules from Magento Instance.";
158+
$context = [
159+
"Admin Module List Url" => $url,
160+
"MAGENTO_ADMIN_USERNAME" => getenv("MAGENTO_ADMIN_USERNAME"),
161+
"MAGENTO_ADMIN_PASSWORD" => getenv("MAGENTO_ADMIN_PASSWORD"),
162+
];
163+
throw new TestFrameworkException($message, $context);
163164
}
165+
166+
$this->enabledModules = json_decode($response);
167+
164168
return $this->enabledModules;
165169
}
166170

@@ -190,25 +194,14 @@ public function getModulesPath()
190194
return $this->enabledModulePaths;
191195
}
192196

193-
$enabledModules = $this->getEnabledModules();
194-
if (empty($enabledModules) && !MftfApplicationConfig::getConfig()->forceGenerateEnabled()) {
195-
$errorMsg = 'Could not retrieve enabled modules from provided MAGENTO_BASE_URL ' .
196-
'please make sure Magento is available at this url';
197-
LoggingUtil::getInstance()->getLogger(ModuleResolver::class)->error(
198-
$errorMsg,
199-
['MAGENTO_BASE_URL' => getenv('MAGENTO_BASE_URL')]
200-
);
201-
trigger_error($errorMsg, E_USER_ERROR);
202-
}
203-
204197
$allModulePaths = $this->aggregateTestModulePaths();
205198

206-
if (empty($enabledModules)) {
199+
if (MftfApplicationConfig::getConfig()->forceGenerateEnabled()) {
207200
$this->enabledModulePaths = $this->applyCustomModuleMethods($allModulePaths);
208201
return $this->enabledModulePaths;
209202
}
210203

211-
$enabledModules = array_merge($enabledModules, $this->getModuleWhitelist());
204+
$enabledModules = array_merge($this->getEnabledModules(), $this->getModuleWhitelist());
212205
$enabledDirectoryPaths = $this->getEnabledDirectoryPaths($enabledModules, $allModulePaths);
213206

214207
$this->enabledModulePaths = $this->applyCustomModuleMethods($enabledDirectoryPaths);
@@ -325,9 +318,15 @@ private function getEnabledDirectoryPaths($enabledModules, $allModulePaths)
325318
{
326319
$enabledDirectoryPaths = [];
327320
foreach ($enabledModules as $magentoModuleName) {
328-
$moduleShortName = explode('_', $magentoModuleName)[1];
321+
// Magento_Backend -> Backend or DevDocs -> DevDocs (if whitelisted has no underscore)
322+
$moduleShortName = explode('_', $magentoModuleName)[1] ?? $magentoModuleName;
329323
if (!isset($this->knownDirectories[$moduleShortName]) && !isset($allModulePaths[$moduleShortName])) {
330324
continue;
325+
} elseif (isset($this->knownDirectories[$moduleShortName]) && !isset($allModulePaths[$moduleShortName])) {
326+
LoggingUtil::getInstance()->getLogger(ModuleResolver::class)->warn(
327+
"Known directory could not match to an existing path.",
328+
['knownDirectory' => $moduleShortName]
329+
);
331330
} else {
332331
$enabledDirectoryPaths[$moduleShortName] = $allModulePaths[$moduleShortName];
333332
}
@@ -342,7 +341,6 @@ private function getEnabledDirectoryPaths($enabledModules, $allModulePaths)
342341
*/
343342
private function printMagentoVersionInfo()
344343
{
345-
346344
if (MftfApplicationConfig::getConfig()->forceGenerateEnabled()) {
347345
return;
348346
}
@@ -377,7 +375,13 @@ protected function getAdminToken()
377375
$login = $_ENV['MAGENTO_ADMIN_USERNAME'] ?? null;
378376
$password = $_ENV['MAGENTO_ADMIN_PASSWORD'] ?? null;
379377
if (!$login || !$password || !isset($_ENV['MAGENTO_BASE_URL'])) {
380-
return false;
378+
$message = "Cannot retrieve API token without credentials and base url, please fill out .env.";
379+
$context = [
380+
"MAGENTO_BASE_URL" => getenv("MAGENTO_BASE_URL"),
381+
"MAGENTO_ADMIN_USERNAME" => getenv("MAGENTO_ADMIN_USERNAME"),
382+
"MAGENTO_ADMIN_PASSWORD" => getenv("MAGENTO_ADMIN_PASSWORD"),
383+
];
384+
throw new TestFrameworkException($message, $context);
381385
}
382386

383387
$url = ConfigSanitizerUtil::sanitizeUrl($_ENV['MAGENTO_BASE_URL']) . $this->adminTokenUrl;
@@ -398,9 +402,17 @@ protected function getAdminToken()
398402
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
399403

400404
$response = curl_exec($ch);
405+
401406
if (!$response) {
402-
return $response;
407+
$message = "Could not retrieve API token from Magento Instance.";
408+
$context = [
409+
"Admin Integration Token Url" => $url,
410+
"MAGENTO_ADMIN_USERNAME" => getenv("MAGENTO_ADMIN_USERNAME"),
411+
"MAGENTO_ADMIN_PASSWORD" => getenv("MAGENTO_ADMIN_PASSWORD"),
412+
];
413+
throw new TestFrameworkException($message, $context);
403414
}
415+
404416
return json_decode($response);
405417
}
406418

0 commit comments

Comments
 (0)