Skip to content

Commit 0a7e06a

Browse files
authored
MQE-841: robo generate:tests --force should not require MAGENTO_BASE_URL
- using --force no longers required MAGENTO_BASE_URL to be defined - assertion action warning now only happens at generate_tests time (verification tests should be a lot more concise now)
1 parent b006344 commit 0a7e06a

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ public function trimAssertionAttributes()
227227
$oldAttributes = array_intersect($actionAttributeKeys, ActionObject::OLD_ASSERTION_ATTRIBUTES);
228228
if (!empty($oldAttributes)) {
229229
// @codingStandardsIgnoreStart
230-
echo("WARNING: Use of one line Assertion actions will be deprecated in MFTF 3.0.0, please use nested syntax (Action: {$this->type} StepKey: {$this->stepKey})" . PHP_EOL);
230+
if ($GLOBALS['GENERATE_TESTS'] ?? false == true) {
231+
echo("WARNING: Use of one line Assertion actions will be deprecated in MFTF 3.0.0, please use nested syntax (Action: {$this->type} StepKey: {$this->stepKey})" . PHP_EOL);
232+
}
231233
// @codingStandardsIgnoreEnd
232234
return;
233235
}
@@ -239,6 +241,29 @@ public function trimAssertionAttributes()
239241
return;
240242
}
241243

244+
$this->validateAssertionSchema($relevantAssertionAttributes);
245+
246+
// Flatten nested Elements's type and value into key=>value entries
247+
foreach ($this->actionAttributes as $key => $subAttributes) {
248+
if (in_array($key, $relevantKeys)) {
249+
$prefix = ActionObject::ASSERTION_ATTRIBUTES[$key];
250+
$this->resolvedCustomAttributes[$prefix . ucfirst(ActionObject::ASSERTION_TYPE_ATTRIBUTE)] =
251+
$subAttributes[ActionObject::ASSERTION_TYPE_ATTRIBUTE];
252+
$this->resolvedCustomAttributes[$prefix] =
253+
$subAttributes[ActionObject::ASSERTION_VALUE_ATTRIBUTE];
254+
unset($this->actionAttributes[$key]);
255+
}
256+
}
257+
}
258+
259+
/**
260+
* Validates that the given assertion attributes have valid schema according to nested assertion syntax.
261+
* @param array $attributes
262+
* @return void
263+
* @throws TestReferenceException
264+
*/
265+
private function validateAssertionSchema($attributes)
266+
{
242267
/** MQE-683 DEPRECATE OLD METHOD HERE
243268
* Unnecessary validation, only needed for backwards compatibility
244269
*/
@@ -247,25 +272,13 @@ public function trimAssertionAttributes()
247272
'assertElementContainsAttribute'];
248273

249274
if (!in_array($this->type, $singleChildTypes)) {
250-
if (!in_array('expectedResult', $relevantAssertionAttributes)
251-
|| !in_array('actualResult', $relevantAssertionAttributes)) {
275+
if (!in_array('expectedResult', $attributes)
276+
|| !in_array('actualResult', $attributes)) {
252277
// @codingStandardsIgnoreStart
253278
throw new TestReferenceException("{$this->type} must have both an expectedResult and actualResult defined (stepKey: {$this->stepKey})");
254279
// @codingStandardsIgnoreEnd
255280
}
256281
}
257-
258-
// Flatten nested Elements's type and value into key=>value entries
259-
foreach ($this->actionAttributes as $key => $subAttributes) {
260-
if (in_array($key, $relevantKeys)) {
261-
$prefix = ActionObject::ASSERTION_ATTRIBUTES[$key];
262-
$this->resolvedCustomAttributes[$prefix . ucfirst(ActionObject::ASSERTION_TYPE_ATTRIBUTE)] =
263-
$subAttributes[ActionObject::ASSERTION_TYPE_ATTRIBUTE];
264-
$this->resolvedCustomAttributes[$prefix] =
265-
$subAttributes[ActionObject::ASSERTION_VALUE_ATTRIBUTE];
266-
unset($this->actionAttributes[$key]);
267-
}
268-
}
269282
}
270283

271284
/**

src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ private static function validateConfigBasedVars($config)
8686
*/
8787
public static function sanitizeUrl($url)
8888
{
89-
if ($url === "") {
89+
$forceGenerate = $GLOBALS['FORCE_PHP_GENERATE'] ?? false;
90+
if (strlen($url) == 0 && $forceGenerate === false) {
9091
trigger_error("MAGENTO_BASE_URL must be defined in .env", E_USER_ERROR);
9192
}
9293

src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,12 @@ private function __construct()
126126
*/
127127
public function getEnabledModules()
128128
{
129+
$testGenerationPhase = $GLOBALS['GENERATE_TESTS'] ?? false;
130+
129131
if (isset($this->enabledModules)) {
130132
return $this->enabledModules;
131133
}
132134

133-
$testGenerationPhase = $GLOBALS['GENERATE_TESTS'] ?? false;
134135
if ($testGenerationPhase) {
135136
$this->printMagentoVersionInfo();
136137
}
@@ -141,7 +142,7 @@ public function getEnabledModules()
141142
return $this->enabledModules;
142143
}
143144

144-
$url = ConfigSanitizerUtil::sanitizeUrl($_ENV['MAGENTO_BASE_URL']) . $this->moduleUrl;
145+
$url = ConfigSanitizerUtil::sanitizeUrl(getenv('MAGENTO_BASE_URL')) . $this->moduleUrl;
145146

146147
$headers = [
147148
'Authorization: Bearer ' . $token,
@@ -253,6 +254,11 @@ private function printMagentoVersionInfo()
253254
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
254255
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
255256
$response = curl_exec($ch);
257+
258+
if (!$response) {
259+
$response = "No version information available.";
260+
}
261+
256262
print "\nVersion Information: {$response}\n";
257263
}
258264

0 commit comments

Comments
 (0)