From 6f2affb6ddb167de610c218e99a775a4354f2910 Mon Sep 17 00:00:00 2001 From: Ji Lu Date: Thu, 28 May 2020 10:17:43 -0500 Subject: [PATCH 1/3] MQE-2135: MFTF static check output directory should not depend on current working directory --- .../StaticCheck/ActionGroupArgumentsCheck.php | 2 +- .../StaticCheck/AnnotationsCheck.php | 2 +- .../DeprecatedEntityUsageCheck.php | 2 +- .../StaticCheck/StaticChecksList.php | 25 +++++++++++++++++++ .../StaticCheck/TestDependencyCheck.php | 2 +- .../Util/Script/ScriptUtil.php | 14 +++++++---- 6 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/StaticCheck/ActionGroupArgumentsCheck.php b/src/Magento/FunctionalTestingFramework/StaticCheck/ActionGroupArgumentsCheck.php index e6afded68..8b95fb9d5 100644 --- a/src/Magento/FunctionalTestingFramework/StaticCheck/ActionGroupArgumentsCheck.php +++ b/src/Magento/FunctionalTestingFramework/StaticCheck/ActionGroupArgumentsCheck.php @@ -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 ); } diff --git a/src/Magento/FunctionalTestingFramework/StaticCheck/AnnotationsCheck.php b/src/Magento/FunctionalTestingFramework/StaticCheck/AnnotationsCheck.php index 86cbec2db..10aa853ec 100644 --- a/src/Magento/FunctionalTestingFramework/StaticCheck/AnnotationsCheck.php +++ b/src/Magento/FunctionalTestingFramework/StaticCheck/AnnotationsCheck.php @@ -82,7 +82,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 ); } diff --git a/src/Magento/FunctionalTestingFramework/StaticCheck/DeprecatedEntityUsageCheck.php b/src/Magento/FunctionalTestingFramework/StaticCheck/DeprecatedEntityUsageCheck.php index af5a1835e..5da16ec6a 100644 --- a/src/Magento/FunctionalTestingFramework/StaticCheck/DeprecatedEntityUsageCheck.php +++ b/src/Magento/FunctionalTestingFramework/StaticCheck/DeprecatedEntityUsageCheck.php @@ -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 ); } diff --git a/src/Magento/FunctionalTestingFramework/StaticCheck/StaticChecksList.php b/src/Magento/FunctionalTestingFramework/StaticCheck/StaticChecksList.php index 4b4b9b4c0..7cd894e00 100644 --- a/src/Magento/FunctionalTestingFramework/StaticCheck/StaticChecksList.php +++ b/src/Magento/FunctionalTestingFramework/StaticCheck/StaticChecksList.php @@ -7,6 +7,9 @@ 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 @@ -14,6 +17,7 @@ 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. @@ -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 = []) { @@ -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; + } } /** @@ -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; + } } diff --git a/src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php b/src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php index 9f20f2e08..6bfe17219 100644 --- a/src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php +++ b/src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php @@ -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 ); } diff --git a/src/Magento/FunctionalTestingFramework/Util/Script/ScriptUtil.php b/src/Magento/FunctionalTestingFramework/Util/Script/ScriptUtil.php index 84016721b..14f9c27e0 100644 --- a/src/Magento/FunctionalTestingFramework/Util/Script/ScriptUtil.php +++ b/src/Magento/FunctionalTestingFramework/Util/Script/ScriptUtil.php @@ -56,18 +56,22 @@ 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); @@ -75,7 +79,7 @@ public function printErrorsToFile($errors, $filename, $message) 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; } From 46068452f3b5d4dc41884ee462d8b41f3fa7356c Mon Sep 17 00:00:00 2001 From: Ji Lu Date: Thu, 28 May 2020 16:58:16 -0500 Subject: [PATCH 2/3] MQE-2135: MFTF static check output directory should not depend on current working directory --- docs/commands/mftf.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/commands/mftf.md b/docs/commands/mftf.md index b71e45148..f1ef3955d 100644 --- a/docs/commands/mftf.md +++ b/docs/commands/mftf.md @@ -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 From 3c04057471a3ef20fdd47c5f95566f79b4ea607f Mon Sep 17 00:00:00 2001 From: Ji Lu Date: Fri, 29 May 2020 16:32:19 -0500 Subject: [PATCH 3/3] MQE-2135: MFTF static check output directory should not depend on current working directory --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1ad606e97..fad995502 100755 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,4 @@ dev/tests/mftf.log dev/tests/docs/* dev/tests/_output dev/tests/functional.suite.yml -mftf-annotations-static-check.txt +