Skip to content

Mqe 2135 #721

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 5 commits into from
May 29, 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ dev/tests/mftf.log
dev/tests/docs/*
dev/tests/_output
dev/tests/functional.suite.yml
mftf-annotations-static-check.txt

4 changes: 3 additions & 1 deletion docs/commands/mftf.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,15 @@ 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.
Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to.
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.

Static checks errors are written to *.txt files under TEST_BP/tests/_output/static-results/

#### Usage

```bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function execute(InputInterface $input)

$this->output = $this->scriptUtil->printErrorsToFile(
$this->errors,
self::ERROR_LOG_FILENAME,
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
self::ERROR_LOG_MESSAGE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function execute(InputInterface $input)
$scriptUtil = new ScriptUtil();
$this->output = $scriptUtil->printErrorsToFile(
$this->errors,
self::ERROR_LOG_FILENAME,
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
self::ERROR_LOG_MESSAGE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function execute(InputInterface $input)
// Hold on to the output and print any errors to a file
$this->output = $this->scriptUtil->printErrorsToFile(
$this->errors,
self::ERROR_LOG_FILENAME,
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
self::ERROR_LOG_MESSAGE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@

namespace Magento\FunctionalTestingFramework\StaticCheck;

use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;

/**
* Class StaticChecksList has a list of static checks to run on test xml
* @codingStandardsIgnoreFile
*/
class StaticChecksList implements StaticCheckListInterface
{
const DEPRECATED_ENTITY_USAGE_CHECK_NAME = 'deprecatedEntityUsage';
const STATIC_RESULTS = 'tests' . DIRECTORY_SEPARATOR .'_output' . DIRECTORY_SEPARATOR . 'static-results';

/**
* Property contains all static check scripts.
Expand All @@ -22,10 +26,18 @@ class StaticChecksList implements StaticCheckListInterface
*/
private $checks;

/**
* Directory path for static checks error files
*
* @var string
*/
private static $errorFilesPath = null;

/**
* Constructor
*
* @param array $checks
* @throws TestFrameworkException
*/
public function __construct(array $checks = [])
{
Expand All @@ -35,6 +47,11 @@ public function __construct(array $checks = [])
self::DEPRECATED_ENTITY_USAGE_CHECK_NAME => new DeprecatedEntityUsageCheck(),
'annotations' => new AnnotationsCheck()
] + $checks;

// Static checks error files directory
if (null === self::$errorFilesPath) {
self::$errorFilesPath = FilePathFormatter::format(TESTS_BP) . self::STATIC_RESULTS;
}
}

/**
Expand All @@ -44,4 +61,12 @@ public function getStaticChecks()
{
return $this->checks;
}

/**
* Return the directory path for the static check error files
*/
public static function getErrorFilesPath()
{
return self::$errorFilesPath;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function execute(InputInterface $input)
// hold on to the output and print any errors to a file
$this->output = $this->scriptUtil->printErrorsToFile(
$this->errors,
self::ERROR_LOG_FILENAME,
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
self::ERROR_LOG_MESSAGE
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,30 @@ public function getAllModulePaths()
/**
* Prints out given errors to file, and returns summary result string
* @param array $errors
* @param string $filename
* @param string $filePath
* @param string $message
* @return string
*/
public function printErrorsToFile($errors, $filename, $message)
public function printErrorsToFile($errors, $filePath, $message)
{
if (empty($errors)) {
return $message . ": No errors found.";
}

$outputPath = getcwd() . DIRECTORY_SEPARATOR . $filename . ".txt";
$fileResource = fopen($outputPath, 'w');
$dirname = dirname($filePath);
if (!file_exists($dirname)) {
mkdir($dirname, 0777, true);
}

$fileResource = fopen($filePath, 'w');

foreach ($errors as $test => $error) {
fwrite($fileResource, $error[0] . PHP_EOL);
}

fclose($fileResource);
$errorCount = count($errors);
$output = $message . ": Errors found across {$errorCount} file(s). Error details output to {$outputPath}";
$output = $message . ": Errors found across {$errorCount} file(s). Error details output to {$filePath}";

return $output;
}
Expand Down