Skip to content

Commit 64e7788

Browse files
authored
Merge pull request #721 from magento/MQE-2135
MQE-2135: MFTF static check output directory should not depend on current working directory
2 parents e8bc533 + 1481bc7 commit 64e7788

File tree

8 files changed

+42
-11
lines changed

8 files changed

+42
-11
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ dev/tests/mftf.log
1919
dev/tests/docs/*
2020
dev/tests/_output
2121
dev/tests/functional.suite.yml
22-
mftf-annotations-static-check.txt
22+

docs/commands/mftf.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,15 @@ The example parameters are taken from the `etc/config/.env.example` file.
430430

431431
### `static-checks`
432432

433-
Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to.
433+
Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to.
434434
Behavior for determining what tests to run is as follows:
435435

436436
* If test names are specified, only those tests are run.
437437
* If no test names are specified, tests are run according to `staticRuleset.json`.
438438
* If no `staticRuleset.json` is found, all tests are run.
439439

440+
Static checks errors are written to *.txt files under TEST_BP/tests/_output/static-results/
441+
440442
#### Usage
441443

442444
```bash

src/Magento/FunctionalTestingFramework/StaticCheck/ActionGroupArgumentsCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function execute(InputInterface $input)
6565

6666
$this->output = $this->scriptUtil->printErrorsToFile(
6767
$this->errors,
68-
self::ERROR_LOG_FILENAME,
68+
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
6969
self::ERROR_LOG_MESSAGE
7070
);
7171
}

src/Magento/FunctionalTestingFramework/StaticCheck/AnnotationsCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function execute(InputInterface $input)
8585
$scriptUtil = new ScriptUtil();
8686
$this->output = $scriptUtil->printErrorsToFile(
8787
$this->errors,
88-
self::ERROR_LOG_FILENAME,
88+
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
8989
self::ERROR_LOG_MESSAGE
9090
);
9191
}

src/Magento/FunctionalTestingFramework/StaticCheck/DeprecatedEntityUsageCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public function execute(InputInterface $input)
128128
// Hold on to the output and print any errors to a file
129129
$this->output = $this->scriptUtil->printErrorsToFile(
130130
$this->errors,
131-
self::ERROR_LOG_FILENAME,
131+
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
132132
self::ERROR_LOG_MESSAGE
133133
);
134134
}

src/Magento/FunctionalTestingFramework/StaticCheck/StaticChecksList.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77

88
namespace Magento\FunctionalTestingFramework\StaticCheck;
99

10+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
11+
use Magento\FunctionalTestingFramework\Util\Path\FilePathFormatter;
12+
1013
/**
1114
* Class StaticChecksList has a list of static checks to run on test xml
1215
* @codingStandardsIgnoreFile
1316
*/
1417
class StaticChecksList implements StaticCheckListInterface
1518
{
1619
const DEPRECATED_ENTITY_USAGE_CHECK_NAME = 'deprecatedEntityUsage';
20+
const STATIC_RESULTS = 'tests' . DIRECTORY_SEPARATOR .'_output' . DIRECTORY_SEPARATOR . 'static-results';
1721

1822
/**
1923
* Property contains all static check scripts.
@@ -22,10 +26,18 @@ class StaticChecksList implements StaticCheckListInterface
2226
*/
2327
private $checks;
2428

29+
/**
30+
* Directory path for static checks error files
31+
*
32+
* @var string
33+
*/
34+
private static $errorFilesPath = null;
35+
2536
/**
2637
* Constructor
2738
*
2839
* @param array $checks
40+
* @throws TestFrameworkException
2941
*/
3042
public function __construct(array $checks = [])
3143
{
@@ -35,6 +47,11 @@ public function __construct(array $checks = [])
3547
self::DEPRECATED_ENTITY_USAGE_CHECK_NAME => new DeprecatedEntityUsageCheck(),
3648
'annotations' => new AnnotationsCheck()
3749
] + $checks;
50+
51+
// Static checks error files directory
52+
if (null === self::$errorFilesPath) {
53+
self::$errorFilesPath = FilePathFormatter::format(TESTS_BP) . self::STATIC_RESULTS;
54+
}
3855
}
3956

4057
/**
@@ -44,4 +61,12 @@ public function getStaticChecks()
4461
{
4562
return $this->checks;
4663
}
64+
65+
/**
66+
* Return the directory path for the static check error files
67+
*/
68+
public static function getErrorFilesPath()
69+
{
70+
return self::$errorFilesPath;
71+
}
4772
}

src/Magento/FunctionalTestingFramework/StaticCheck/TestDependencyCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function execute(InputInterface $input)
121121
// hold on to the output and print any errors to a file
122122
$this->output = $this->scriptUtil->printErrorsToFile(
123123
$this->errors,
124-
self::ERROR_LOG_FILENAME,
124+
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
125125
self::ERROR_LOG_MESSAGE
126126
);
127127
}

src/Magento/FunctionalTestingFramework/Util/Script/ScriptUtil.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,30 @@ public function getAllModulePaths()
5656
/**
5757
* Prints out given errors to file, and returns summary result string
5858
* @param array $errors
59-
* @param string $filename
59+
* @param string $filePath
6060
* @param string $message
6161
* @return string
6262
*/
63-
public function printErrorsToFile($errors, $filename, $message)
63+
public function printErrorsToFile($errors, $filePath, $message)
6464
{
6565
if (empty($errors)) {
6666
return $message . ": No errors found.";
6767
}
6868

69-
$outputPath = getcwd() . DIRECTORY_SEPARATOR . $filename . ".txt";
70-
$fileResource = fopen($outputPath, 'w');
69+
$dirname = dirname($filePath);
70+
if (!file_exists($dirname)) {
71+
mkdir($dirname, 0777, true);
72+
}
73+
74+
$fileResource = fopen($filePath, 'w');
7175

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

7680
fclose($fileResource);
7781
$errorCount = count($errors);
78-
$output = $message . ": Errors found across {$errorCount} file(s). Error details output to {$outputPath}";
82+
$output = $message . ": Errors found across {$errorCount} file(s). Error details output to {$filePath}";
7983

8084
return $output;
8185
}

0 commit comments

Comments
 (0)