Completed
Push — output_parsers_refactor ( 710907...9ffc6c )
by Alessandro
02:42
created

JSONLogParserTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 52.17 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 6
dl 24
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testParseAndContinue() 12 12 1
A parsableResultsProvider() 0 14 1
A testLogNotFound() 12 12 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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