Skip to content

Commit ff1a22e

Browse files
committed
MQE-1260: Create RERUN_COUNT field in Jenkins MFTF Parameters section same as MTF parameters section
- Updated to prevent write correct tests to file after a rerun with multiple failures
1 parent d24d74c commit ff1a22e

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class RunTestFailedCommand extends BaseGenerateCommand
3636
DIRECTORY_SEPARATOR .
3737
"testManifest.txt";
3838

39+
/**
40+
* @var array
41+
*/
42+
private $failedList = [];
43+
3944
/**
4045
* Configures the current command.
4146
*
@@ -83,8 +88,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
8388

8489
$testManifestList = $this->readTestManifestFile();
8590

86-
foreach ($testManifestList as $testCommand)
87-
{
91+
foreach ($testManifestList as $testCommand) {
8892
$codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional ';
8993
$codeceptionCommand .= $testCommand;
9094

@@ -97,6 +101,13 @@ function ($type, $buffer) use ($output) {
97101
$output->write($buffer);
98102
}
99103
);
104+
$this->failedList = array_merge(
105+
$this->failedList,
106+
$this->readFailedTestFile(self::TESTS_FAILED_FILE)
107+
);
108+
}
109+
foreach ($this->failedList as $test) {
110+
$this->writeFailedTestToFile($test, self::TESTS_FAILED_FILE);
100111
}
101112
}
102113

@@ -107,21 +118,13 @@ function ($type, $buffer) use ($output) {
107118
*/
108119
private function getFailedTestList()
109120
{
110-
$failedTestPath = TESTS_BP .
111-
DIRECTORY_SEPARATOR .
112-
"tests" .
113-
DIRECTORY_SEPARATOR .
114-
"_output" .
115-
DIRECTORY_SEPARATOR .
116-
"failed";
117-
118121
$failedTestDetails = ['tests' => [], 'suites' => []];
119122

120-
if (realpath($failedTestPath)) {
121-
$testList = $this->readFailedTestFile($failedTestPath);
123+
if (realpath(self::TESTS_FAILED_FILE)) {
124+
$testList = $this->readFailedTestFile(self::TESTS_FAILED_FILE);
122125

123126
foreach ($testList as $test) {
124-
$this->writeFailedTestToFile($test);
127+
$this->writeFailedTestToFile($test, self::TESTS_RERUN_FILE);
125128
$testInfo = explode(DIRECTORY_SEPARATOR, $test);
126129
$testName = explode(":", $testInfo[count($testInfo) - 1])[1];
127130
$suiteName = $testInfo[count($testInfo) - 2];
@@ -150,9 +153,8 @@ private function getFailedTestList()
150153
}
151154

152155
/**
153-
* Returns an array of tests read from the failed test file in _output
156+
* Returns an array of run commands read from the manifest file created post generation
154157
*
155-
* @param string $filePath
156158
* @return array|boolean
157159
*/
158160
private function readTestManifestFile()
@@ -177,14 +179,14 @@ private function readFailedTestFile($filePath)
177179
* @param string $test
178180
* @return void
179181
*/
180-
private function writeFailedTestToFile($test)
182+
private function writeFailedTestToFile($test, $filePath)
181183
{
182-
if (realpath(self::TESTS_RERUN_FILE)) {
183-
if (strpos(file_get_contents(self::TESTS_RERUN_FILE), $test) == false) {
184-
file_put_contents(self::TESTS_RERUN_FILE, $test . "\n", FILE_APPEND);
184+
if (realpath($filePath)) {
185+
if (strpos(file_get_contents($filePath), $test) === false) {
186+
file_put_contents($filePath, "\n" . $test, FILE_APPEND);
185187
}
186188
} else {
187-
file_put_contents(self::TESTS_RERUN_FILE, $test . "\n");
189+
file_put_contents($filePath, $test . "\n");
188190
}
189191
}
190192
}

0 commit comments

Comments
 (0)