|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Late static binding sniff test file |
|
4
|
|
|
* |
|
5
|
|
|
* @package PHPCompatibility |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Late static binding sniff test file |
|
11
|
|
|
* |
|
12
|
|
|
* @uses BaseSniffTest |
|
13
|
|
|
* @package PHPCompatibility |
|
14
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class LateStaticBindingSniffTest extends BaseSniffTest |
|
|
|
|
|
|
17
|
|
|
{ |
|
18
|
|
|
const TEST_FILE = 'sniff-examples/late_static_binding.php'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* testLateStaticBinding |
|
22
|
|
|
* |
|
23
|
|
|
* @group lateStaticBinding |
|
24
|
|
|
* |
|
25
|
|
|
* @dataProvider dataLateStaticBinding |
|
26
|
|
|
* |
|
27
|
|
|
* @param int $line The line number. |
|
28
|
|
|
* |
|
29
|
|
|
* @return void |
|
30
|
|
|
*/ |
|
31
|
|
View Code Duplication |
public function testLateStaticBinding($line) |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.2'); |
|
34
|
|
|
$this->assertError($file, $line, 'Late static binding is not supported in PHP 5.2 or earlier.'); |
|
35
|
|
|
|
|
36
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.3'); |
|
37
|
|
|
$this->assertNoViolation($file, $line); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Data provider. |
|
42
|
|
|
* |
|
43
|
|
|
* @see testLateStaticBinding() |
|
44
|
|
|
* |
|
45
|
|
|
* @return array |
|
46
|
|
|
*/ |
|
47
|
|
|
public function dataLateStaticBinding() |
|
48
|
|
|
{ |
|
49
|
|
|
return array( |
|
50
|
|
|
array(8), |
|
51
|
|
|
array(9), |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* testLateStaticBindingOutsideClassScope |
|
58
|
|
|
* |
|
59
|
|
|
* @group lateStaticBinding |
|
60
|
|
|
* |
|
61
|
|
|
* @dataProvider dataLateStaticBindingOutsideClassScope |
|
62
|
|
|
* |
|
63
|
|
|
* @param int $line The line number. |
|
64
|
|
|
* |
|
65
|
|
|
* @return void |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testLateStaticBindingOutsideClassScope($line) |
|
68
|
|
|
{ |
|
69
|
|
|
$file = $this->sniffFile(self::TEST_FILE); |
|
70
|
|
|
$this->assertError($file, $line, 'Late static binding is not supported outside of class scope.'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Data provider. |
|
75
|
|
|
* |
|
76
|
|
|
* @see testLateStaticBindingOutsideClassScope() |
|
77
|
|
|
* |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
|
|
public function dataLateStaticBindingOutsideClassScope() |
|
81
|
|
|
{ |
|
82
|
|
|
return array( |
|
83
|
|
|
array(19), |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* testNoViolation |
|
90
|
|
|
* |
|
91
|
|
|
* @group lateStaticBinding |
|
92
|
|
|
* |
|
93
|
|
|
* @dataProvider dataNoViolation |
|
94
|
|
|
* |
|
95
|
|
|
* @param int $line The line number. |
|
96
|
|
|
* |
|
97
|
|
|
* @return void |
|
98
|
|
|
*/ |
|
99
|
|
|
public function testNoViolation($line) |
|
100
|
|
|
{ |
|
101
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.2'); |
|
102
|
|
|
$this->assertNoViolation($file, $line); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Data provider. |
|
107
|
|
|
* |
|
108
|
|
|
* @see testNoViolation() |
|
109
|
|
|
* |
|
110
|
|
|
* @return array |
|
111
|
|
|
*/ |
|
112
|
|
View Code Duplication |
public function dataNoViolation() |
|
|
|
|
|
|
113
|
|
|
{ |
|
114
|
|
|
return array( |
|
115
|
|
|
array(7), |
|
116
|
|
|
array(12), |
|
117
|
|
|
array(15), |
|
118
|
|
|
array(16), |
|
119
|
|
|
); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|
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.