Test Failed
Pull Request — master (#132)
by Alessandro
03:15
created

testHandleLogItemCatchesEndingIfGraceful()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Tests\Unit\Parser\JSON;
6
7
use Paraunit\Parser\JSON\LogFetcher;
8
use Paraunit\Parser\JSON\TestStartParser;
9
use Paraunit\TestResult\Interfaces\TestResultInterface;
10
use Tests\BaseUnitTestCase;
11
use Tests\Stub\StubbedParaunitProcess;
12
13
/**
14
 * Class TestStartParserTest
15
 * @package Tests\Unit\Parser\JSON
16
 */
17
class TestStartParserTest extends BaseUnitTestCase
18
{
19
    /**
20
     * @dataProvider logsProvider
21
     */
22
    public function testHandleLogItem(string $event, bool $chainInterrupted, bool $processExpectsTestResult = false)
23
    {
24
        $process = new StubbedParaunitProcess();
25
        $process->setWaitingForTestResult(true);
26
        $parser = new TestStartParser();
27
        $log = new \stdClass();
28
        $log->event = $event;
29
        $log->test = 'testFunction';
30
31
        $return = $parser->handleLogItem($process, $log);
32
33
        if ($chainInterrupted) {
34
            $this->assertInstanceOf(TestResultInterface::class, $return);
35
        } else {
36
            $this->assertNull($return);
37
        }
38
39
        if ($processExpectsTestResult) {
40
            $this->assertTrue($process->isWaitingForTestResult());
41
        }
42
    }
43
44
    public function logsProvider(): array
45
    {
46
        return [
47
            ['testStart', true, true],
48
            ['suiteStart', true, true],
49
            ['test', false, false],
50
            ['aaaa', false, false],
51
        ];
52
    }
53
54 View Code Duplication
    public function testHandleLogItemCatchesEndingIfGraceful()
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...
55
    {
56
        $process = new StubbedParaunitProcess();
57
        $process->setWaitingForTestResult(false);
58
        $parser = new TestStartParser();
59
        $log = new \stdClass();
60
        $log->status = LogFetcher::LOG_ENDING_STATUS;
61
62
        $return = $parser->handleLogItem($process, $log);
63
64
        $this->assertInstanceOf(TestResultInterface::class, $return);
65
    }
66
67 View Code Duplication
    public function testHandleLogItemAppendsNoCulpableFunctionForMissingLog()
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...
68
    {
69
        $process = new StubbedParaunitProcess();
70
        $process->setWaitingForTestResult(true);
71
        $parser = new TestStartParser();
72
        $log = new \stdClass();
73
        $log->status = LogFetcher::LOG_ENDING_STATUS;
74
75
        $return = $parser->handleLogItem($process, $log);
76
77
        $this->assertNull($return);
78
        $this->assertEquals('UNKNOWN -- log not found', $log->test);
79
    }
80
81 View Code Duplication
    public function testHandleLogItemAppendsCulpableFunction()
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...
82
    {
83
        $process = new StubbedParaunitProcess();
84
        $process->setWaitingForTestResult(true);
85
        $parser = new TestStartParser();
86
        $log = new \stdClass();
87
        $log->event = 'testStart';
88
        $log->test = 'testFunction';
89
90
        $parser->handleLogItem($process, $log);
91
92
        $log->status = LogFetcher::LOG_ENDING_STATUS;
93
94
        $return = $parser->handleLogItem($process, $log);
95
96
        $this->assertNull($return, 'Parsing should not be interrupted');
97
        $this->assertEquals('testFunction', $log->test);
98
    }
99
100 View Code Duplication
    public function testHandleLogItemAppendsCulpableFunctionToRightProcess()
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...
101
    {
102
        $parser = new TestStartParser();
103
        $log = new \stdClass();
104
        $log->event = 'testStart';
105
        $log->test = 'testFunction';
106
107
        $parser->handleLogItem(new StubbedParaunitProcess(), $log);
108
109
        $log = new \stdClass();
110
        $log->status = LogFetcher::LOG_ENDING_STATUS;
111
        $process = new StubbedParaunitProcess();
112
        $process->setWaitingForTestResult(true);
113
114
        $return = $parser->handleLogItem($process, $log);
115
116
        $this->assertNull($return, 'Parsing should not be interrupted');
117
        $this->assertEquals('UNKNOWN -- log not found', $log->test);
118
    }
119
}
120