Skip to content

Commit e56232d

Browse files
committed
MQE-2272: run:failed only runs last failed test when multiple tests are run with run:test
1 parent f6ccbb5 commit e56232d

File tree

3 files changed

+25
-49
lines changed

3 files changed

+25
-49
lines changed

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ class BaseGenerateCommand extends Command
5454
private $testsOutputDir = null;
5555

5656
/**
57-
* File handle for 'failed_all' file
57+
* String contains all 'failed' tests
5858
*
59-
* @var resource
59+
* @var string
6060
*/
61-
private $fhFailedAll;
61+
private $allFailed;
6262

6363
/**
6464
* Console output style
@@ -314,20 +314,7 @@ protected function getTestsOutputDir()
314314
}
315315

316316
/**
317-
* Initialize 'failed_all' file
318-
*
319-
* @return void
320-
* @throws TestFrameworkException
321-
*/
322-
protected function initializeFailedAllFile()
323-
{
324-
// Initialize 'failed_all' file
325-
$allFailedFile = $this->getTestsOutputDir() . self::FAILED_ALL_FILE;
326-
$this->fhFailedAll = fopen($allFailedFile, 'w+');
327-
}
328-
329-
/**
330-
* Appends content of file 'failed' to file 'failed_all'
317+
* Save 'failed' tests
331318
*
332319
* @return void
333320
*/
@@ -339,46 +326,41 @@ protected function appendRunFailed()
339326
}
340327

341328
if (file_exists($this->testsFailedFile)) {
342-
// Append 'failed' into 'failed_all'
329+
// Save 'failed' tests
343330
$contents = file_get_contents($this->testsFailedFile);
344331
if ($contents !== false && !empty($contents)) {
345-
fwrite($this->fhFailedAll, trim($contents) . PHP_EOL);
332+
$this->allFailed .= trim($contents) . PHP_EOL;
346333
}
347334
}
348335
} catch (TestFrameworkException $e) {
349336
}
350337
}
351338

352339
/**
353-
* Replace content of file 'failed' with content in file 'failed_all'
340+
* Apply 'allFailed' in 'failed' file
354341
*
355342
* @return void
356343
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
357344
*/
358-
protected function updateRunFailedWithFailedAll()
345+
protected function applyAllFailed()
359346
{
360347
try {
361348
if (!$this->testsFailedFile) {
362349
$this->testsFailedFile = $this->getTestsOutputDir() . self::FAILED_FILE;
363350
}
364351

365-
if (file_exists($this->getTestsOutputDir() . self::FAILED_ALL_FILE)) {
352+
if (!empty($this->allFailed)) {
366353
// Update 'failed' with content from 'failed_all'
367-
$contents = file_get_contents($this->getTestsOutputDir() . self::FAILED_ALL_FILE);
368-
if ($contents !== false && !empty($contents)) {
369-
if (file_exists($this->testsFailedFile)) {
370-
rename($this->testsFailedFile, $this->testsFailedFile . '.copy');
371-
}
372-
if (file_put_contents($this->testsFailedFile, $contents) === false
373-
&& file_exists($this->testsFailedFile . '.copy')) {
374-
rename($this->testsFailedFile . '.copy', $this->testsFailedFile);
375-
}
376-
if (file_exists($this->testsFailedFile . '.copy')) {
377-
unlink($this->testsFailedFile . '.copy');
378-
}
354+
if (file_exists($this->testsFailedFile)) {
355+
rename($this->testsFailedFile, $this->testsFailedFile . '.copy');
356+
}
357+
if (file_put_contents($this->testsFailedFile, $this->allFailed) === false
358+
&& file_exists($this->testsFailedFile . '.copy')) {
359+
rename($this->testsFailedFile . '.copy', $this->testsFailedFile);
360+
}
361+
if (file_exists($this->testsFailedFile . '.copy')) {
362+
unlink($this->testsFailedFile . '.copy');
379363
}
380-
fclose($this->fhFailedAll);
381-
unlink($this->getTestsOutputDir() . self::FAILED_ALL_FILE);
382364
}
383365
} catch (TestFrameworkException $e) {
384366
}

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
109109

110110
$testConfigArray = json_decode($testConfiguration, true);
111111

112-
// Initialize `failed_all` file
113-
$this->initializeFailedAllFile();
114-
115112
if (isset($testConfigArray['tests'])) {
116113
$this->runTests($testConfigArray['tests'], $output);
117114
}
@@ -120,8 +117,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
120117
$this->runTestsInSuite($testConfigArray['suites'], $output);
121118
}
122119

123-
// Update `failed` with contents from `failed_all`
124-
$this->updateRunFailedWithFailedAll();
120+
// Add all failed tests in 'failed' file
121+
$this->applyAllFailed();
125122

126123
return max($this->returnCode, $generationErrorCode);
127124
}
@@ -168,7 +165,7 @@ private function runTests(array $tests, OutputInterface $output)
168165
$this->returnCode = max($this->returnCode, $this->executeTestCommand($fullCommand, $output));
169166
}
170167

171-
// Append `failed` to `failed_all`
168+
// Save failed tests
172169
$this->appendRunFailed();
173170
}
174171
}
@@ -206,7 +203,7 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output)
206203
$this->returnCode = max($this->returnCode, $this->executeTestCommand($fullCommand, $output));
207204
}
208205

209-
// Append `failed` to `failed_all`
206+
// Save failed tests
210207
$this->appendRunFailed();
211208
}
212209
}

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
103103
}
104104
}
105105

106-
// Initialize `failed_all` file
107-
$this->initializeFailedAllFile();
108-
109106
if ($this->pauseEnabled()) {
110107
$commandString = self::CODECEPT_RUN_FUNCTIONAL . '--verbose --steps --debug';
111108
} else {
@@ -134,12 +131,12 @@ function ($type, $buffer) use ($output) {
134131
);
135132
}
136133

137-
// Append `failed` to `failed_all`
134+
// Save failed tests
138135
$this->appendRunFailed();
139136
}
140137

141-
// Update `failed` with contents from `failed_all`
142-
$this->updateRunFailedWithFailedAll();
138+
// Add all failed tests in 'failed' file
139+
$this->applyAllFailed();
143140

144141
foreach ($returnCodes as $returnCode) {
145142
if ($returnCode != 0) {

0 commit comments

Comments
 (0)