Skip to content

Commit 155d846

Browse files
authored
Merge pull request #658 from magento/MQE-1957
MQE-1957: Entity Deprecation Reference - Static Check
2 parents 9799582 + 101ead6 commit 155d846

File tree

9 files changed

+877
-28
lines changed

9 files changed

+877
-28
lines changed

docs/commands/mftf.md

+6
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,12 @@ If no script name argument is specified, all existing static check scripts will
439439
vendor/bin/mftf static-checks [<names>]...
440440
```
441441

442+
#### Options
443+
444+
| Option | Description |
445+
|-----------------------|-----------------------------------------------------------------------------------------------------------|
446+
| `-p, --path` | Path to a MFTF test module to run "deprecatedEntityUsage" static check script. Option is ignored by other static check scripts.
447+
442448
#### Examples
443449

444450
To check what existing static check scripts are available

src/Magento/FunctionalTestingFramework/Config/FileResolver/Root.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function get($filename, $scope)
3333
);
3434

3535
// include root suite dir when running standalone version
36-
$altPath = MAGENTO_BP . DIRECTORY_SEPARATOR . 'dev/tests/acceptance';
36+
$altPath = FilePathFormatter::format(MAGENTO_BP) . 'dev/tests/acceptance';
3737

3838
if (realpath($altPath) && ($altPath !== TESTS_BP)) {
3939
$paths = array_merge(

src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php

+49-15
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
use Symfony\Component\Console\Exception\InvalidArgumentException;
1616
use Symfony\Component\Console\Input\InputArgument;
1717
use Symfony\Component\Console\Input\InputInterface;
18+
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Output\OutputInterface;
1920
use Exception;
21+
use Symfony\Component\Console\Style\SymfonyStyle;
2022

2123
class StaticChecksCommand extends Command
2224
{
@@ -34,6 +36,13 @@ class StaticChecksCommand extends Command
3436
*/
3537
private $staticCheckObjects;
3638

39+
/**
40+
* Console output style
41+
*
42+
* @var SymfonyStyle
43+
*/
44+
protected $ioStyle;
45+
3746
/**
3847
* Configures the current command.
3948
*
@@ -44,14 +53,20 @@ protected function configure()
4453
$list = new StaticChecksList();
4554
$this->allStaticCheckObjects = $list->getStaticChecks();
4655
$staticCheckNames = implode(', ', array_keys($this->allStaticCheckObjects));
47-
$description = "This command will run all static checks on xml test materials. "
48-
. "Available static check scripts are:\n{$staticCheckNames}";
56+
$description = 'This command will run all static checks on xml test materials. '
57+
. 'Available static check scripts are:' . PHP_EOL . $staticCheckNames;
4958
$this->setName('static-checks')
5059
->setDescription($description)
5160
->addArgument(
5261
'names',
5362
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
5463
'name(s) of specific static check script(s) to run'
64+
)->addOption(
65+
'path',
66+
'p',
67+
InputOption::VALUE_OPTIONAL,
68+
'Path to a MFTF test module to run "deprecatedEntityUsage" static check script. ' . PHP_EOL
69+
. 'Option is ignored by other static check scripts.' . PHP_EOL
5570
);
5671
}
5772

@@ -65,32 +80,41 @@ protected function configure()
6580
*/
6681
protected function execute(InputInterface $input, OutputInterface $output)
6782
{
83+
$this->ioStyle = new SymfonyStyle($input, $output);
6884
try {
69-
$this->validateInputArguments($input, $output);
85+
$this->validateInput($input);
7086
} catch (InvalidArgumentException $e) {
7187
LoggingUtil::getInstance()->getLogger(StaticChecksCommand::class)->error($e->getMessage());
72-
$output->writeln($e->getMessage() . " Please fix input arguments and rerun.");
88+
$this->ioStyle->error($e->getMessage() . ' Please fix input argument(s) or option(s) and rerun.');
7389
return 1;
7490
}
7591

92+
$cmdFailed = false;
7693
$errors = [];
7794
foreach ($this->staticCheckObjects as $name => $staticCheck) {
7895
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->info(
79-
"\nRunning static check script for: " . $name
80-
);
81-
$output->writeln(
82-
"\nRunning static check script for: " . $name
96+
'Running static check script for: ' . $name . PHP_EOL
8397
);
8498

85-
$staticCheck->execute($input);
99+
$this->ioStyle->text(PHP_EOL . 'Running static check script for: ' . $name . PHP_EOL);
100+
$start = microtime(true);
101+
try {
102+
$staticCheck->execute($input);
103+
} catch (Exception $e) {
104+
$cmdFailed = true;
105+
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->error($e->getMessage() . PHP_EOL);
106+
$this->ioStyle->error($e->getMessage());
107+
}
108+
$end = microtime(true);
109+
$errors += $staticCheck->getErrors();
86110

87111
$staticOutput = $staticCheck->getOutput();
88112
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->info($staticOutput);
89-
$output->writeln($staticOutput);
90-
$errors += $staticCheck->getErrors();
91-
}
113+
$this->ioStyle->text($staticOutput);
92114

93-
if (empty($errors)) {
115+
$this->ioStyle->text('Total execution time is ' . (string)($end - $start) . ' seconds.' . PHP_EOL);
116+
}
117+
if (!$cmdFailed && empty($errors)) {
94118
return 0;
95119
} else {
96120
return 1;
@@ -104,7 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
104128
* @return void
105129
* @throws InvalidArgumentException
106130
*/
107-
private function validateInputArguments(InputInterface $input)
131+
private function validateInput(InputInterface $input)
108132
{
109133
$this->staticCheckObjects = [];
110134
$requiredChecksNames = $input->getArgument('names');
@@ -126,8 +150,18 @@ private function validateInputArguments(InputInterface $input)
126150

127151
if (!empty($invalidCheckNames)) {
128152
throw new InvalidArgumentException(
129-
"Invalid static check script(s): " . implode(', ', $invalidCheckNames) . "."
153+
'Invalid static check script(s): ' . implode(', ', $invalidCheckNames) . '.'
130154
);
131155
}
156+
157+
if ($input->getOption('path')) {
158+
if ( (count($this->staticCheckObjects) !== 1)
159+
|| array_keys($this->staticCheckObjects)[0] !== StaticChecksList::DEPRECATED_ENTITY_USAGE_CHECK_NAME )
160+
throw new InvalidArgumentException(
161+
'--path option can only be used for "'
162+
. StaticChecksList::DEPRECATED_ENTITY_USAGE_CHECK_NAME
163+
. '".'
164+
);
165+
}
132166
}
133167
}

0 commit comments

Comments
 (0)