Skip to content

Commit 72a0ebe

Browse files
authored
Merge pull request #4 from magento-commerce/MQE-2272
MQE-2272: run:failed only runs last failed test when multiple tests a…
2 parents 9da15a8 + fe8bd59 commit 72a0ebe

File tree

4 files changed

+111
-13
lines changed

4 files changed

+111
-13
lines changed

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

+94
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class BaseGenerateCommand extends Command
3636
const CODECEPT_RUN = 'codecept:run';
3737
const CODECEPT_RUN_FUNCTIONAL = self::CODECEPT_RUN . ' functional ';
3838
const CODECEPT_RUN_OPTION_NO_EXIT = ' --no-exit ';
39+
const FAILED_FILE = 'failed';
3940

4041
/**
4142
* Enable pause()
@@ -44,13 +45,34 @@ class BaseGenerateCommand extends Command
4445
*/
4546
private $enablePause = null;
4647

48+
/**
49+
* Full path to '_output' dir
50+
*
51+
* @var string
52+
*/
53+
private $testsOutputDir = null;
54+
55+
/**
56+
* String contains all 'failed' tests
57+
*
58+
* @var string
59+
*/
60+
private $allFailed;
61+
4762
/**
4863
* Console output style
4964
*
5065
* @var SymfonyStyle
5166
*/
5267
protected $ioStyle = null;
5368

69+
/**
70+
* Full path to 'failed' file
71+
*
72+
* @var string
73+
*/
74+
protected $testsFailedFile = null;
75+
5476
/**
5577
* Configures the base command.
5678
*
@@ -270,4 +292,76 @@ protected function codeceptRunTest(string $commandStr, OutputInterface $output)
270292
$command = $this->getApplication()->find(self::CODECEPT_RUN);
271293
return $command->run($input, $output);
272294
}
295+
296+
/**
297+
* Return tests _output directory
298+
*
299+
* @return string
300+
* @throws TestFrameworkException
301+
*/
302+
protected function getTestsOutputDir()
303+
{
304+
if (!$this->testsOutputDir) {
305+
$this->testsOutputDir = FilePathFormatter::format(TESTS_BP) .
306+
"tests" .
307+
DIRECTORY_SEPARATOR .
308+
"_output" .
309+
DIRECTORY_SEPARATOR;
310+
}
311+
312+
return $this->testsOutputDir;
313+
}
314+
315+
/**
316+
* Save 'failed' tests
317+
*
318+
* @return void
319+
*/
320+
protected function appendRunFailed()
321+
{
322+
try {
323+
if (!$this->testsFailedFile) {
324+
$this->testsFailedFile = $this->getTestsOutputDir() . self::FAILED_FILE;
325+
}
326+
327+
if (file_exists($this->testsFailedFile)) {
328+
// Save 'failed' tests
329+
$contents = file_get_contents($this->testsFailedFile);
330+
if ($contents !== false && !empty($contents)) {
331+
$this->allFailed .= trim($contents) . PHP_EOL;
332+
}
333+
}
334+
} catch (TestFrameworkException $e) {
335+
}
336+
}
337+
338+
/**
339+
* Apply 'allFailed' in 'failed' file
340+
*
341+
* @return void
342+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
343+
*/
344+
protected function applyAllFailed()
345+
{
346+
try {
347+
if (!$this->testsFailedFile) {
348+
$this->testsFailedFile = $this->getTestsOutputDir() . self::FAILED_FILE;
349+
}
350+
351+
if (!empty($this->allFailed)) {
352+
// Update 'failed' with content from 'allFailed'
353+
if (file_exists($this->testsFailedFile)) {
354+
rename($this->testsFailedFile, $this->testsFailedFile . '.copy');
355+
}
356+
if (file_put_contents($this->testsFailedFile, $this->allFailed) === false
357+
&& file_exists($this->testsFailedFile . '.copy')) {
358+
rename($this->testsFailedFile . '.copy', $this->testsFailedFile);
359+
}
360+
if (file_exists($this->testsFailedFile . '.copy')) {
361+
unlink($this->testsFailedFile . '.copy');
362+
}
363+
}
364+
} catch (TestFrameworkException $e) {
365+
}
366+
}
273367
}

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

+9
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
117117
$this->runTestsInSuite($testConfigArray['suites'], $output);
118118
}
119119

120+
// Add all failed tests in 'failed' file
121+
$this->applyAllFailed();
122+
120123
return max($this->returnCode, $generationErrorCode);
121124
}
122125

@@ -161,6 +164,9 @@ private function runTests(array $tests, OutputInterface $output)
161164
$fullCommand = $codeceptionCommand . $testsDirectory . $testName . ' --verbose --steps';
162165
$this->returnCode = max($this->returnCode, $this->executeTestCommand($fullCommand, $output));
163166
}
167+
168+
// Save failed tests
169+
$this->appendRunFailed();
164170
}
165171
}
166172

@@ -196,6 +202,9 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output)
196202
} else {
197203
$this->returnCode = max($this->returnCode, $this->executeTestCommand($fullCommand, $output));
198204
}
205+
206+
// Save failed tests
207+
$this->appendRunFailed();
199208
}
200209
}
201210

src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php

+2-13
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ class RunTestFailedCommand extends BaseGenerateCommand
2323
*/
2424
const DEFAULT_TEST_GROUP = 'default';
2525

26-
/**
27-
* @var string
28-
*/
29-
private $testsFailedFile;
30-
3126
/**
3227
* @var string
3328
*/
@@ -69,14 +64,8 @@ protected function configure()
6964
*/
7065
protected function execute(InputInterface $input, OutputInterface $output): int
7166
{
72-
$testsOutputDir = FilePathFormatter::format(TESTS_BP) .
73-
"tests" .
74-
DIRECTORY_SEPARATOR .
75-
"_output" .
76-
DIRECTORY_SEPARATOR;
77-
78-
$this->testsFailedFile = $testsOutputDir . "failed";
79-
$this->testsReRunFile = $testsOutputDir . "rerun_tests";
67+
$this->testsFailedFile = $this->getTestsOutputDir() . self::FAILED_FILE;
68+
$this->testsReRunFile = $this->getTestsOutputDir() . "rerun_tests";
8069
$this->testsManifestFile= FilePathFormatter::format(TESTS_MODULE_PATH) .
8170
"_generated" .
8271
DIRECTORY_SEPARATOR .

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

+6
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,14 @@ function ($type, $buffer) use ($output) {
130130
}
131131
);
132132
}
133+
134+
// Save failed tests
135+
$this->appendRunFailed();
133136
}
134137

138+
// Add all failed tests in 'failed' file
139+
$this->applyAllFailed();
140+
135141
foreach ($returnCodes as $returnCode) {
136142
if ($returnCode != 0) {
137143
return $returnCode;

0 commit comments

Comments
 (0)