|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Paraunit\Tests\Unit\Parser; |
|
4
|
|
|
|
|
5
|
|
|
use Paraunit\Exception\JSONLogNotFoundException; |
|
6
|
|
|
use Paraunit\Parser\JSONLogParser; |
|
7
|
|
|
use Paraunit\Printer\OutputContainer; |
|
8
|
|
|
use Paraunit\Tests\Stub\StubbedParaProcess; |
|
9
|
|
|
use Prophecy\Argument; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class JSONLogParserTest |
|
13
|
|
|
* @package Paraunit\Tests\Unit\Parser |
|
14
|
|
|
*/ |
|
15
|
|
|
class JSONLogParserTest extends \PHPUnit_Framework_TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
public function testParseHandlesMissingLogs() |
|
18
|
|
|
{ |
|
19
|
|
|
$process = new StubbedParaProcess(); |
|
20
|
|
|
$process->setOutput('Test output (core dumped)'); |
|
21
|
|
|
$logLocator = $this->prophesize('Paraunit\Parser\JSONLogFetcher'); |
|
22
|
|
|
$logLocator->fetch($process)->willThrow(new JSONLogNotFoundException($process)); |
|
23
|
|
|
|
|
24
|
|
|
$parser = new JSONLogParser($logLocator->reveal(), new OutputContainer('', '')); |
|
25
|
|
|
|
|
26
|
|
|
$parser->parse($process); |
|
27
|
|
|
|
|
28
|
|
|
$this->assertTrue($process->hasAbnormalTermination()); |
|
29
|
|
|
$this->assertEquals('Unknown function -- test log not found', $process->getAbnormalTerminatedFunction()); |
|
30
|
|
|
$outputContainer = $parser->getAbnormalTerminatedOutputContainer(); |
|
31
|
|
|
$this->assertContains($process->getFilename(), $outputContainer->getFileNames()); |
|
32
|
|
|
$buffer = $outputContainer->getOutputBuffer(); // PHP 5.3 workaround to direct call |
|
33
|
|
|
$this->assertContains($process->getOutput(), $buffer[$process->getFilename()]); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testParseHandlesTruncatedLogs() |
|
37
|
|
|
{ |
|
38
|
|
|
$process = new StubbedParaProcess(); |
|
39
|
|
|
$process->setOutput('Test output (core dumped)'); |
|
40
|
|
|
$logLocator = $this->prophesize('Paraunit\Parser\JSONLogFetcher'); |
|
41
|
|
|
$log1 = new \stdClass(); |
|
42
|
|
|
$log1->event = 'testStart'; |
|
43
|
|
|
$log1->test = 'testSomething'; |
|
44
|
|
|
$logLocator->fetch($process)->willReturn(array($log1)); |
|
45
|
|
|
|
|
46
|
|
|
$parser = new JSONLogParser($logLocator->reveal(), new OutputContainer('', '')); |
|
47
|
|
|
|
|
48
|
|
|
$parser->parse($process); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertTrue($process->hasAbnormalTermination()); |
|
51
|
|
|
$this->assertEquals('testSomething', $process->getAbnormalTerminatedFunction()); |
|
52
|
|
|
$outputContainer = $parser->getAbnormalTerminatedOutputContainer(); |
|
53
|
|
|
$this->assertContains($process->getFilename(), $outputContainer->getFileNames()); |
|
54
|
|
|
$buffer = $outputContainer->getOutputBuffer(); // PHP 5.3 workaround to direct call |
|
55
|
|
|
$this->assertContains($process->getOutput(), $buffer[$process->getFilename()]); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|