Completed
Push — master ( 96df1a...267f86 )
by Naveen
09:52
created

Framework_TestCaseTest   D

Complexity

Total Complexity 43

Size/Duplication

Total Lines 523
Duplicated Lines 48.37 %

Coupling/Cohesion

Components 2
Dependencies 22
Metric Value
wmc 43
lcom 2
cbo 22
dl 253
loc 523
rs 4.71

43 Methods

Rating   Name   Duplication   Size   Complexity  
A testCaseToString() 0 7 1
A testSuccess() 11 11 1
A testFailure() 11 11 1
A testError() 11 11 1
A testSkipped() 12 12 1
A testIncomplete() 12 12 1
A testExceptionInSetUp() 11 11 1
A testExceptionInAssertPreConditions() 11 11 1
A testExceptionInTest() 11 11 1
A testExceptionInAssertPostConditions() 11 11 1
A testExceptionInTearDown() 11 11 1
A testNoArgTestCasePasses() 0 11 1
A testWasRun() 0 7 1
A testException() 0 10 1
A testExceptionWithMessage() 0 10 1
A testExceptionWithWrongMessage() 14 14 1
A testExceptionWithRegexpMessage() 0 10 1
A testExceptionWithWrongRegexpMessage() 14 14 1
A testExceptionWithInvalidRegexpMessage() 0 12 1
A testNoException() 10 10 1
A testWrongException() 10 10 1
B testGlobalsBackupPre() 0 41 1
A testGlobalsBackupPost() 0 19 1
A testStaticAttributesBackupPre() 0 5 1
A testStaticAttributesBackupPost() 0 5 1
A testIsInIsolationReturnsFalse() 8 8 1
A testIsInIsolationReturnsTrue() 9 9 1
A testExpectOutputStringFooActualFoo() 8 8 1
A testExpectOutputStringFooActualBar() 8 8 1
A testExpectOutputRegexFooActualFoo() 8 8 1
A testExpectOutputRegexFooActualBar() 8 8 1
A testSkipsIfRequiresHigherVersionOfPHPUnit() 11 11 1
A testSkipsIfRequiresHigherVersionOfPHP() 11 11 1
A testSkipsIfRequiresNonExistingOs() 11 11 1
A testSkipsIfRequiresNonExistingFunction() 11 11 1
A testSkipsIfRequiresNonExistingExtension() 0 10 1
A testSkipsProvidesMessagesForAllSkippingReasons() 0 16 1
A testRequiringAnExistingMethodDoesNotSkip() 0 6 1
A testRequiringAnExistingFunctionDoesNotSkip() 0 6 1
A testRequiringAnExistingExtensionDoesNotSkip() 0 6 1
A testRequiringAnExistingOsDoesNotSkip() 0 6 1
A testCurrentWorkingDirectoryIsRestored() 0 9 1
A testTypeErrorCanBeExpected() 0 5 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Framework_TestCaseTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Framework_TestCaseTest, and based on these observations, apply Extract Interface, too.

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 28 and the first side effect is on line 11.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 * This file is part of PHPUnit.
4
 *
5
 * (c) Sebastian Bergmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'NoArgTestCaseTest.php';
12
require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Singleton.php';
13
14
$GLOBALS['a']  = 'a';
15
$_ENV['b']     = 'b';
16
$_POST['c']    = 'c';
17
$_GET['d']     = 'd';
18
$_COOKIE['e']  = 'e';
19
$_SERVER['f']  = 'f';
20
$_FILES['g']   = 'g';
21
$_REQUEST['h'] = 'h';
22
$GLOBALS['i']  = 'i';
23
24
/**
25
 * @since      Class available since Release 2.0.0
26
 * @covers     PHPUnit_Framework_TestCase
27
 */
