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

RunnerTest::testWarning()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 34
Code Lines 21

Duplication

Lines 34
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 34
loc 34
rs 8.8571
cc 2
eloc 21
nc 2
nop 0
1
<?php
2
3
namespace Paraunit\Tests\Functional\Runner;
4
5
use Paraunit\Configuration\Paraunit;
6
use Paraunit\Configuration\PHPUnitConfigFile;
7
use Paraunit\Runner\Runner;
8
use Paraunit\Tests\BaseFunctionalTestCase;
9
use Paraunit\Tests\Stub\ConsoleOutputStub;
10
11
/**
12
 * Class RunnerTest.
13
 */
14
class RunnerTest extends BaseFunctionalTestCase
15
{
16
    public function testAllGreen()
17
    {
18
        $outputInterface = new ConsoleOutputStub();
19
20
        /** @var Runner $runner */
21
        $runner = $this->container->get('paraunit.runner.runner');
22
23
        $fileArray = array(
24
            'src/Paraunit/Tests/Stub/ThreeGreenTestStub.php',
25
        );
26
27
        $this->assertEquals(0, $runner->run($fileArray, $outputInterface, new PHPUnitConfigFile('')));
28
29
        $dumpster = array(); // PHP 5.3 needs this crap
30
        $greenCount = preg_match_all('/<ok>.<\/ok>/', $outputInterface->getOutput(), $dumpster);
31
32
        $this->assertEquals(3, $greenCount);
33
    }
34
35 View Code Duplication
    public function testMaxRetryEntityManagerIsClosed()
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...
36
    {
37
        $outputInterface = new ConsoleOutputStub();
38
39
        /** @var Runner $runner */
40
        $runner = $this->container->get('paraunit.runner.runner');
41
42
        $fileArray = array(
43
            'src/Paraunit/Tests/Stub/EntityManagerClosedTestStub.php',
44
        );
45
46
        $this->assertNotEquals(0, $runner->run($fileArray, $outputInterface, new PHPUnitConfigFile('')));
47
48
        $retryCount = array();
49
        preg_match_all('/<ok>A<\/ok>/', $outputInterface->getOutput(), $retryCount);
50
        $errorCount = array();
51
        preg_match_all('/<error>X|E<\/error>/', $outputInterface->getOutput(), $errorCount);
52
53
        $this->assertCount($this->container->getParameter('paraunit.max_retry_count'), $retryCount[0]);
54
        $this->assertCount(1, $errorCount[0]);
55
    }
56
57
    /**
58
     * @dataProvider stubFilePathProvider
59
     */
60 View Code Duplication
    public function testMaxRetryDeadlock($stubFilePath)
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...
61
    {
62
        $outputInterface = new ConsoleOutputStub();
63
64
        $runner = $this->container->get('paraunit.runner.runner');
65
66
        $fileArray = array(
67
            $stubFilePath,
68
        );
69
70
        $this->assertNotEquals(0, $runner->run($fileArray, $outputInterface, new PHPUnitConfigFile('')));
71
72
        $retryCount = array();
73
        preg_match_all('/<ok>A<\/ok>/', $outputInterface->getOutput(), $retryCount);
74
        $errorCount = array();
75
        preg_match_all('/<error>X|E<\/error>/', $outputInterface->getOutput(), $errorCount);
76
77
        $this->assertCount($this->container->getParameter('paraunit.max_retry_count'), $retryCount[0]);
78
        $this->assertCount(1, $errorCount[0]);
79
    }
80
81
    public function stubFilePathProvider()
82
    {
83
        return array(
84
            array('src/Paraunit/Tests/Stub/MySQLDeadLockTestStub.php'),
85
            array('src/Paraunit/Tests/Stub/SQLiteDeadLockTestStub.php'),
86
        );
87
    }
88
89 View Code Duplication
    public function testSegFault()
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...
90
    {
91
        if (!extension_loaded('sigsegv')) {
92
            $this->markTestSkipped('The segfault cannot be reproduced in this environment');
93
        }
94
95
        $outputInterface = new ConsoleOutputStub();
96
97
        $runner = $this->container->get('paraunit.runner.runner');
98
99
        $fileArray = array(
100
            'src/Paraunit/Tests/Stub/SegFaultTestStub.php',
101
        );
102
103
        $this->assertNotEquals(
104
            0,
105
            $runner->run($fileArray, $outputInterface, new PHPUnitConfigFile('')),
106
            'Exit code should not be 0'
107
        );
108
109
        $this->assertContains('<segfault>X</segfault>', $outputInterface->getOutput(), 'Missing X output');
110
        $this->assertContains(
111
            '1 files with SEGMENTATION FAULTS:',
112
            $outputInterface->getOutput(),
113
            'Missing recap title'
114
        );
115
        $this->assertContains(
116
            'SegFaultTestStub.php',
117
            $outputInterface->getOutput(),
118
            'Missing failing filename'
119
        );
120
    }
121
122
    /**
123
     * @group this
124
     */
125 View Code Duplication
    public function testWarning()
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...
126
    {
127
        $phpunitVersion = new \PHPUnit_Runner_Version();
128
129
        if ( ! preg_match('/^5\./', $phpunitVersion->id())) {
130
            $this->markTestSkipped('PHPUnit < 5 in this env, warnings are not present.');
131
        }
132
133
        $outputInterface = new ConsoleOutputStub();
134
135
        $runner = $this->container->get('paraunit.runner.runner');
136
137
        $fileArray = array(
138
            'src/Paraunit/Tests/Stub/MissingProviderTestStub.php',
139
        );
140
141
        $this->assertEquals(
142
            0,
143
            $runner->run($fileArray, $outputInterface, new PHPUnitConfigFile('')),
144
            'Exit code should be 0'
145
        );
146
147
        $this->assertContains('<warning>W</warning>', $outputInterface->getOutput(), 'Missing W output');
148
        $this->assertContains(
149
            '1 files with WARNINGS:',
150
            $outputInterface->getOutput(),
151
            'Missing recap title'
152
        );
153
        $this->assertContains(
154
            '<warning>MissingProviderTestStub.php</warning>',
155
            $outputInterface->getOutput(),
156
            'Missing warned filename'
157
        );
158
    }
159
160
    public function testRegressionFatalErrorsRecognizedAsUnknownResults()
161
    {
162
        $outputInterface = new ConsoleOutputStub();
163
164
        $runner = $this->container->get('paraunit.runner.runner');
165
166
        $fileArray = array(
167
            'src/Paraunit/Tests/Stub/FatalErrorTestStub.php',
168
        );
169
170
        $this->assertNotEquals(0, $runner->run($fileArray, $outputInterface, new PHPUnitConfigFile('phpunit.xml.dist')), 'Exit code should not be 0');
171
172
        $this->assertContains('<fatal>X</fatal>', $outputInterface->getOutput(), 'Missing X output');
173
        $this->assertContains('1 files with FATAL ERRORS:', $outputInterface->getOutput(), 'Missing fatal error recap title');
174
        $this->assertNotContains('1 files with UNKNOWN STATUS:', $outputInterface->getOutput(), 'REGRESSION: fatal error mistaken for unknown result');
175
176
    }
177
}
178