Completed
Push — output_parsers_refactor ( 9ffc6c...755930 )
by Alessandro
09:57
created

RetryParserTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 11
c 2
b 0
f 0
lcom 1
cbo 4
dl 0
loc 91
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testParseAndSetRetry() 0 10 1
A testParseAndContinueWithNoRetry() 0 13 3
A testParseAndContinueWithNoRetryAfterLimit() 0 13 1
A toBeRetriedTestsProvider() 0 9 1
A notToBeRetriedTestLogsProvider() 0 14 1
A getLogWithError() 0 14 4
1
<?php
2
3
namespace Paraunit\Tests\Unit\Parser;
4
5
use Paraunit\Parser\RetryParser;
6
use Paraunit\Tests\BaseUnitTestCase;
7
use Paraunit\Tests\Stub\EntityManagerClosedTestStub;
8
use Paraunit\Tests\Stub\MySQLDeadLockTestStub;
9
use Paraunit\Tests\Stub\MySQLLockTimeoutTestStub;
10
use Paraunit\Tests\Stub\PHPUnitOutput\JSONLogs\JSONLogStub;
11
use Paraunit\Tests\Stub\SQLiteDeadLockTestStub;
12
use Paraunit\Tests\Stub\StubbedParaProcess;
13
use Paraunit\Tests\StubbedPHPUnitBaseTestCase;
14
15
/**
16
 * Class RetryParserTest
17
 * @package Paraunit\Tests\Unit
18
 */
19
class RetryParserTest extends BaseUnitTestCase
20
{
21
    /**
22
     * @dataProvider toBeRetriedTestsProvider
23
     */
24
    public function testParseAndSetRetry($testOutput)
25
    {
26
        $log = $this->getLogWithError($testOutput);
27
        
28
        $process = new StubbedParaProcess();
29
        $parser = new RetryParser();
30
31
        $this->assertTrue($parser->parsingFoundResult($process, $log), 'Parsing shouldn\'t continue!');
32
        $this->assertTrue($process->isToBeRetried(), 'Test should be marked as to be retried!');
33
    }
34
35
    /**
36
     * @dataProvider notToBeRetriedTestLogsProvider
37
     */
38
    public function testParseAndContinueWithNoRetry($jsonLogs)
39
    {
40
        $process = new StubbedParaProcess();
41
        $parser = new RetryParser();
42
43
        $logs = json_decode($jsonLogs);
44
        foreach ($logs as $singlelog) {
45
            if ($singlelog->event == 'test') {
46
                $this->assertFalse($parser->parsingFoundResult($process, $singlelog), 'Parsing should continue!');
47
                $this->assertFalse($process->isToBeRetried(), 'Test shouldn\'t be retried!');
48
            }
49
        }
50
    }
51
52
    public function testParseAndContinueWithNoRetryAfterLimit()
53
    {
54
        $process = new StubbedParaProcess();
55
        $log = $this->getLogWithError(EntityManagerClosedTestStub::OUTPUT);
56
        $process->increaseRetryCount();
57
58
        $this->assertEquals(1, $process->getRetryCount());
59
60
        $parser = new RetryParser(0);
61
62
        $this->assertFalse($parser->parsingFoundResult($process, $log), 'Parsing should continue!');
63
        $this->assertFalse($process->isToBeRetried(), 'Test shouldn\'t retry no more!');
64
    }
65
66
    public function toBeRetriedTestsProvider()
67
    {
68
        return array(
69
            array(EntityManagerClosedTestStub::OUTPUT),
70
            array(MySQLDeadLockTestStub::OUTPUT),
71
            array(MySQLLockTimeoutTestStub::OUTPUT),
72
            array(SQLiteDeadLockTestStub::OUTPUT),
73
        );
74
    }
75
76
    public function notToBeRetriedTestLogsProvider()
77
    {
78
        return array(
79
            array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::TWO_ERRORS_TWO_FAILURES)),
80
            array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ALL_GREEN)),
81
            array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::FATAL_ERROR)),
82
            array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::SEGFAULT)),
83
            array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_ERROR)),
84
            array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_INCOMPLETE)),
85
            array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_RISKY)),
86
            array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_SKIP)),
87
            array(JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_WARNING)),
88
        );
89
    }
90
91
    /**
92
     * @param $testOutput
93
     * @return \stdClass
94
     */
95
    private function getLogWithError($testOutput)
96
    {
97
        $jsonLogs = JSONLogStub::getCleanOutputFileContent(JSONLogStub::ONE_ERROR);
98
        $logs = json_decode($jsonLogs);
99
        foreach ($logs as $log) {
100
            if ($log->event == 'test' && $log->status == 'error') {
101
                $log->message = $testOutput;
102
103
                return $log;
104
            }
105
        }
106
107
        $this->fail('Feasible log message not found for test');
108
    }
109
}
110