Skip to content

MQE-1957: Entity Deprecation Reference - Static Check #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/commands/mftf.md
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@ If no script name argument is specified, all existing static check scripts will
vendor/bin/mftf static-checks [<names>]...
```

#### Options

| Option | Description |
|-----------------------|-----------------------------------------------------------------------------------------------------------|
| `-p, --path` | Path to a MFTF test module to run "deprecatedEntityUsage" static check script. Option is ignored by other static check scripts.

#### Examples

To check what existing static check scripts are available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function get($filename, $scope)
);

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

if (realpath($altPath) && ($altPath !== TESTS_BP)) {
$paths = array_merge(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Exception;
use Symfony\Component\Console\Style\SymfonyStyle;

class StaticChecksCommand extends Command
{
Expand All @@ -34,6 +36,13 @@ class StaticChecksCommand extends Command
*/
private $staticCheckObjects;

/**
* Console output style
*
* @var SymfonyStyle
*/
protected $ioStyle;

/**
* Configures the current command.
*
Expand All @@ -44,14 +53,20 @@ protected function configure()
$list = new StaticChecksList();
$this->allStaticCheckObjects = $list->getStaticChecks();
$staticCheckNames = implode(', ', array_keys($this->allStaticCheckObjects));
$description = "This command will run all static checks on xml test materials. "
. "Available static check scripts are:\n{$staticCheckNames}";
$description = 'This command will run all static checks on xml test materials. '
. 'Available static check scripts are:' . PHP_EOL . $staticCheckNames;
$this->setName('static-checks')
->setDescription($description)
->addArgument(
'names',
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'name(s) of specific static check script(s) to run'
)->addOption(
'path',
'p',
InputOption::VALUE_OPTIONAL,
'Path to a MFTF test module to run "deprecatedEntityUsage" static check script. ' . PHP_EOL
. 'Option is ignored by other static check scripts.' . PHP_EOL
);
}

Expand All @@ -65,32 +80,41 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->ioStyle = new SymfonyStyle($input, $output);
try {
$this->validateInputArguments($input, $output);
$this->validateInput($input);
} catch (InvalidArgumentException $e) {
LoggingUtil::getInstance()->getLogger(StaticChecksCommand::class)->error($e->getMessage());
$output->writeln($e->getMessage() . " Please fix input arguments and rerun.");
$this->ioStyle->error($e->getMessage() . ' Please fix input argument(s) or option(s) and rerun.');
return 1;
}

$cmdFailed = false;
$errors = [];
foreach ($this->staticCheckObjects as $name => $staticCheck) {
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->info(
"\nRunning static check script for: " . $name
);
$output->writeln(
"\nRunning static check script for: " . $name
'Running static check script for: ' . $name . PHP_EOL
);

$staticCheck->execute($input);
$this->ioStyle->text(PHP_EOL . 'Running static check script for: ' . $name . PHP_EOL);
$start = microtime(true);
try {
$staticCheck->execute($input);
} catch (Exception $e) {
$cmdFailed = true;
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->error($e->getMessage() . PHP_EOL);
$this->ioStyle->error($e->getMessage());
}
$end = microtime(true);
$errors += $staticCheck->getErrors();

$staticOutput = $staticCheck->getOutput();
LoggingUtil::getInstance()->getLogger(get_class($staticCheck))->info($staticOutput);
$output->writeln($staticOutput);
$errors += $staticCheck->getErrors();
}
$this->ioStyle->text($staticOutput);

if (empty($errors)) {
$this->ioStyle->text('Total execution time is ' . (string)($end - $start) . ' seconds.' . PHP_EOL);
}
if (!$cmdFailed && empty($errors)) {
return 0;
} else {
return 1;
Expand All @@ -104,7 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
* @return void
* @throws InvalidArgumentException
*/
private function validateInputArguments(InputInterface $input)
private function validateInput(InputInterface $input)
{
$this->staticCheckObjects = [];
$requiredChecksNames = $input->getArgument('names');
Expand All @@ -126,8 +150,18 @@ private function validateInputArguments(InputInterface $input)

if (!empty($invalidCheckNames)) {
throw new InvalidArgumentException(
"Invalid static check script(s): " . implode(', ', $invalidCheckNames) . "."
'Invalid static check script(s): ' . implode(', ', $invalidCheckNames) . '.'
);
}

if ($input->getOption('path')) {
if ( (count($this->staticCheckObjects) !== 1)
|| array_keys($this->staticCheckObjects)[0] !== StaticChecksList::DEPRECATED_ENTITY_USAGE_CHECK_NAME )
throw new InvalidArgumentException(
'--path option can only be used for "'
. StaticChecksList::DEPRECATED_ENTITY_USAGE_CHECK_NAME
. '".'
);
}
}
}
Loading