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