28
class Framework_TestCaseTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
29
{
30
    protected $backupGlobalsBlacklist = array('i', 'singleton');
31
32
    /**
33
     * Used be testStaticAttributesBackupPre
34
     */
35
    protected static $_testStatic = 0;
36
37
    public function testCaseToString()
38
    {
39
        $this->assertEquals(
40
            'Framework_TestCaseTest::testCaseToString',
41
            $this->toString()
42
        );
43
    }
44
45 View Code Duplication
    public function testSuccess()
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...
46
    {
47
        $test   = new Success;
48
        $result = $test->run();
49
50
        $this->assertEquals(PHPUnit_Runner_BaseTestRunner::STATUS_PASSED, $test->getStatus());
51
        $this->assertEquals(0, $result->errorCount());
52
        $this->assertEquals(0, $result->failureCount());
53
        $this->assertEquals(0, $result->skippedCount());
54
        $this->assertEquals(1, count($result));
55
    }
56
57 View Code Duplication
    public function testFailure()
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...
58
    {
59
        $test   = new Failure;
60
        $result = $test->run();
61
62
        $this->assertEquals(PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE, $test->getStatus());
63
        $this->assertEquals(0, $result->errorCount());
64
        $this->assertEquals(1, $result->failureCount());
65
        $this->assertEquals(0, $result->skippedCount());
66
        $this->assertEquals(1, count($result));
67
    }
68
69 View Code Duplication
    public function testError()
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
        $test   = new TestError;
72
        $result = $test->run();
73
74
        $this->assertEquals(PHPUnit_Runner_BaseTestRunner::STATUS_ERROR, $test->getStatus());
75
        $this->assertEquals(1, $result->errorCount());
76
        $this->assertEquals(0, $result->failureCount());
77
        $this->assertEquals(0, $result->skippedCount());
78
        $this->assertEquals(1, count($result));
79
    }
80
81 View Code Duplication
    public function testSkipped()
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
        $test   = new TestSkipped();
84
        $result = $test->run();
85
86
        $this->assertEquals(PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED, $test->getStatus());
87
        $this->assertEquals('Skipped test', $test->getStatusMessage());
88
        $this->assertEquals(0, $result->errorCount());
89
        $this->assertEquals(0, $result->failureCount());
90
        $this->assertEquals(1, $result->skippedCount());
91
        $this->assertEquals(1, count($result));
92
    }
93
94 View Code Duplication
    public function testIncomplete()
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...
95
    {
96
        $test   = new TestIncomplete();
97
        $result = $test->run();
98
99
        $this->assertEquals(PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE, $test->getStatus());
100
        $this->assertEquals('Incomplete test', $test->getStatusMessage());
101
        $this->assertEquals(0, $result->errorCount());
102
        $this->assertEquals(0, $result->failureCount());
103
        $this->assertEquals(0, $result->skippedCount());
104
        $this->assertEquals(1, count($result));
105
    }
106
107 View Code Duplication
    public function testExceptionInSetUp()
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...
108
    {
109
        $test   = new ExceptionInSetUpTest('testSomething');
110
        $result = $test->run();
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
111
112
        $this->assertTrue($test->setUp);
113
        $this->assertFalse($test->assertPreConditions);
114
        $this->assertFalse($test->testSomething);
115
        $this->assertFalse($test->assertPostConditions);
116
        $this->assertTrue($test->tearDown);
117
    }
118
119 View Code Duplication
    public function testExceptionInAssertPreConditions()
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...
120
    {
121
        $test   = new ExceptionInAssertPreConditionsTest('testSomething');
122
        $result = $test->run();
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
123
124
        $this->assertTrue($test->setUp);
125
        $this->assertTrue($test->assertPreConditions);
126
        $this->assertFalse($test->testSomething);
127
        $this->assertFalse($test->assertPostConditions);
128
        $this->assertTrue($test->tearDown);
129
    }
130
131 View Code Duplication
    public function testExceptionInTest()
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...
132
    {
133
        $test   = new ExceptionInTest('testSomething');
134
        $result = $test->run();
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
135
136
        $this->assertTrue($test->setUp);
137
        $this->assertTrue($test->assertPreConditions);
138
        $this->assertTrue($test->testSomething);
139
        $this->assertFalse($test->assertPostConditions);
140
        $this->assertTrue($test->tearDown);
141
    }
