Skip to content

Commit 488327e

Browse files
committed
MQE-2047: Static Check Options
- Added docs - Fixed static check errors
1 parent 52360a7 commit 488327e

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

docs/commands/mftf.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,11 @@ The example parameters are taken from the `etc/config/.env.example` file.
430430

431431
### `static-checks`
432432

433-
Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to.
434-
If no script name argument is specified, all existing static check scripts will run.
433+
Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to.
434+
Behavior for determining what tests to runs is as follows:
435+
* If test names are specified, runs only those tests
436+
* If no test names are specified, run tests according to `staticRuleset.json`
437+
* If no `staticRuleset.json` is found, run all tests.
435438

436439
#### Usage
437440

@@ -489,6 +492,27 @@ vendor/bin/mftf static-checks testDependencies actionGroupArguments
489492
|`actionGroupArguments` | Checks that action groups do not have unused arguments.|
490493
|`deprecatedEntityUsage`| Checks that deprecated test entities are not being referenced.|
491494
495+
#### Defining ruleset
496+
497+
The `static-checks` command will look for a `staticRuleset.json` file under either:
498+
* `dev/tests/acceptance/staticRuleset.json` if embedded with Magento2
499+
* `dev/staticRuleset.json` if standalone
500+
501+
This file works as a default configuration to easily allow for integration of `static-checks` in a CI environment.
502+
503+
Currently, the ruleset only defines the tests to run. Here is an example of the expected format:
504+
505+
```json
506+
{
507+
"tests": [
508+
"actionGroupArguments",
509+
"anotherTest"
510+
]
511+
}
512+
513+
```
514+
515+
492516
### `upgrade:tests`
493517

494518
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.

src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,28 +140,14 @@ private function validateInput(InputInterface $input)
140140
{
141141
$this->staticCheckObjects = [];
142142
$requiredChecksNames = $input->getArgument('names');
143-
$invalidCheckNames = [];
144143
// Build list of static check names to run.
145144
if (empty($requiredChecksNames) && isset($this->ruleSet['tests'])) {
146145
$requiredChecksNames = $this->ruleSet['tests'];
147146
}
148147
if (empty($requiredChecksNames)) {
149148
$this->staticCheckObjects = $this->allStaticCheckObjects;
150149
} else {
151-
for ($index = 0; $index < count($requiredChecksNames); $index++) {
152-
if (in_array($requiredChecksNames[$index], array_keys($this->allStaticCheckObjects))) {
153-
$this->staticCheckObjects[$requiredChecksNames[$index]] =
154-
$this->allStaticCheckObjects[$requiredChecksNames[$index]];
155-
} else {
156-
$invalidCheckNames[] = $requiredChecksNames[$index];
157-
}
158-
}
159-
}
160-
161-
if (!empty($invalidCheckNames)) {
162-
throw new InvalidArgumentException(
163-
'Invalid static check script(s): ' . implode(', ', $invalidCheckNames) . '.'
164-
);
150+
$this->validateTestNames($requiredChecksNames);
165151
}
166152

167153
if ($input->getOption('path')) {
@@ -175,6 +161,30 @@ private function validateInput(InputInterface $input)
175161
}
176162
}
177163

164+
/**
165+
* Validates that all passed in static-check names match an existing static check
166+
* @param string[] $requiredChecksNames
167+
* @return void
168+
*/
169+
private function validateTestNames($requiredChecksNames)
170+
{
171+
$invalidCheckNames = [];
172+
for ($index = 0; $index < count($requiredChecksNames); $index++) {
173+
if (in_array($requiredChecksNames[$index], array_keys($this->allStaticCheckObjects))) {
174+
$this->staticCheckObjects[$requiredChecksNames[$index]] =
175+
$this->allStaticCheckObjects[$requiredChecksNames[$index]];
176+
} else {
177+
$invalidCheckNames[] = $requiredChecksNames[$index];
178+
}
179+
}
180+
181+
if (!empty($invalidCheckNames)) {
182+
throw new InvalidArgumentException(
183+
'Invalid static check script(s): ' . implode(', ', $invalidCheckNames) . '.'
184+
);
185+
}
186+
}
187+
178188
/**
179189
* Parses and sets local ruleSet. If not found, simply returns and lets script continue.
180190
* @return void;

0 commit comments

Comments
 (0)