From 164d969bc28cc1fc55eeb2d78b09faf5349cf2f6 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Wed, 6 May 2020 10:07:45 -0500 Subject: [PATCH 1/8] MQE-2047: Static Check Options - added ruleset reading functionality to static-checks command - added example staticRuleset.json to framework. --- .../Console/StaticChecksCommand.php | 29 +++++++++++++++++-- staticRuleset.json | 5 ++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 staticRuleset.json diff --git a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php index c8242c8b1..df3b3da24 100644 --- a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php @@ -22,6 +22,13 @@ class StaticChecksCommand extends Command { + /** + * Associative array containing static ruleset properties. + * + * @var array + */ + private $ruleSet; + /** * Pool of all existing static check objects * @@ -81,6 +88,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $this->ioStyle = new SymfonyStyle($input, $output); + $this->parseRulesetJson(); try { $this->validateInput($input); } catch (InvalidArgumentException $e) { @@ -133,8 +141,10 @@ private function validateInput(InputInterface $input) $this->staticCheckObjects = []; $requiredChecksNames = $input->getArgument('names'); $invalidCheckNames = []; - // Found user required static check script(s) to run, - // If no static check name is supplied, run all static check scripts + // Build list of static check names to run. + if (empty($requiredChecksNames) && isset($this->ruleSet['tests'])) { + $requiredChecksNames = $this->ruleSet['tests']; + } if (empty($requiredChecksNames)) { $this->staticCheckObjects = $this->allStaticCheckObjects; } else { @@ -164,4 +174,19 @@ private function validateInput(InputInterface $input) ); } } + + /** + * Parses and sets local ruleSet. If not found, simply returns and lets script continue. + * @return void; + */ + private function parseRulesetJson() + { + $pathToRuleset = FW_BP . DIRECTORY_SEPARATOR . "staticRuleset.json"; + if ($pathToRuleset === null) { + $this->ioStyle->text("No ruleset under $pathToRuleset" . PHP_EOL); + return; + } + $this->ioStyle->text("Using ruleset under $pathToRuleset" . PHP_EOL); + $this->ruleSet = json_decode(file_get_contents($pathToRuleset), true); + } } diff --git a/staticRuleset.json b/staticRuleset.json new file mode 100644 index 000000000..b65d8b83d --- /dev/null +++ b/staticRuleset.json @@ -0,0 +1,5 @@ +{ + "tests": [ + "actionGroupArguments" + ] +} From c2a53cf5bff9bff83070beb7a26631b5d9d70548 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Wed, 6 May 2020 11:39:22 -0500 Subject: [PATCH 2/8] MQE-2047: Static Check Options - Fixed project root --- .../FunctionalTestingFramework/Console/StaticChecksCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php index df3b3da24..d76404cf0 100644 --- a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php @@ -181,7 +181,7 @@ private function validateInput(InputInterface $input) */ private function parseRulesetJson() { - $pathToRuleset = FW_BP . DIRECTORY_SEPARATOR . "staticRuleset.json"; + $pathToRuleset = PROJECT_ROOT . DIRECTORY_SEPARATOR . "staticRuleset.json"; if ($pathToRuleset === null) { $this->ioStyle->text("No ruleset under $pathToRuleset" . PHP_EOL); return; From 52360a732464f2539a4a20a45076180e86be02cf Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Wed, 6 May 2020 12:35:51 -0500 Subject: [PATCH 3/8] MQE-2047: Static Check Options -Fixed to use TESTS_BP, should be good now. --- staticRuleset.json => dev/staticRuleset.json | 0 .../FunctionalTestingFramework/Console/StaticChecksCommand.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename staticRuleset.json => dev/staticRuleset.json (100%) diff --git a/staticRuleset.json b/dev/staticRuleset.json similarity index 100% rename from staticRuleset.json rename to dev/staticRuleset.json diff --git a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php index d76404cf0..1d33102e6 100644 --- a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php @@ -181,7 +181,7 @@ private function validateInput(InputInterface $input) */ private function parseRulesetJson() { - $pathToRuleset = PROJECT_ROOT . DIRECTORY_SEPARATOR . "staticRuleset.json"; + $pathToRuleset = TESTS_BP . DIRECTORY_SEPARATOR . "staticRuleset.json"; if ($pathToRuleset === null) { $this->ioStyle->text("No ruleset under $pathToRuleset" . PHP_EOL); return; From 488327ee4bfcac4b16bdd56ef2fdd39af72f27f9 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Thu, 7 May 2020 09:29:23 -0500 Subject: [PATCH 4/8] MQE-2047: Static Check Options - Added docs - Fixed static check errors --- docs/commands/mftf.md | 28 ++++++++++++- .../Console/StaticChecksCommand.php | 40 ++++++++++++------- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/docs/commands/mftf.md b/docs/commands/mftf.md index a4d77ad7a..5ea4d6dcc 100644 --- a/docs/commands/mftf.md +++ b/docs/commands/mftf.md @@ -430,8 +430,11 @@ The example parameters are taken from the `etc/config/.env.example` file. ### `static-checks` -Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to. -If no script name argument is specified, all existing static check scripts will run. +Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to. +Behavior for determining what tests to runs is as follows: +* If test names are specified, runs only those tests +* If no test names are specified, run tests according to `staticRuleset.json` +* If no `staticRuleset.json` is found, run all tests. #### Usage @@ -489,6 +492,27 @@ vendor/bin/mftf static-checks testDependencies actionGroupArguments |`actionGroupArguments` | Checks that action groups do not have unused arguments.| |`deprecatedEntityUsage`| Checks that deprecated test entities are not being referenced.| +#### Defining ruleset + +The `static-checks` command will look for a `staticRuleset.json` file under either: +* `dev/tests/acceptance/staticRuleset.json` if embedded with Magento2 +* `dev/staticRuleset.json` if standalone + +This file works as a default configuration to easily allow for integration of `static-checks` in a CI environment. + +Currently, the ruleset only defines the tests to run. Here is an example of the expected format: + +```json +{ + "tests": [ + "actionGroupArguments", + "anotherTest" + ] +} + +``` + + ### `upgrade:tests` When the path argument is specified, this `upgrade` command applies all the major version MFTF upgrade scripts to a `Test Module` in the given path. diff --git a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php index 1d33102e6..934ff14a6 100644 --- a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php @@ -140,7 +140,6 @@ private function validateInput(InputInterface $input) { $this->staticCheckObjects = []; $requiredChecksNames = $input->getArgument('names'); - $invalidCheckNames = []; // Build list of static check names to run. if (empty($requiredChecksNames) && isset($this->ruleSet['tests'])) { $requiredChecksNames = $this->ruleSet['tests']; @@ -148,20 +147,7 @@ private function validateInput(InputInterface $input) if (empty($requiredChecksNames)) { $this->staticCheckObjects = $this->allStaticCheckObjects; } else { - for ($index = 0; $index < count($requiredChecksNames); $index++) { - if (in_array($requiredChecksNames[$index], array_keys($this->allStaticCheckObjects))) { - $this->staticCheckObjects[$requiredChecksNames[$index]] = - $this->allStaticCheckObjects[$requiredChecksNames[$index]]; - } else { - $invalidCheckNames[] = $requiredChecksNames[$index]; - } - } - } - - if (!empty($invalidCheckNames)) { - throw new InvalidArgumentException( - 'Invalid static check script(s): ' . implode(', ', $invalidCheckNames) . '.' - ); + $this->validateTestNames($requiredChecksNames); } if ($input->getOption('path')) { @@ -175,6 +161,30 @@ private function validateInput(InputInterface $input) } } + /** + * Validates that all passed in static-check names match an existing static check + * @param string[] $requiredChecksNames + * @return void + */ + private function validateTestNames($requiredChecksNames) + { + $invalidCheckNames = []; + for ($index = 0; $index < count($requiredChecksNames); $index++) { + if (in_array($requiredChecksNames[$index], array_keys($this->allStaticCheckObjects))) { + $this->staticCheckObjects[$requiredChecksNames[$index]] = + $this->allStaticCheckObjects[$requiredChecksNames[$index]]; + } else { + $invalidCheckNames[] = $requiredChecksNames[$index]; + } + } + + if (!empty($invalidCheckNames)) { + throw new InvalidArgumentException( + 'Invalid static check script(s): ' . implode(', ', $invalidCheckNames) . '.' + ); + } + } + /** * Parses and sets local ruleSet. If not found, simply returns and lets script continue. * @return void; From 2167a37f8ac934f023ae644241d032f9a1c393f2 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Thu, 7 May 2020 09:43:38 -0500 Subject: [PATCH 5/8] MQE-2047: Static Check Options - Added proper static checks to sample file. --- dev/staticRuleset.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dev/staticRuleset.json b/dev/staticRuleset.json index b65d8b83d..98041c3d8 100644 --- a/dev/staticRuleset.json +++ b/dev/staticRuleset.json @@ -1,5 +1,6 @@ { "tests": [ - "actionGroupArguments" + "actionGroupArguments", + "deprecatedEntityUsage" ] -} +} \ No newline at end of file From 7b3aca15c6444f887d5875b45632292999994d51 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Mon, 11 May 2020 09:21:01 -0500 Subject: [PATCH 6/8] MQE-2047: Static Check Options - CR Fixes --- dev/staticRuleset.json | 6 ------ .../Console/StaticChecksCommand.php | 8 ++++---- 2 files changed, 4 insertions(+), 10 deletions(-) delete mode 100644 dev/staticRuleset.json diff --git a/dev/staticRuleset.json b/dev/staticRuleset.json deleted file mode 100644 index 98041c3d8..000000000 --- a/dev/staticRuleset.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "tests": [ - "actionGroupArguments", - "deprecatedEntityUsage" - ] -} \ No newline at end of file diff --git a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php index 934ff14a6..792f65ff1 100644 --- a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php @@ -88,7 +88,6 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $this->ioStyle = new SymfonyStyle($input, $output); - $this->parseRulesetJson(); try { $this->validateInput($input); } catch (InvalidArgumentException $e) { @@ -141,8 +140,9 @@ private function validateInput(InputInterface $input) $this->staticCheckObjects = []; $requiredChecksNames = $input->getArgument('names'); // Build list of static check names to run. - if (empty($requiredChecksNames) && isset($this->ruleSet['tests'])) { - $requiredChecksNames = $this->ruleSet['tests']; + if (empty($requiredChecksNames)) { + $this->parseRulesetJson(); + $requiredChecksNames = $this->ruleSet['tests'] ?? null; } if (empty($requiredChecksNames)) { $this->staticCheckObjects = $this->allStaticCheckObjects; @@ -192,7 +192,7 @@ private function validateTestNames($requiredChecksNames) private function parseRulesetJson() { $pathToRuleset = TESTS_BP . DIRECTORY_SEPARATOR . "staticRuleset.json"; - if ($pathToRuleset === null) { + if (!file_exists($pathToRuleset)) { $this->ioStyle->text("No ruleset under $pathToRuleset" . PHP_EOL); return; } From 37d16ccf9a672e78e254494f0fe64118f3e61395 Mon Sep 17 00:00:00 2001 From: Kevin Kozan Date: Mon, 11 May 2020 11:27:56 -0500 Subject: [PATCH 7/8] MQE-2047: Static Check Options - CR Fixes --- .../Console/StaticChecksCommand.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php index 792f65ff1..fe07dbaaf 100644 --- a/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php +++ b/src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php @@ -191,7 +191,12 @@ private function validateTestNames($requiredChecksNames) */ private function parseRulesetJson() { - $pathToRuleset = TESTS_BP . DIRECTORY_SEPARATOR . "staticRuleset.json"; + $pathAddition = "/dev/tests/acceptance/"; + // MFTF is both NOT attached and no MAGENTO_BP defined in .env + if (MAGENTO_BP === FW_BP) { + $pathAddition = "/dev/"; + } + $pathToRuleset = MAGENTO_BP . $pathAddition . "staticRuleset.json"; if (!file_exists($pathToRuleset)) { $this->ioStyle->text("No ruleset under $pathToRuleset" . PHP_EOL); return; From a7964e84dfabcfd20a154ee1d514503079620ab0 Mon Sep 17 00:00:00 2001 From: Donald Booth Date: Mon, 11 May 2020 14:57:00 -0500 Subject: [PATCH 8/8] Grammar and formatting --- docs/commands/mftf.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/commands/mftf.md b/docs/commands/mftf.md index 5ea4d6dcc..55b488e52 100644 --- a/docs/commands/mftf.md +++ b/docs/commands/mftf.md @@ -431,10 +431,11 @@ The example parameters are taken from the `etc/config/.env.example` file. ### `static-checks` Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to. -Behavior for determining what tests to runs is as follows: -* If test names are specified, runs only those tests -* If no test names are specified, run tests according to `staticRuleset.json` -* If no `staticRuleset.json` is found, run all tests. +Behavior for determining what tests to run is as follows: + +* If test names are specified, only those tests are run. +* If no test names are specified, tests are run according to `staticRuleset.json`. +* If no `staticRuleset.json` is found, all tests are run. #### Usage @@ -495,11 +496,11 @@ vendor/bin/mftf static-checks testDependencies actionGroupArguments #### Defining ruleset The `static-checks` command will look for a `staticRuleset.json` file under either: -* `dev/tests/acceptance/staticRuleset.json` if embedded with Magento2 -* `dev/staticRuleset.json` if standalone -This file works as a default configuration to easily allow for integration of `static-checks` in a CI environment. +* `dev/tests/acceptance/staticRuleset.json`, if embedded with Magento2 +* `dev/staticRuleset.json`, if standalone +This file works as the default configuration to easily allow for the integration of `static-checks` in a CI environment. Currently, the ruleset only defines the tests to run. Here is an example of the expected format: ```json @@ -509,10 +510,8 @@ Currently, the ruleset only defines the tests to run. Here is an example of the "anotherTest" ] } +``` -``` - - ### `upgrade:tests` When the path argument is specified, this `upgrade` command applies all the major version MFTF upgrade scripts to a `Test Module` in the given path.