1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Tests\Functional\Parser\JSON; |
6
|
|
|
|
7
|
|
|
use Paraunit\Lifecycle\ProcessEvent; |
8
|
|
|
use Paraunit\Parser\JSON\LogParser; |
9
|
|
|
use Paraunit\TestResult\Interfaces\PrintableTestResultInterface; |
10
|
|
|
use Paraunit\TestResult\TestResultWithSymbolFormat; |
11
|
|
|
use Tests\BaseFunctionalTestCase; |
12
|
|
|
use Tests\Stub\PHPUnitJSONLogOutput\JSONLogStub; |
13
|
|
|
use Tests\Stub\StubbedParaunitProcess; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class LogParserTest |
17
|
|
|
* @package Tests\Functional\Parser |
18
|
|
|
*/ |
19
|
|
|
class LogParserTest extends BaseFunctionalTestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @dataProvider parsableResultsProvider |
23
|
|
|
*/ |
24
|
|
|
public function testParse(string $stubLog, string $expectedResult, bool $hasAbnormalTermination = false) |
25
|
|
|
{ |
26
|
|
|
$process = new StubbedParaunitProcess(); |
27
|
|
|
$this->createLogForProcessFromStubbedLog($process, $stubLog); |
28
|
|
|
|
29
|
|
|
/** @var LogParser $parser */ |
30
|
|
|
$parser = $this->getService(LogParser::class); |
31
|
|
|
|
32
|
|
|
$parser->onProcessTerminated(new ProcessEvent($process)); |
33
|
|
|
|
34
|
|
|
$results = $process->getTestResults(); |
35
|
|
|
$this->assertContainsOnlyInstancesOf(PrintableTestResultInterface::class, $results); |
36
|
|
|
$textResults = ''; |
37
|
|
|
/** @var PrintableTestResultInterface $singleResult */ |
38
|
|
|
foreach ($results as $singleResult) { |
39
|
|
|
/** @var TestResultWithSymbolFormat $formatWithSymbol */ |
40
|
|
|
$formatWithSymbol = $singleResult->getTestResultFormat(); |
41
|
|
|
$this->assertInstanceOf(TestResultWithSymbolFormat::class, $formatWithSymbol); |
42
|
|
|
$textResults .= $formatWithSymbol->getTestResultSymbol(); |
43
|
|
|
} |
44
|
|
|
$this->assertEquals($expectedResult, $textResults); |
45
|
|
|
|
46
|
|
|
$this->assertEquals($hasAbnormalTermination, $process->hasAbnormalTermination()); |
47
|
|
|
|
48
|
|
|
if ($process->getTestClassName()) { |
49
|
|
|
$this->assertStringStartsWith('Paraunit\Tests\Stub\\', $process->getTestClassName()); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return (bool|string)[][] |
55
|
|
|
*/ |
56
|
|
|
public function parsableResultsProvider(): array |
57
|
|
|
{ |
58
|
|
|
return [ |
59
|
|
|
[JSONLogStub::TWO_ERRORS_TWO_FAILURES, 'FF..E...E'], |
60
|
|
|
[JSONLogStub::ALL_GREEN, '.........'], |
61
|
|
|
[JSONLogStub::ONE_ERROR, '.E.'], |
62
|
|
|
[JSONLogStub::ONE_INCOMPLETE, '..I.'], |
63
|
|
|
[JSONLogStub::ONE_RISKY, '..R.'], |
64
|
|
|
[JSONLogStub::ONE_SKIP, '..S.'], |
65
|
|
|
[JSONLogStub::ONE_WARNING, '...W'], |
66
|
|
|
[JSONLogStub::FATAL_ERROR, '...X', true], |
67
|
|
|
[JSONLogStub::SEGFAULT, '...X', true], |
68
|
|
|
[JSONLogStub::PARSE_ERROR, '...................................................X', true], |
69
|
|
|
[JSONLogStub::UNKNOWN, '?', false], |
70
|
|
|
]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testParseHandlesMissingLogsAsAbnormalTerminations() |
74
|
|
|
{ |
75
|
|
|
/** @var LogParser $parser */ |
76
|
|
|
$parser = $this->getService(LogParser::class); |
77
|
|
|
$process = new StubbedParaunitProcess(); |
78
|
|
|
$process->setExitCode(139); |
79
|
|
|
|
80
|
|
|
$parser->onProcessTerminated(new ProcessEvent($process)); |
81
|
|
|
|
82
|
|
|
$results = $process->getTestResults(); |
83
|
|
|
$this->assertContainsOnlyInstancesOf(PrintableTestResultInterface::class, $results); |
84
|
|
|
$this->assertCount(1, $results); |
|
|
|
|
85
|
|
|
|
86
|
|
|
/** @var TestResultWithSymbolFormat $formatWithSymbol */ |
87
|
|
|
$formatWithSymbol = $results[0]->getTestResultFormat(); |
88
|
|
|
$this->assertInstanceOf(TestResultWithSymbolFormat::class, $formatWithSymbol); |
89
|
|
|
$this->assertEquals('X', $formatWithSymbol->getTestResultSymbol()); |
90
|
|
|
$this->assertTrue($process->hasAbnormalTermination()); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: