|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* New execution directives test file |
|
4
|
|
|
* |
|
5
|
|
|
* @package PHPCompatibility |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* New execution directives test file |
|
11
|
|
|
* |
|
12
|
|
|
* @uses BaseSniffTest |
|
13
|
|
|
* @package PHPCompatibility |
|
14
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class NewExecutionDirectivesSniffTest extends BaseSniffTest |
|
17
|
|
|
{ |
|
18
|
|
|
const TEST_FILE = 'sniff-examples/new_execution_directives.php'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Sniffed file |
|
22
|
|
|
* |
|
23
|
|
|
* @var PHP_CodeSniffer_File |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $_sniffFile; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* setUp |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
public function setUp() |
|
33
|
|
|
{ |
|
34
|
|
|
parent::setUp(); |
|
35
|
|
|
|
|
36
|
|
|
$this->_sniffFile = $this->sniffFile(self::TEST_FILE); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* testNewExecutionDirective |
|
41
|
|
|
* |
|
42
|
|
|
* @group newExecutionDirectives |
|
43
|
|
|
* |
|
44
|
|
|
* @dataProvider dataNewExecutionDirective |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $directive Name of the execution directive. |
|
47
|
|
|
* @param string $lastVersionBefore The PHP version just *before* the directive was introduced. |
|
48
|
|
|
* @param array $lines The line numbers in the test file where the error should occur. |
|
49
|
|
|
* @param string $okVersion A PHP version in which the directive was ok to be used. |
|
50
|
|
|
* @param string $conditionalVersion Optional. A PHP version in which the directive was conditionaly available. |
|
51
|
|
|
* @param string $condition The availability condition. |
|
52
|
|
|
* |
|
53
|
|
|
* @return void |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testNewExecutionDirective($directive, $lastVersionBefore, $lines, $okVersion, $conditionalVersion = null, $condition = null) |
|
56
|
|
|
{ |
|
57
|
|
|
$file = $this->sniffFile(self::TEST_FILE, $lastVersionBefore); |
|
58
|
|
|
foreach ($lines as $line) { |
|
59
|
|
|
$this->assertError($file, $line, "Directive {$directive} is not present in PHP version {$lastVersionBefore} or earlier"); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
if (isset($conditionalVersion, $condition)) { |
|
63
|
|
|
$file = $this->sniffFile(self::TEST_FILE, $conditionalVersion); |
|
64
|
|
|
foreach ($lines as $line) { |
|
65
|
|
|
$this->assertWarning($file, $line, "Directive {$directive} is present in PHP version {$conditionalVersion} but will be disregarded unless PHP is compiled with {$condition}"); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$file = $this->sniffFile(self::TEST_FILE, $okVersion); |
|
70
|
|
|
foreach ($lines as $line) { |
|
71
|
|
|
$this->assertNoViolation($file, $line); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Data provider. |
|
77
|
|
|
* |
|
78
|
|
|
* @see testNewExecutionDirectivs() |
|
79
|
|
|
* |
|
80
|
|
|
* @return array |
|
81
|
|
|
*/ |
|
82
|
|
|
public function dataNewExecutionDirective() |
|
83
|
|
|
{ |
|
84
|
|
|
return array( |
|
85
|
|
|
array('ticks', '3.1', array(6, 7), '4.0'), |
|
86
|
|
|
array('encoding', '5.2', array(8), '5.4', '5.3', '--enable-zend-multibyte'), |
|
87
|
|
|
array('strict_types', '5.6', array(9), '7.0'), |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* testInvalidDirectiveValue |
|
94
|
|
|
* |
|
95
|
|
|
* @group newExecutionDirectives |
|
96
|
|
|
* |
|
97
|
|
|
* @dataProvider dataInvalidDirectiveValue |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $directive Name of the execution directive. |
|
100
|
|
|
* @param string $value The value. |
|
101
|
|
|
* @param int $line Line number where the error should occur. |
|
102
|
|
|
* |
|
103
|
|
|
* @return void |
|
104
|
|
|
*/ |
|
105
|
|
|
public function testInvalidDirectiveValue($directive, $value, $line) |
|
106
|
|
|
{ |
|
107
|
|
|
$this->assertError($this->_sniffFile, $line, "The execution directive {$directive} does not seem to have a valid value. Please review. Found: {$value}"); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* dataInvalidDirectiveValue |
|
112
|
|
|
* |
|
113
|
|
|
* @see testInvalidDirectiveValue() |
|
114
|
|
|
* |
|
115
|
|
|
* @return array |
|
116
|
|
|
*/ |
|
117
|
|
|
public function dataInvalidDirectiveValue() { |
|
118
|
|
|
return array( |
|
119
|
|
|
array('ticks', 'TICK_VALUE', 16), |
|
120
|
|
|
array('strict_types', 'false', 18), |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* testInvalidEncodingDirectiveValue |
|
127
|
|
|
* |
|
128
|
|
|
* @group newExecutionDirectives |
|
129
|
|
|
* |
|
130
|
|
|
* @requires function mb_list_encodings |
|
131
|
|
|
* |
|
132
|
|
|
* @dataProvider dataInvalidEncodingDirectiveValue |
|
133
|
|
|
* |
|
134
|
|
|
* @param string $directive Name of the execution directive. |
|
135
|
|
|
* @param string $value The value. |
|
136
|
|
|
* @param int $line Line number where the error should occur. |
|
137
|
|
|
* |
|
138
|
|
|
* @return void |
|
139
|
|
|
*/ |
|
140
|
|
|
public function testInvalidEncodingDirectiveValue($directive, $value, $line) |
|
141
|
|
|
{ |
|
142
|
|
|
$file = $this->sniffFile(self::TEST_FILE, '5.4'); |
|
143
|
|
|
$this->assertError($file, $line, "The execution directive {$directive} does not seem to have a valid value. Please review. Found: {$value}"); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
/** |
|
147
|
|
|
* dataInvalidEncodingDirectiveValue |
|
148
|
|
|
* |
|
149
|
|
|
* @see testInvalidEncodingDirectiveValue() |
|
150
|
|
|
* |
|
151
|
|
|
* @return array |
|
152
|
|
|
*/ |
|
153
|
|
|
public function dataInvalidEncodingDirectiveValue() { |
|
154
|
|
|
return array( |
|
155
|
|
|
array('encoding', 'invalid', 17), |
|
156
|
|
|
); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* testInvalidDirective |
|
162
|
|
|
* |
|
163
|
|
|
* @group newExecutionDirectives |
|
164
|
|
|
* |
|
165
|
|
|
* @return void |
|
166
|
|
|
*/ |
|
167
|
|
|
public function testInvalidDirective() |
|
168
|
|
|
{ |
|
169
|
|
|
$this->assertError($this->_sniffFile, 22, 'Declare can only be used with the directives ticks, encoding, strict_types. Found: invalid'); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* testIncompleteDirective |
|
175
|
|
|
* |
|
176
|
|
|
* @group newExecutionDirectives |
|
177
|
|
|
* |
|
178
|
|
|
* @return void |
|
179
|
|
|
*/ |
|
180
|
|
|
public function testIncompleteDirective() |
|
181
|
|
|
{ |
|
182
|
|
|
$this->assertNoViolation($this->_sniffFile, 25); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
|