142
143 View Code Duplication
    public function testExceptionInAssertPostConditions()
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...
144
    {
145
        $test   = new ExceptionInAssertPostConditionsTest('testSomething');
146
        $result = $test->run();
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
147
148
        $this->assertTrue($test->setUp);
149
        $this->assertTrue($test->assertPreConditions);
150
        $this->assertTrue($test->testSomething);
151
        $this->assertTrue($test->assertPostConditions);
152
        $this->assertTrue($test->tearDown);
153
    }
154
155 View Code Duplication
    public function testExceptionInTearDown()
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...
156
    {
157
        $test   = new ExceptionInTearDownTest('testSomething');
158
        $result = $test->run();
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
159
160
        $this->assertTrue($test->setUp);
161
        $this->assertTrue($test->assertPreConditions);
162
        $this->assertTrue($test->testSomething);
163
        $this->assertTrue($test->assertPostConditions);
164
        $this->assertTrue($test->tearDown);
165
    }
166
167
    public function testNoArgTestCasePasses()
168
    {
169
        $result = new PHPUnit_Framework_TestResult;
170
        $t      = new PHPUnit_Framework_TestSuite('NoArgTestCaseTest');
171
172
        $t->run($result);
173
174
        $this->assertEquals(1, count($result));
175
        $this->assertEquals(0, $result->failureCount());
176
        $this->assertEquals(0, $result->errorCount());
177
    }
178
179
    public function testWasRun()
180
    {
181
        $test = new WasRun;
182
        $test->run();
183
184
        $this->assertTrue($test->wasRun);
185
    }
186
187
    public function testException()
188
    {
189
        $test = new ThrowExceptionTestCase('test');
190
        $test->setExpectedException('RuntimeException');
191
192
        $result = $test->run();
193
194
        $this->assertEquals(1, count($result));
195
        $this->assertTrue($result->wasSuccessful());
196
    }
197
198
    public function testExceptionWithMessage()
199
    {
200
        $test = new ThrowExceptionTestCase('test');
201
        $test->setExpectedException('RuntimeException', 'A runtime error occurred');
202
203
        $result = $test->run();
204
205
        $this->assertEquals(1, count($result));
206
        $this->assertTrue($result->wasSuccessful());
207
    }
208
209 View Code Duplication
    public function testExceptionWithWrongMessage()
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...
210
    {
211
        $test = new ThrowExceptionTestCase('test');
212
        $test->setExpectedException('RuntimeException', 'A logic error occurred');
213
214
        $result = $test->run();
215
216
        $this->assertEquals(1, $result->failureCount());
217
        $this->assertEquals(1, count($result));
218
        $this->assertEquals(
219
            "Failed asserting that exception message 'A runtime error occurred' contains 'A logic error occurred'.",
220
            $test->getStatusMessage()
221
        );
222
    }
223
224
    public function testExceptionWithRegexpMessage()
225
    {
226
        $test = new ThrowExceptionTestCase('test');
227
        $test->setExpectedExceptionRegExp('RuntimeException', '/runtime .*? occurred/');
228
229
        $result = $test->run();
230
231
        $this->assertEquals(1, count($result));
232
        $this->assertTrue($result->wasSuccessful());
233
    }
234
235 View Code Duplication
    public function testExceptionWithWrongRegexpMessage()
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...
236
    {
237
        $test = new ThrowExceptionTestCase('test');
238
        $test->setExpectedExceptionRegExp('RuntimeException', '/logic .*? occurred/');
239
240
        $result = $test->run();
241
242
        $this->assertEquals(1, $result->failureCount());
243
        $this->assertEquals(1, count($result));
244
        $this->assertEquals(
245
            "Failed asserting that exception message 'A runtime error occurred' matches '/logic .*? occurred/'.",
246
            $test->getStatusMessage()
247
        );
248
    }
249
250
    /**
251
     * @covers PHPUnit_Framework_Constraint_ExceptionMessageRegExp
252
     */
