Skip to content

Commit

Permalink
Merge pull request #165 from magento-commerce/2.x-develop-filters
Browse files Browse the repository at this point in the history
MQE-3251: Release MFTF 2.7.3 to allow filters functionality for Magento 2.3.x
  • Loading branch information
okolesnyk authored Feb 17, 2022
2 parents 042c6a6 + db5466e commit 63a8e2f
Show file tree
Hide file tree
Showing 7 changed files with 633 additions and 63 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Magento Functional Testing Framework Changelog
================================================
2.7.3
---------

### Enhancements

* Add filter for groups, now we can generate tests with specific group annotation

2.7.2
---------
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magento/magento2-functional-testing-framework",
"description": "Magento2 Functional Testing Framework",
"type": "library",
"version": "2.7.2",
"version": "2.7.3",
"license": "AGPL-3.0",
"keywords": ["magento", "automation", "functional", "testing"],
"config": {
Expand Down
75 changes: 38 additions & 37 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 89 additions & 25 deletions src/Magento/FunctionalTestingFramework/Console/StaticChecksCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@
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
{
/**
* Associative array containing static ruleset properties.
*
* @var array
*/
private $ruleSet;

/**
* Pool of all existing static check objects
*
Expand All @@ -34,6 +43,13 @@ class StaticChecksCommand extends Command
*/
private $staticCheckObjects;

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

/**
* Configures the current command.
*
Expand All @@ -44,14 +60,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 +87,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,30 +135,63 @@ 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');
$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)) {
$this->parseRulesetJson();
$requiredChecksNames = $this->ruleSet['tests'] ?? null;
}
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];
}
$this->validateTestNames($requiredChecksNames);
}
}

/**
* 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) . "."
'Invalid static check script(s): ' . implode(', ', $invalidCheckNames) . '.'
);
}
}

/**
* Parses and sets local ruleSet. If not found, simply returns and lets script continue.
* @return void;
*/
private function parseRulesetJson()
{
$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;
}
$this->ioStyle->text("Using ruleset under $pathToRuleset" . PHP_EOL);
$this->ruleSet = json_decode(file_get_contents($pathToRuleset), true);
}
}
Loading

0 comments on commit 63a8e2f

Please sign in to comment.