Skip to content

Commit 8b56bfe

Browse files
committed
MQE-1800: Allow generate:tests to continue running even if one test fails generation
1 parent 8ac5662 commit 8b56bfe

File tree

3 files changed

+116
-1
lines changed

3 files changed

+116
-1
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Util/GenerationErrorHandlerTest.php

+87
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,93 @@ public function testGetAllErrorsDuplicate()
242242
$this->assertEquals($expectedSuiteErrors, GenerationErrorHandler::getInstance()->getErrorsByType('suite'));
243243
}
244244

245+
/**
246+
* Test get all error messages
247+
*
248+
* @param string $expectedErrMessages
249+
* @param array $errors
250+
* @dataProvider getAllErrorMessagesDataProvider
251+
*/
252+
public function testGetAllErrorMessages($expectedErrMessages, $errors)
253+
{
254+
$handler = GenerationErrorHandler::getInstance();
255+
$handler->reset();
256+
257+
$property = new \ReflectionProperty(GenerationErrorHandler::class, 'errors');
258+
$property->setAccessible(true);
259+
$property->setValue($handler, $errors);
260+
261+
// Assert getAllErrorMessages
262+
$this->assertEquals($expectedErrMessages, GenerationErrorHandler::getInstance()->getAllErrorMessages());
263+
}
264+
265+
/**
266+
* Data provider for testGetAllErrorMessages()
267+
*
268+
* @return array
269+
*/
270+
public function getAllErrorMessagesDataProvider()
271+
{
272+
return [
273+
['', []],
274+
['', [
275+
'test' => [],
276+
'suite' => [],
277+
]
278+
],
279+
['TestError1'
280+
. PHP_EOL
281+
. 'TestError2'
282+
. PHP_EOL
283+
. 'TestError3'
284+
. PHP_EOL
285+
. 'SuiteError1'
286+
. PHP_EOL
287+
. 'SuiteError2'
288+
. PHP_EOL
289+
. 'SuiteError3'
290+
. PHP_EOL
291+
. 'SuiteError4',
292+
[
293+
'test' => [
294+
'Sameple1Test' => [
295+
'message' => [
296+
0 => 'TestError1',
297+
1 => 'TestError2'
298+
],
299+
'generated' => [
300+
0 => false,
301+
1 => false
302+
],
303+
],
304+
'Sameple2Test' => [
305+
'message' => 'TestError3',
306+
'generated' => true,
307+
],
308+
],
309+
'suite' => [
310+
'Sameple1Suite' => [
311+
'message' => 'SuiteError1',
312+
'generated' => true,
313+
],
314+
'Sameple2Suite' => [
315+
'message' => [
316+
0 => 'SuiteError2',
317+
1 => 'SuiteError3',
318+
2 => 'SuiteError4',
319+
],
320+
'generated' => [
321+
0 => false,
322+
1 => true,
323+
2 => false,
324+
],
325+
],
326+
],
327+
]
328+
],
329+
];
330+
}
331+
245332
/**
246333
* Test reset
247334
*/

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
140140
// $testConfiguration['tests'] cannot be empty if $tests is not empty
141141
TestGenerator::getInstance(null, $testConfiguration['tests'])->createAllTestFiles($testManifest);
142142
} elseif (empty($testConfiguration['suites'])) {
143-
throw new FastFailException('Invalid input');
143+
throw new FastFailException(
144+
!empty(GenerationErrorHandler::getInstance()->getAllErrors())
145+
?
146+
GenerationErrorHandler::getInstance()->getAllErrorMessages()
147+
:
148+
'Invalid input'
149+
);
144150
}
145151
} catch (FastFailException $e) {
146152
throw $e;

src/Magento/FunctionalTestingFramework/Util/GenerationErrorHandler.php

+22
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ public function getAllErrors()
7878
return $this->errors;
7979
}
8080

81+
/**
82+
* Return all error message in a string
83+
*
84+
* @return string
85+
*/
86+
public function getAllErrorMessages()
87+
{
88+
$errMessages = '';
89+
90+
foreach ($this->errors as $type => $errors) {
91+
foreach ($errors as $error) {
92+
if (is_array($error['message'])) {
93+
$errMessages .= (!empty($errMessages) ? PHP_EOL : '') . implode(PHP_EOL, $error['message']);
94+
} else {
95+
$errMessages .= (!empty($errMessages) ? PHP_EOL : '') . $error['message'];
96+
}
97+
}
98+
}
99+
100+
return $errMessages;
101+
}
102+
81103
/**
82104
* Return errors for given type
83105
*

0 commit comments

Comments
 (0)