253
    public function testExceptionWithInvalidRegexpMessage()
254
    {
255
        $test = new ThrowExceptionTestCase('test');
256
        $test->setExpectedExceptionRegExp('RuntimeException', '#runtime .*? occurred/'); // wrong delimiter
257
258
        $result = $test->run();
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
259
260
        $this->assertEquals(
261
            "Invalid expected exception message regex given: '#runtime .*? occurred/'",
262
            $test->getStatusMessage()
263
        );
264
    }
265
266 View Code Duplication
    public function testNoException()
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...
267
    {
268
        $test = new ThrowNoExceptionTestCase('test');
269
        $test->setExpectedException('RuntimeException');
270
271
        $result = $test->run();
272
273
        $this->assertEquals(1, $result->failureCount());
274
        $this->assertEquals(1, count($result));
275
    }
276
277 View Code Duplication
    public function testWrongException()
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...
278
    {
279
        $test = new ThrowExceptionTestCase('test');
280
        $test->setExpectedException('InvalidArgumentException');
281
282
        $result = $test->run();
283
284
        $this->assertEquals(1, $result->failureCount());
285
        $this->assertEquals(1, count($result));
286
    }
287
288
    /**
289
     * @backupGlobals enabled
290
     */
291
    public function testGlobalsBackupPre()
0 ignored issues
show
Coding Style introduced by
testGlobalsBackupPre uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPre uses the super-global variable $_ENV which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPre uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPre uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPre uses the super-global variable $_COOKIE which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPre uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPre uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPre uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
292
    {
293
        global $a;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
294
        global $i;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
295
296
        $this->assertEquals('a', $a);
297
        $this->assertEquals('a', $GLOBALS['a']);
298
        $this->assertEquals('b', $_ENV['b']);
299
        $this->assertEquals('c', $_POST['c']);
300
        $this->assertEquals('d', $_GET['d']);
301
        $this->assertEquals('e', $_COOKIE['e']);
302
        $this->assertEquals('f', $_SERVER['f']);
303
        $this->assertEquals('g', $_FILES['g']);
304
        $this->assertEquals('h', $_REQUEST['h']);
305
        $this->assertEquals('i', $i);
306
        $this->assertEquals('i', $GLOBALS['i']);
307
308
        $GLOBALS['a']   = 'aa';
309
        $GLOBALS['foo'] = 'bar';
310
        $_ENV['b']      = 'bb';
311
        $_POST['c']     = 'cc';
312
        $_GET['d']      = 'dd';
313
        $_COOKIE['e']   = 'ee';
314
        $_SERVER['f']   = 'ff';
315
        $_FILES['g']    = 'gg';
316
        $_REQUEST['h']  = 'hh';
317
        $GLOBALS['i']   = 'ii';
318
319
        $this->assertEquals('aa', $a);
320
        $this->assertEquals('aa', $GLOBALS['a']);
321
        $this->assertEquals('bar', $GLOBALS['foo']);
322
        $this->assertEquals('bb', $_ENV['b']);
323
        $this->assertEquals('cc', $_POST['c']);
324
        $this->assertEquals('dd', $_GET['d']);
325
        $this->assertEquals('ee', $_COOKIE['e']);
326
        $this->assertEquals('ff', $_SERVER['f']);
327
        $this->assertEquals('gg', $_FILES['g']);
328
        $this->assertEquals('hh', $_REQUEST['h']);
329
        $this->assertEquals('ii', $i);
330
        $this->assertEquals('ii', $GLOBALS['i']);
331
    }
332
333
    public function testGlobalsBackupPost()
