diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index 63cac272f..23e061b63 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -227,7 +227,9 @@ public function trimAssertionAttributes() $oldAttributes = array_intersect($actionAttributeKeys, ActionObject::OLD_ASSERTION_ATTRIBUTES); if (!empty($oldAttributes)) { // @codingStandardsIgnoreStart - 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); + if ($GLOBALS['GENERATE_TESTS'] ?? false == true) { + 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); + } // @codingStandardsIgnoreEnd return; } @@ -239,6 +241,29 @@ public function trimAssertionAttributes() return; } + $this->validateAssertionSchema($relevantAssertionAttributes); + + // Flatten nested Elements's type and value into key=>value entries + foreach ($this->actionAttributes as $key => $subAttributes) { + if (in_array($key, $relevantKeys)) { + $prefix = ActionObject::ASSERTION_ATTRIBUTES[$key]; + $this->resolvedCustomAttributes[$prefix . ucfirst(ActionObject::ASSERTION_TYPE_ATTRIBUTE)] = + $subAttributes[ActionObject::ASSERTION_TYPE_ATTRIBUTE]; + $this->resolvedCustomAttributes[$prefix] = + $subAttributes[ActionObject::ASSERTION_VALUE_ATTRIBUTE]; + unset($this->actionAttributes[$key]); + } + } + } + + /** + * Validates that the given assertion attributes have valid schema according to nested assertion syntax. + * @param array $attributes + * @return void + * @throws TestReferenceException + */ + private function validateAssertionSchema($attributes) + { /** MQE-683 DEPRECATE OLD METHOD HERE * Unnecessary validation, only needed for backwards compatibility */ @@ -247,25 +272,13 @@ public function trimAssertionAttributes() 'assertElementContainsAttribute']; if (!in_array($this->type, $singleChildTypes)) { - if (!in_array('expectedResult', $relevantAssertionAttributes) - || !in_array('actualResult', $relevantAssertionAttributes)) { + if (!in_array('expectedResult', $attributes) + || !in_array('actualResult', $attributes)) { // @codingStandardsIgnoreStart throw new TestReferenceException("{$this->type} must have both an expectedResult and actualResult defined (stepKey: {$this->stepKey})"); // @codingStandardsIgnoreEnd } } - - // Flatten nested Elements's type and value into key=>value entries - foreach ($this->actionAttributes as $key => $subAttributes) { - if (in_array($key, $relevantKeys)) { - $prefix = ActionObject::ASSERTION_ATTRIBUTES[$key]; - $this->resolvedCustomAttributes[$prefix . ucfirst(ActionObject::ASSERTION_TYPE_ATTRIBUTE)] = - $subAttributes[ActionObject::ASSERTION_TYPE_ATTRIBUTE]; - $this->resolvedCustomAttributes[$prefix] = - $subAttributes[ActionObject::ASSERTION_VALUE_ATTRIBUTE]; - unset($this->actionAttributes[$key]); - } - } } /** diff --git a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php index 17ce0b77a..c6244ca82 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php +++ b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php @@ -86,7 +86,8 @@ private static function validateConfigBasedVars($config) */ public static function sanitizeUrl($url) { - if ($url === "") { + $forceGenerate = $GLOBALS['FORCE_PHP_GENERATE'] ?? false; + if (strlen($url) == 0 && $forceGenerate === false) { trigger_error("MAGENTO_BASE_URL must be defined in .env", E_USER_ERROR); } diff --git a/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php b/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php index 8dd5536b8..2377f428a 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php +++ b/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php @@ -126,11 +126,12 @@ private function __construct() */ public function getEnabledModules() { + $testGenerationPhase = $GLOBALS['GENERATE_TESTS'] ?? false; + if (isset($this->enabledModules)) { return $this->enabledModules; } - $testGenerationPhase = $GLOBALS['GENERATE_TESTS'] ?? false; if ($testGenerationPhase) { $this->printMagentoVersionInfo(); } @@ -141,7 +142,7 @@ public function getEnabledModules() return $this->enabledModules; } - $url = ConfigSanitizerUtil::sanitizeUrl($_ENV['MAGENTO_BASE_URL']) . $this->moduleUrl; + $url = ConfigSanitizerUtil::sanitizeUrl(getenv('MAGENTO_BASE_URL')) . $this->moduleUrl; $headers = [ 'Authorization: Bearer ' . $token, @@ -252,6 +253,11 @@ private function printMagentoVersionInfo() curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); + + if (!$response) { + $response = "No version information available."; + } + print "\nVersion Information: {$response}\n"; }