1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Long Arrays Sniff test file |
4
|
|
|
* |
5
|
|
|
* @package PHPCompatibility |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Long Arrays Sniff tests |
11
|
|
|
* |
12
|
|
|
* @uses BaseSniffTest |
13
|
|
|
* @package PHPCompatibility |
14
|
|
|
* @author Jansen Price <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class LongArraysSniffTest extends BaseSniffTest |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
const TEST_FILE = 'sniff-examples/long_arrays.php'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* testLongVariable |
23
|
|
|
* |
24
|
|
|
* @dataProvider dataLongVariable |
25
|
|
|
* |
26
|
|
|
* @param string $longVariable Variable name. |
27
|
|
|
* @param array $lines The line numbers in the test file which apply to this variable. |
28
|
|
|
* @param string $deprecatedIn The PHP version in which the variable became deprecated. |
29
|
|
|
* @param string $removedIn The PHP version in which the variable was removed. |
30
|
|
|
* @param string $okVersion A PHP version in which the variable was still ok to be used. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
public function testLongVariable($longVariable, $lines, $deprecatedIn, $removedIn, $okVersion) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$file = $this->sniffFile(self::TEST_FILE); |
37
|
|
|
foreach ($lines as $line) { |
38
|
|
|
$this->assertWarning($file, $line, "The use of long predefined variables has been deprecated in {$deprecatedIn} and removed in {$removedIn}; Found '{$longVariable}'"); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$file = $this->sniffFile(self::TEST_FILE, $okVersion); |
42
|
|
|
foreach ($lines as $line) { |
43
|
|
|
$this->assertNoViolation($file, $line); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Data provider. |
49
|
|
|
* |
50
|
|
|
* @see testLongVariable() |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
public function dataLongVariable() |
55
|
|
|
{ |
56
|
|
|
return array( |
57
|
|
|
array('$HTTP_POST_VARS', array(3), '5.3', '5.4', '5.2'), |
58
|
|
|
array('$HTTP_GET_VARS', array(4), '5.3', '5.4', '5.2'), |
59
|
|
|
array('$HTTP_ENV_VARS', array(5), '5.3', '5.4', '5.2'), |
60
|
|
|
array('$HTTP_SERVER_VARS', array(6), '5.3', '5.4', '5.2'), |
61
|
|
|
array('$HTTP_COOKIE_VARS', array(7), '5.3', '5.4', '5.2'), |
62
|
|
|
array('$HTTP_SESSION_VARS', array(8), '5.3', '5.4', '5.2'), |
63
|
|
|
array('$HTTP_POST_FILES', array(9), '5.3', '5.4', '5.2'), |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.