0 ignored issues
show
Coding Style introduced by
testGlobalsBackupPost uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPost uses the super-global variable $_ENV which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPost uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPost uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPost uses the super-global variable $_COOKIE which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPost uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPost uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
testGlobalsBackupPost uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
334
    {
335
        global $a;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
336
        global $i;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
337
338
        $this->assertEquals('a', $a);
339
        $this->assertEquals('a', $GLOBALS['a']);
340
        $this->assertEquals('b', $_ENV['b']);
341
        $this->assertEquals('c', $_POST['c']);
342
        $this->assertEquals('d', $_GET['d']);
343
        $this->assertEquals('e', $_COOKIE['e']);
344
        $this->assertEquals('f', $_SERVER['f']);
345
        $this->assertEquals('g', $_FILES['g']);
346
        $this->assertEquals('h', $_REQUEST['h']);
347
        $this->assertEquals('ii', $i);
348
        $this->assertEquals('ii', $GLOBALS['i']);
349
350
        $this->assertArrayNotHasKey('foo', $GLOBALS);
351
    }
352
353
    /**
354
     * @backupGlobals enabled
355
     * @backupStaticAttributes enabled
356
     */
357
    public function testStaticAttributesBackupPre()
0 ignored issues
show
Coding Style introduced by
testStaticAttributesBackupPre uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
358
    {
359
        $GLOBALS['singleton'] = Singleton::getInstance();
360
        self::$_testStatic    = 123;
361
    }
362
363
    /**
364
     * @depends testStaticAttributesBackupPre
365
     */
366
    public function testStaticAttributesBackupPost()
0 ignored issues
show
Coding Style introduced by
testStaticAttributesBackupPost uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
367
    {
368
        $this->assertNotSame($GLOBALS['singleton'], Singleton::getInstance());
369
        $this->assertSame(0, self::$_testStatic);
370
    }
371
372 View Code Duplication
    public function testIsInIsolationReturnsFalse()
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...
373
    {
374
        $test   = new IsolationTest('testIsInIsolationReturnsFalse');
375
        $result = $test->run();
376
377
        $this->assertEquals(1, count($result));
378
        $this->assertTrue($result->wasSuccessful());
379
    }
380
381 View Code Duplication
    public function testIsInIsolationReturnsTrue()
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...
382
    {
383
        $test   = new IsolationTest('testIsInIsolationReturnsTrue');
384
        $test->setRunTestInSeparateProcess(true);
385
        $result = $test->run();
386
387
        $this->assertEquals(1, count($result));
388
        $this->assertTrue($result->wasSuccessful());
389
    }
390
391 View Code Duplication
    public function testExpectOutputStringFooActualFoo()
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...
392
    {
393
        $test   = new OutputTestCase('testExpectOutputStringFooActualFoo');
394
        $result = $test->run();
395
396
        $this->assertEquals(1, count($result));
397
        $this->assertTrue($result->wasSuccessful());
398
    }
399
400 View Code Duplication
    public function testExpectOutputStringFooActualBar()
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...
401
    {
402
        $test   = new OutputTestCase('testExpectOutputStringFooActualBar');
403
        $result = $test->run();
404
405
        $this->assertEquals(1, count($result));
406
        $this->assertFalse($result->wasSuccessful());
407
    }
408
409 View Code Duplication
    public function testExpectOutputRegexFooActualFoo()
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...
410
    {
411
        $test   = new OutputTestCase('testExpectOutputRegexFooActualFoo');
412
        $result = $test->run();
413
414
        $this->assertEquals(1, count($result));
415
        $this->assertTrue($result->wasSuccessful());
416
    }
417
418 View Code Duplication
    public function testExpectOutputRegexFooActualBar()
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...
419
    {
420
        $test   = new OutputTestCase('testExpectOutputRegexFooActualBar');
421
        $result = $test->run();
422
423
        $this->assertEquals(1, count($result));
424
        $this->assertFalse($result->wasSuccessful());
425
    }
426
427 View Code Duplication
    public function testSkipsIfRequiresHigherVersionOfPHPUnit()
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...
428
    {
429
        $test   = new RequirementsTest('testAlwaysSkip');
430
        $result = $test->run();
431
432
        $this->assertEquals(1, $result->skippedCount());
433
        $this->assertEquals(
434
            'PHPUnit 1111111 (or later) is required.',
435
            $test->getStatusMessage()
436
        );
437
    }
