Skip to content

Commit 741115e

Browse files
committed
MQE-567: System env var collision with .env file causes codeception run to fail
- add validate method to ConfigSanitizerUtil - refactor url based sanitization to use single method with params
1 parent 933bb90 commit 741115e

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

src/Magento/FunctionalTestingFramework/Module/MagentoRestDriver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ public function _beforeSuite($settings = [])
108108
if (empty($this->config['url']) || empty($this->config['username']) || empty($this->config['password'])) {
109109
return;
110110
}
111-
$this->config['url'] = ConfigSanitizerUtil::sanitizeUrl($this->config['url']);
111+
112+
$this->config = ConfigSanitizerUtil::sanitizeWebDriverConfig($this->config, ['url']);
112113

113114
$this->haveHttpHeader('Content-Type', 'application/json');
114115
$this->sendPOST(

src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@
1212
class ConfigSanitizerUtil
1313
{
1414
/**
15-
* Sanitizes the given Webdriver Config's url and selenium env params.
15+
* Sanitizes the given Webdriver Config's url and selenium env params, can be selective based on second argument.
1616
* @param array $config
17+
* @param String[] $params
1718
* @return array
1819
*/
19-
public static function sanitizeWebDriverConfig($config)
20+
public static function sanitizeWebDriverConfig($config, $params = ['url', 'selenium'])
2021
{
21-
$config['url'] = self::sanitizeUrl($config['url']);
22-
$config = self::sanitizeSeleniumEnvs($config);
22+
self::validateConfigBasedVars($config);
23+
24+
if (array_key_exists('url', array_flip($params))) {
25+
$config['url'] = self::sanitizeUrl($config['url']);
26+
}
27+
28+
if (array_key_exists('selenium', array_flip($params))) {
29+
$config = self::sanitizeSeleniumEnvs($config);
30+
}
31+
2332
return $config;
2433
}
2534

@@ -45,12 +54,37 @@ private static function sanitizeSeleniumEnvs($config)
4554
return $config;
4655
}
4756

57+
/**
58+
* Method which validates env vars have been properly read into the config. Method implemented as part of
59+
* bug MQE-567
60+
*
61+
* @param array $config
62+
* @return void
63+
*/
64+
private static function validateConfigBasedVars($config)
65+
{
66+
$configStrings = array_filter($config, function ($value) {
67+
return is_string($value);
68+
});
69+
70+
foreach ($configStrings as $configKey => $configValue) {
71+
$var = trim((String)$configValue, '%');
72+
if (array_key_exists($var, $_ENV)) {
73+
trigger_error(
74+
"Issue with setting configuration for test runs. Please make sure '{$var}' is "
75+
. "not duplicated as a system level variable",
76+
E_USER_ERROR
77+
);
78+
}
79+
}
80+
}
81+
4882
/**
4983
* Sanitizes and returns given URL.
5084
* @param string $url
5185
* @return string
5286
*/
53-
public static function sanitizeUrl($url)
87+
private static function sanitizeUrl($url)
5488
{
5589
if ($url === "") {
5690
trigger_error("MAGENTO_BASE_URL must be defined in .env", E_USER_ERROR);

0 commit comments

Comments
 (0)