Completed
Branch output_parsers_refactor (d2cb12)
by Alessandro
02:20
created

RunnerTest::testSegFault()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 33
Code Lines 21

Duplication

Lines 33
Ratio 100 %

Importance

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