Skip to content

Commit 6f2affb

Browse files
committed
MQE-2135: MFTF static check output directory should not depend on current working directory
1 parent 545a266 commit 6f2affb

File tree

6 files changed

+38
-9
lines changed

6 files changed

+38
-9
lines changed

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
@@ -82,7 +82,7 @@ public function execute(InputInterface $input)
8282
$scriptUtil = new ScriptUtil();
8383
$this->output = $scriptUtil->printErrorsToFile(
8484
$this->errors,
85-
self::ERROR_LOG_FILENAME,
85+
StaticChecksList::getErrorFilesPath() . DIRECTORY_SEPARATOR . self::ERROR_LOG_FILENAME . '.txt',
8686
self::ERROR_LOG_MESSAGE
8787
);
8888
}

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)