Skip to content

Commit 29dbf25

Browse files
authored
Merge pull request #787 from magento/MQE-2269
MQE-2269: Test manifest run stops at first failure encountered when E…
2 parents d9418db + 3f28521 commit 29dbf25

File tree

5 files changed

+43
-13
lines changed

5 files changed

+43
-13
lines changed

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class BaseGenerateCommand extends Command
3333
const MFTF_NOTICES = "Placeholder text for MFTF notices\n";
3434
const CODECEPT_RUN = 'codecept:run';
3535
const CODECEPT_RUN_FUNCTIONAL = self::CODECEPT_RUN . ' functional ';
36+
const CODECEPT_RUN_OPTION_NO_EXIT = ' --no-exit ';
3637

3738
/**
3839
* Enable pause()

src/Magento/FunctionalTestingFramework/Console/RunManifestCommand.php

+16-6
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8181
// Delete the Codeception failed file just in case it exists from any previous test runs
8282
$this->deleteFailedFile();
8383

84-
foreach ($manifestFile as $manifestLine) {
85-
if (empty($manifestLine)) {
84+
for ($line = 0; $line < count($manifestFile); $line++) {
85+
if (empty($manifestFile[$line])) {
8686
continue;
8787
}
8888

89-
$this->runManifestLine($manifestLine, $output);
89+
if ($line == count($manifestFile) - 1) {
90+
$this->runManifestLine($manifestFile[$line], $output, true);
91+
} else {
92+
$this->runManifestLine($manifestFile[$line], $output);
93+
}
94+
9095
$this->aggregateFailed();
9196
}
9297

@@ -103,18 +108,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int
103108
*
104109
* @param string $manifestLine
105110
* @param OutputInterface $output
111+
* @param boolean $exit
106112
* @return void
107113
* @throws \Exception
108114
*
109115
* @SuppressWarnings(PHPMD.UnusedLocalVariable) Need this because of the unused $type variable in the closure
110116
*/
111-
private function runManifestLine(string $manifestLine, OutputInterface $output)
117+
private function runManifestLine($manifestLine, $output, $exit = false)
112118
{
113119
if (getenv('ENABLE_PAUSE') === 'true') {
114120
$codeceptionCommand = BaseGenerateCommand::CODECEPT_RUN_FUNCTIONAL
115-
. '--verbose --steps --debug ' . $manifestLine;
121+
. '--verbose --steps --debug ';
122+
if (!$exit) {
123+
$codeceptionCommand .= BaseGenerateCommand::CODECEPT_RUN_OPTION_NO_EXIT;
124+
}
125+
$codeceptionCommand .= $manifestLine;
116126
$input = new StringInput($codeceptionCommand);
117-
$command = $this->getApplication()->find('codecept:run');
127+
$command = $this->getApplication()->find(BaseGenerateCommand::CODECEPT_RUN);
118128
$subReturnCode = $command->run($input, $output);
119129
} else {
120130
$codeceptionCommand = realpath(PROJECT_ROOT . "/vendor/bin/codecept")

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ private function runTests(array $tests, OutputInterface $output)
135135
TestGenerator::DEFAULT_DIR .
136136
DIRECTORY_SEPARATOR ;
137137

138-
foreach ($tests as $test) {
139-
$testName = $test . 'Cest.php';
138+
for ($i = 0; $i < count($tests); $i++) {
139+
$testName = $tests[$i] . 'Cest.php';
140140
if (!realpath($testsDirectory . $testName)) {
141141
throw new TestFrameworkException(
142142
$testName . " is not available under " . $testsDirectory
@@ -145,6 +145,9 @@ private function runTests(array $tests, OutputInterface $output)
145145

146146
if ($this->pauseEnabled()) {
147147
$fullCommand = $codeceptionCommand . $testsDirectory . $testName . ' --verbose --steps --debug';
148+
if ($i != count($tests) - 1) {
149+
$fullCommand .= self::CODECEPT_RUN_OPTION_NO_EXIT;
150+
}
148151
$this->returnCode = max($this->returnCode, $this->codeceptRunTest($fullCommand, $output));
149152
} else {
150153
$fullCommand = $codeceptionCommand . $testsDirectory . $testName . ' --verbose --steps';
@@ -169,10 +172,18 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output)
169172
$codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept')
170173
. ' run functional --verbose --steps ';
171174
}
175+
176+
$count = count($suitesConfig);
177+
$index = 0;
172178
//for tests in suites, run them as a group to run before and after block
173179
foreach (array_keys($suitesConfig) as $suite) {
174180
$fullCommand = $codeceptionCommand . " -g {$suite}";
181+
182+
$index += 1;
175183
if ($this->pauseEnabled()) {
184+
if ($index != $count) {
185+
$fullCommand .= self::CODECEPT_RUN_OPTION_NO_EXIT;
186+
}
176187
$this->returnCode = max($this->returnCode, $this->codeceptRunTest($fullCommand, $output));
177188
} else {
178189
$this->returnCode = max($this->returnCode, $this->executeTestCommand($fullCommand, $output));

src/Magento/FunctionalTestingFramework/Console/RunTestFailedCommand.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
116116

117117
$testManifestList = $this->readTestManifestFile();
118118
$returnCode = 0;
119-
foreach ($testManifestList as $testCommand) {
119+
for ($i = 0; $i < count($testManifestList); $i++) {
120120
if ($this->pauseEnabled()) {
121-
$codeceptionCommand = self::CODECEPT_RUN_FUNCTIONAL . $testCommand . ' --debug';
121+
$codeceptionCommand = self::CODECEPT_RUN_FUNCTIONAL . $testManifestList[$i] . ' --debug ';
122+
if ($i != count($testManifestList) - 1) {
123+
$codeceptionCommand .= self::CODECEPT_RUN_OPTION_NO_EXIT;
124+
}
122125
$returnCode = $this->codeceptRunTest($codeceptionCommand, $output);
123126
} else {
124127
$codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional ';
125-
$codeceptionCommand .= $testCommand;
128+
$codeceptionCommand .= $testManifestList[$i];
126129

127130
$process = new Process($codeceptionCommand);
128131
$process->setWorkingDirectory(TESTS_BP);
@@ -142,6 +145,7 @@ function ($type, $buffer) use ($output) {
142145
);
143146
}
144147
}
148+
145149
foreach ($this->failedList as $test) {
146150
$this->writeFailedTestToFile($test, $this->testsFailedFile);
147151
}

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ protected function configure()
5252
* @throws \Exception
5353
*
5454
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
55+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
5556
*/
5657
protected function execute(InputInterface $input, OutputInterface $output): int
5758
{
@@ -102,10 +103,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102103

103104
$exitCode = -1;
104105
$returnCodes = [];
105-
foreach ($groups as $group) {
106-
$codeceptionCommandString = $commandString . " -g {$group}";
106+
for ($i = 0; $i < count($groups); $i++) {
107+
$codeceptionCommandString = $commandString . ' -g ' . $groups[$i];
107108

108109
if ($this->pauseEnabled()) {
110+
if ($i != count($groups) - 1) {
111+
$codeceptionCommandString .= self::CODECEPT_RUN_OPTION_NO_EXIT;
112+
}
109113
$returnCodes[] = $this->codeceptRunTest($codeceptionCommandString, $output);
110114
} else {
111115
$process = new Process($codeceptionCommandString);

0 commit comments

Comments
 (0)