438
439 View Code Duplication
    public function testSkipsIfRequiresHigherVersionOfPHP()
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...
440
    {
441
        $test   = new RequirementsTest('testAlwaysSkip2');
442
        $result = $test->run();
443
444
        $this->assertEquals(1, $result->skippedCount());
445
        $this->assertEquals(
446
            'PHP 9999999 (or later) is required.',
447
            $test->getStatusMessage()
448
        );
449
    }
450
451 View Code Duplication
    public function testSkipsIfRequiresNonExistingOs()
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...
452
    {
453
        $test   = new RequirementsTest('testAlwaysSkip3');
454
        $result = $test->run();
455
456
        $this->assertEquals(1, $result->skippedCount());
457
        $this->assertEquals(
458
            'Operating system matching /DOESNOTEXIST/i is required.',
459
            $test->getStatusMessage()
460
        );
461
    }
462
463 View Code Duplication
    public function testSkipsIfRequiresNonExistingFunction()
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...
464
    {
465
        $test   = new RequirementsTest('testNine');
466
        $result = $test->run();
467
468
        $this->assertEquals(1, $result->skippedCount());
469
        $this->assertEquals(
470
            'Function testFunc is required.',
471
            $test->getStatusMessage()
472
        );
473
    }
474
475
    public function testSkipsIfRequiresNonExistingExtension()
476
    {
477
        $test   = new RequirementsTest('testTen');
478
        $result = $test->run();
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
479
480
        $this->assertEquals(
481
            'Extension testExt is required.',
482
            $test->getStatusMessage()
483
        );
484
    }
485
486
    public function testSkipsProvidesMessagesForAllSkippingReasons()
487
    {
488
        $test   = new RequirementsTest('testAllPossibleRequirements');
489
        $result = $test->run();
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
490
491
        $this->assertEquals(
492
            'PHP 99-dev (or later) is required.' . PHP_EOL .
493
            'PHPUnit 9-dev (or later) is required.' . PHP_EOL .
494
            'Operating system matching /DOESNOTEXIST/i is required.' . PHP_EOL .
495
            'Function testFuncOne is required.' . PHP_EOL .
496
            'Function testFuncTwo is required.' . PHP_EOL .
497
            'Extension testExtOne is required.' . PHP_EOL .
498
            'Extension testExtTwo is required.',
499
            $test->getStatusMessage()
500
        );
501
    }
502
503
    public function testRequiringAnExistingMethodDoesNotSkip()
504
    {
505
        $test   = new RequirementsTest('testExistingMethod');
506
        $result = $test->run();
507
        $this->assertEquals(0, $result->skippedCount());
508
    }
509
510
    public function testRequiringAnExistingFunctionDoesNotSkip()
511
    {
512
        $test   = new RequirementsTest('testExistingFunction');
513
        $result = $test->run();
514
        $this->assertEquals(0, $result->skippedCount());
515
    }
516
517
    public function testRequiringAnExistingExtensionDoesNotSkip()
518
    {
519
        $test   = new RequirementsTest('testExistingExtension');
520
        $result = $test->run();
521
        $this->assertEquals(0, $result->skippedCount());
522
    }
523
524
    public function testRequiringAnExistingOsDoesNotSkip()
525
    {
526
        $test   = new RequirementsTest('testExistingOs');
527
        $result = $test->run();
528
        $this->assertEquals(0, $result->skippedCount());
529
    }
530
531
    public function testCurrentWorkingDirectoryIsRestored()
532
    {
533
        $expectedCwd = getcwd();
534
535
        $test = new ChangeCurrentWorkingDirectoryTest('testSomethingThatChangesTheCwd');
536
        $test->run();
537
538
        $this->assertSame($expectedCwd, getcwd());
539
    }
540
541
    /**
542
     * @requires PHP 7
543
     * @expectedException TypeError
544
     */
545
    public function testTypeErrorCanBeExpected()
546
    {
547
        $o = new ClassWithScalarTypeDeclarations;
548
        $o->foo(null, null);
549
    }
550
}
551