1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Removed Functions Parameter Sniff test file |
4
|
|
|
* |
5
|
|
|
* @package PHPCompatibility |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Removed Functions Parameter Sniff test file |
11
|
|
|
* |
12
|
|
|
* @uses BaseSniffTest |
13
|
|
|
* @package PHPCompatibility |
14
|
|
|
* @author Wim Godden <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class RemovedFunctionParameterSniffTest extends BaseSniffTest |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
const TEST_FILE = 'sniff-examples/removed_function_parameter.php'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* testRemovedParameter |
23
|
|
|
* |
24
|
|
|
* @dataProvider dataRemovedParameter |
25
|
|
|
* |
26
|
|
|
* @param string $functionName Function name. |
27
|
|
|
* @param string $parameterName Parameter name. |
28
|
|
|
* @param string $removedIn The PHP version in which the parameter was removed. |
29
|
|
|
* @param array $lines The line numbers in the test file which apply to this class. |
30
|
|
|
* @param string $okVersion A PHP version in which the parameter was ok to be used. |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
public function testRemovedParameter($functionName, $parameterName, $removedIn, $lines, $okVersion) |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
$file = $this->sniffFile(self::TEST_FILE, $okVersion); |
37
|
|
|
foreach ($lines as $line) { |
38
|
|
|
$this->assertNoViolation($file, $line); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
$file = $this->sniffFile(self::TEST_FILE, $removedIn); |
42
|
|
|
foreach ($lines as $line) { |
43
|
|
|
$this->assertError($file, $line, "The function {$functionName} does not have a parameter {$parameterName} in PHP version {$removedIn} or later"); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Data provider. |
49
|
|
|
* |
50
|
|
|
* @see testRemovedParameter() |
51
|
|
|
* |
52
|
|
|
* @return array |
53
|
|
|
*/ |
54
|
|
|
public function dataRemovedParameter() |
55
|
|
|
{ |
56
|
|
|
return array( |
57
|
|
|
array('mktime', 'is_dst', '7.0', array(3), '5.6'), |
58
|
|
|
array('gmmktime', 'is_dst', '7.0', array(5), '5.6'), |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* testValidParameter |
65
|
|
|
* |
66
|
|
|
* @dataProvider dataValidParameter |
67
|
|
|
* |
68
|
|
|
* @param int $line The line number. |
69
|
|
|
* |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
public function testValidParameter($line) |
73
|
|
|
{ |
74
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '7.0'); |
75
|
|
|
$this->assertNoViolation($file, $line); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Data provider. |
80
|
|
|
* |
81
|
|
|
* @see testValidParameter() |
82
|
|
|
* |
83
|
|
|
* @return array |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function dataValidParameter() |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
return array( |
88
|
|
|
array(8), |
89
|
|
|
array(9), |
90
|
|
|
array(10), |
91
|
|
|
array(11), |
92
|
|
|
array(12), |
93
|
|
|
array(13), |
94
|
|
|
array(14), |
95
|
|
|
array(15), |
96
|
|
|
array(17), |
97
|
|
|
); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
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.