From dccb87487e67d6e1b0295bbc0857fd9c8b13ef36 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Tue, 6 Mar 2018 09:18:17 -0600 Subject: [PATCH 1/5] MQE-841: robo generate:tests --force should not require MAGENTO_BASE_URL - force flag no skips getEnabledModules if no BASE_URL is defined. - assertion action warning now only happens at generate_tests time (verification tests should be a lot more concise now) --- .../Test/Objects/ActionObject.php | 43 ++++++++++++------- .../Util/ModuleResolver.php | 8 +++- 2 files changed, 35 insertions(+), 16 deletions(-) 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/ModuleResolver.php b/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php index 8dd5536b8..c733ea0b7 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php +++ b/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php @@ -126,11 +126,17 @@ private function __construct() */ public function getEnabledModules() { + $testGenerationPhase = $GLOBALS['GENERATE_TESTS'] ?? false; + if (isset($this->enabledModules)) { return $this->enabledModules; + } elseif (!isset($_ENV['MAGENTO_BASE_URL']) && $GLOBALS['FORCE_PHP_GENERATE'] ?? false == true) { + if ($testGenerationPhase) { + print "\nWARNING: No MAGENTO_BASE_URL defined in .env file, merging test files alphabetically.\n"; + } + return null; } - $testGenerationPhase = $GLOBALS['GENERATE_TESTS'] ?? false; if ($testGenerationPhase) { $this->printMagentoVersionInfo(); } From bb2dc3d0ab8062685f82a7c04977edc47affb5a6 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Wed, 7 Mar 2018 13:13:11 -0600 Subject: [PATCH 2/5] MQE-841: robo generate:tests --force should not require MAGENTO_BASE_URL - CR fixes --- .../Util/ConfigSanitizerUtil.php | 6 +++++- .../Util/ModuleResolver.php | 12 ++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php index 17ce0b77a..5207d86ee 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php +++ b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php @@ -86,8 +86,12 @@ private static function validateConfigBasedVars($config) */ public static function sanitizeUrl($url) { + $forceGenerate = $GLOBALS['FORCE_PHP_GENERATE'] ?? false; if ($url === "") { - trigger_error("MAGENTO_BASE_URL must be defined in .env", E_USER_ERROR); + if ($forceGenerate === false) { + trigger_error("MAGENTO_BASE_URL must be defined in .env", E_USER_ERROR); + } + return $url; } if (filter_var($url, FILTER_VALIDATE_URL) === true) { diff --git a/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php b/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php index c733ea0b7..2377f428a 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php +++ b/src/Magento/FunctionalTestingFramework/Util/ModuleResolver.php @@ -130,11 +130,6 @@ public function getEnabledModules() if (isset($this->enabledModules)) { return $this->enabledModules; - } elseif (!isset($_ENV['MAGENTO_BASE_URL']) && $GLOBALS['FORCE_PHP_GENERATE'] ?? false == true) { - if ($testGenerationPhase) { - print "\nWARNING: No MAGENTO_BASE_URL defined in .env file, merging test files alphabetically.\n"; - } - return null; } if ($testGenerationPhase) { @@ -147,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, @@ -258,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"; } From c432dfa1accaa757c851ea513a7af5ae388b92e2 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Wed, 7 Mar 2018 13:36:32 -0600 Subject: [PATCH 3/5] MQE-841: robo generate:tests --force should not require MAGENTO_BASE_URL - CR fixes. --- .../Util/ConfigSanitizerUtil.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php index 5207d86ee..a0a96d27f 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php +++ b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php @@ -87,11 +87,8 @@ private static function validateConfigBasedVars($config) public static function sanitizeUrl($url) { $forceGenerate = $GLOBALS['FORCE_PHP_GENERATE'] ?? false; - if ($url === "") { - if ($forceGenerate === false) { - trigger_error("MAGENTO_BASE_URL must be defined in .env", E_USER_ERROR); - } - return $url; + if ($url === "" && $forceGenerate === false) { + trigger_error("MAGENTO_BASE_URL must be defined in .env", E_USER_ERROR); } if (filter_var($url, FILTER_VALIDATE_URL) === true) { From 48cea52d54ea63fa4c6b4f32e672e449863e6f90 Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Wed, 7 Mar 2018 16:06:38 -0600 Subject: [PATCH 4/5] MQE-841: robo generate:tests --force should not require MAGENTO_BASE_URL - CR Fixes --- .../FunctionalTestingFramework/Util/ConfigSanitizerUtil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php index a0a96d27f..dd3ef8465 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php +++ b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php @@ -87,7 +87,7 @@ private static function validateConfigBasedVars($config) public static function sanitizeUrl($url) { $forceGenerate = $GLOBALS['FORCE_PHP_GENERATE'] ?? false; - if ($url === "" && $forceGenerate === false) { + if (strlen($url) == 0 && $forceGenerate === false) { trigger_error("MAGENTO_BASE_URL must be defined in .env", E_USER_ERROR); } From ce6d2a185a9f5bd867775258c0d17ba69ca4e46a Mon Sep 17 00:00:00 2001 From: KevinBKozan Date: Fri, 9 Mar 2018 11:35:10 -0600 Subject: [PATCH 5/5] MQE-841: robo generate:tests --force should not require MAGENTO_BASE_URL - PHPCS fix. --- .../FunctionalTestingFramework/Util/ConfigSanitizerUtil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php index dd3ef8465..c6244ca82 100644 --- a/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php +++ b/src/Magento/FunctionalTestingFramework/Util/ConfigSanitizerUtil.php @@ -87,7 +87,7 @@ private static function validateConfigBasedVars($config) public static function sanitizeUrl($url) { $forceGenerate = $GLOBALS['FORCE_PHP_GENERATE'] ?? false; - if (strlen($url) == 0 && $forceGenerate === false) { + if (strlen($url) == 0 && $forceGenerate === false) { trigger_error("MAGENTO_BASE_URL must be defined in .env", E_USER_ERROR); }