|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Paraunit\Tests\Unit\Parser; |
|
4
|
|
|
|
|
5
|
|
|
use Paraunit\Exception\JSONLogNotFoundException; |
|
6
|
|
|
use Paraunit\Parser\JSONLogParser; |
|
7
|
|
|
use Paraunit\Tests\Stub\PHPUnitOutput\JSONLogs\JSONLogStub; |
|
8
|
|
|
use Paraunit\Tests\Stub\StubbedParaProcess; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class JSONLogParserTest |
|
12
|
|
|
* @package Paraunit\Tests\Unit\Parser |
|
13
|
|
|
*/ |
|
14
|
|
|
class JSONLogParserTest extends \PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @dataProvider parsableResultsProvider |
|
18
|
|
|
*/ |
|
19
|
|
View Code Duplication |
public function testParseAndContinue($log, $expectedResult) |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
$process = new StubbedParaProcess(); |
|
22
|
|
|
$logLocator = $this->prophesize('Paraunit\Parser\JSONLogFetcher'); |
|
23
|
|
|
$logLocator->fetch($process)->willReturn(JSONLogStub::cleanLog($log)); |
|
24
|
|
|
|
|
25
|
|
|
$parser = new JSONLogParser($logLocator->reveal()); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertFalse($parser->parseAndContinue($process)); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertEquals($expectedResult, $process->getTestResults()); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function parsableResultsProvider() |
|
33
|
|
|
{ |
|
34
|
|
|
return array( |
|
35
|
|
|
array(JSONLogStub::get2Errors2Failures(), str_split('FF..E...E')), |
|
36
|
|
|
array(JSONLogStub::getAllGreen(), str_split('.........')), |
|
37
|
|
|
array(JSONLogStub::getFatalError(), str_split('...')), |
|
38
|
|
|
array(JSONLogStub::getSegFault(), str_split('...')), |
|
39
|
|
|
array(JSONLogStub::getSingleError(), str_split('.E.')), |
|
40
|
|
|
array(JSONLogStub::getSingleIncomplete(), str_split('..I.')), |
|
41
|
|
|
array(JSONLogStub::getSingleRisky(), str_split('..R.')), |
|
42
|
|
|
array(JSONLogStub::getSingleSkip(), str_split('..S.')), |
|
43
|
|
|
array(JSONLogStub::getSingleWarning(), str_split('...W')), |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
View Code Duplication |
public function testLogNotFound() |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
$process = new StubbedParaProcess(); |
|
50
|
|
|
$logLocator = $this->prophesize('Paraunit\Parser\JSONLogFetcher'); |
|
51
|
|
|
$logLocator->fetch($process)->willThrow(new JSONLogNotFoundException($process)); |
|
52
|
|
|
|
|
53
|
|
|
$parser = new JSONLogParser($logLocator->reveal()); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertTrue($parser->parseAndContinue($process)); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertEmpty($process->getTestResults()); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.