|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Paraunit\Tests\Unit\Parser; |
|
4
|
|
|
|
|
5
|
|
|
use Paraunit\Parser\ErrorParser; |
|
6
|
|
|
use Paraunit\Printer\OutputContainer; |
|
7
|
|
|
use Paraunit\Tests\BaseUnitTestCase; |
|
8
|
|
|
use Paraunit\Tests\Stub\PHPUnitOutput\JSONLogs\JSONLogStub; |
|
9
|
|
|
use Paraunit\Tests\Stub\StubbedParaProcess; |
|
10
|
|
|
use Paraunit\Tests\StubbedPHPUnitBaseTestCase; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class ErrorParserTest |
|
14
|
|
|
* @package Paraunit\Tests\Unit\Parser |
|
15
|
|
|
*/ |
|
16
|
|
|
class ErrorParserTest extends BaseUnitTestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @dataProvider logProvider |
|
20
|
|
|
*/ |
|
21
|
|
|
public function testParseAndContinue($jsonLogs, $expectedErrorCount) |
|
22
|
|
|
{ |
|
23
|
|
|
$outputContainer = new OutputContainer('tag', 'title'); |
|
24
|
|
|
$parser = new ErrorParser($outputContainer); |
|
25
|
|
|
$process = new StubbedParaProcess(); |
|
26
|
|
|
$logs = json_decode($jsonLogs); |
|
27
|
|
|
|
|
28
|
|
|
foreach ($logs as $singleLog) { |
|
29
|
|
|
if ($singleLog->event == 'test') { |
|
30
|
|
|
$parsingShouldContinue = $parser->parsingFoundResult($process, $singleLog); |
|
31
|
|
|
$this->assertSame($singleLog->status != 'error', $parsingShouldContinue); |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$this->assertEquals($expectedErrorCount, $parser->getOutputContainer()->countMessages()); |
|
36
|
|
|
$this->assertCount($expectedErrorCount, $process->getTestResults()); |
|
37
|
|
|
foreach ($process->getTestResults() as $testResult) { |
|
38
|
|
|
$this->assertEquals('E', $testResult); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function logProvider() |
|
43
|
|
|
{ |
|
44
|
|
|
return array( |
|
45
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::TWO_ERRORS_TWO_FAILURES), 2), |
|
46
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ALL_GREEN), 0), |
|
47
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::FATAL_ERROR), 0), |
|
48
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::SEGFAULT), 0), |
|
49
|
|
|
array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_ERROR), 1), |
|
50
|
|
|
// those will be intercepted before by other parsers |
|
|
|
|
|
|
51
|
|
|
// array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_INCOMPLETE), 0), |
|
52
|
|
|
// array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_RISKY), 1), |
|
53
|
|
|
// array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_SKIP), 1), |
|
54
|
|
|
// array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_WARNING), 1), |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.