1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* New Interfaces Sniff test file |
4
|
|
|
* |
5
|
|
|
* @package PHPCompatibility |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* New Interfaces Sniff tests |
11
|
|
|
* |
12
|
|
|
* @uses BaseSniffTest |
13
|
|
|
* @package PHPCompatibility |
14
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class NewInterfacesSniffTest extends BaseSniffTest |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* setUp |
20
|
|
|
* |
21
|
|
|
* @return void |
22
|
|
|
*/ |
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
parent::setUp(); |
26
|
|
|
|
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Test Countable interface |
31
|
|
|
* |
32
|
|
|
* @return void |
33
|
|
|
*/ |
34
|
|
|
public function testCountable() |
35
|
|
|
{ |
36
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.0'); |
37
|
|
|
$this->assertError($file, 3, 'The built-in interface Countable is not present in PHP version 5.0 or earlier'); |
38
|
|
|
|
39
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.5'); |
40
|
|
|
$this->assertNoViolation($file, 3); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Test OuterIterator interface |
45
|
|
|
* |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
|
|
public function testOuterIterator() |
49
|
|
|
{ |
50
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.0'); |
51
|
|
|
$this->assertError($file, 4, 'The built-in interface OuterIterator is not present in PHP version 5.0 or earlier'); |
52
|
|
|
|
53
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.5'); |
54
|
|
|
$this->assertNoViolation($file, 4); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Test RecursiveIterator interface |
59
|
|
|
* |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
public function testRecursiveIterator() |
63
|
|
|
{ |
64
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.0'); |
65
|
|
|
$this->assertError($file, 5, 'The built-in interface RecursiveIterator is not present in PHP version 5.0 or earlier'); |
66
|
|
|
|
67
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.5'); |
68
|
|
|
$this->assertNoViolation($file, 5); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Test SeekableIterator interface |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
*/ |
76
|
|
|
public function testSeekableIterator() |
77
|
|
|
{ |
78
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.0'); |
79
|
|
|
$this->assertError($file, 6, 'The built-in interface SeekableIterator is not present in PHP version 5.0 or earlier'); |
80
|
|
|
|
81
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.5'); |
82
|
|
|
$this->assertNoViolation($file, 6); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Test Serializable interface |
87
|
|
|
* |
88
|
|
|
* @return void |
89
|
|
|
*/ |
90
|
|
|
public function testSerializable() |
91
|
|
|
{ |
92
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.0'); |
93
|
|
|
$this->assertError($file, 7, 'The built-in interface Serializable is not present in PHP version 5.0 or earlier'); |
94
|
|
|
|
95
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.5'); |
96
|
|
|
$this->assertNoViolation($file, 7); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Test SplObserver interface |
101
|
|
|
* |
102
|
|
|
* @return void |
103
|
|
|
*/ |
104
|
|
|
public function testSplObserver() |
105
|
|
|
{ |
106
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.0'); |
107
|
|
|
$this->assertError($file, 11, 'The built-in interface SplObserver is not present in PHP version 5.0 or earlier'); |
108
|
|
|
|
109
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.5'); |
110
|
|
|
$this->assertNoViolation($file, 11); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Test SplSubject interface |
115
|
|
|
* |
116
|
|
|
* @return void |
117
|
|
|
*/ |
118
|
|
|
public function testSplSubject() |
119
|
|
|
{ |
120
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.0'); |
121
|
|
|
$this->assertError($file, 12, 'The built-in interface SplSubject is not present in PHP version 5.0 or earlier'); |
122
|
|
|
|
123
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.5'); |
124
|
|
|
$this->assertNoViolation($file, 12); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Test JsonSerializable interface |
129
|
|
|
* |
130
|
|
|
* @return void |
131
|
|
|
*/ |
132
|
|
|
public function testJsonSerializable() |
133
|
|
|
{ |
134
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.3'); |
135
|
|
|
$this->assertError($file, 13, 'The built-in interface JsonSerializable is not present in PHP version 5.3 or earlier'); |
136
|
|
|
|
137
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.5'); |
138
|
|
|
$this->assertNoViolation($file, 13); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Test SessionHandlerInterface interface |
143
|
|
|
* |
144
|
|
|
* @return void |
145
|
|
|
*/ |
146
|
|
|
public function testSessionHandlerInterface() |
147
|
|
|
{ |
148
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.3'); |
149
|
|
|
$this->assertError($file, 14, 'The built-in interface SessionHandlerInterface is not present in PHP version 5.3 or earlier'); |
150
|
|
|
|
151
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.5'); |
152
|
|
|
$this->assertNoViolation($file, 14); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* Test unsupported methods |
157
|
|
|
* |
158
|
|
|
* @return void |
159
|
|
|
*/ |
160
|
|
|
public function testUnsupportedMethods() |
161
|
|
|
{ |
162
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php'); |
163
|
|
|
$this->assertError($file, 8, 'Classes that implement interface Serializable do not support the method __sleep(). See http://php.net/serializable'); |
164
|
|
|
$this->assertError($file, 9, 'Classes that implement interface Serializable do not support the method __wakeup(). See http://php.net/serializable'); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Test multiple interfaces |
169
|
|
|
* |
170
|
|
|
* @return void |
171
|
|
|
*/ |
172
|
|
|
public function testMultipleInterfaces() |
173
|
|
|
{ |
174
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.0'); |
175
|
|
|
$this->assertError($file, 16, 'The built-in interface SplSubject is not present in PHP version 5.0 or earlier'); |
176
|
|
|
$this->assertError($file, 16, 'The built-in interface JsonSerializable is not present in PHP version 5.3 or earlier'); |
177
|
|
|
$this->assertError($file, 16, 'The built-in interface Countable is not present in PHP version 5.0 or earlier'); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Test interfaces in different cases. |
182
|
|
|
* |
183
|
|
|
* @return void |
184
|
|
|
*/ |
185
|
|
|
public function testCaseInsensitive() |
186
|
|
|
{ |
187
|
|
|
$file = $this->sniffFile('sniff-examples/new_interfaces.php', '5.0'); |
188
|
|
|
$this->assertError($file, 18, 'The built-in interface COUNTABLE is not present in PHP version 5.0 or earlier'); |
189
|
|
|
$this->assertError($file, 19, 'The built-in interface countable is not present in PHP version 5.0 or earlier'); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
} |
193
|
|
|
|