1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CodingStandard_Tests_Commenting_FunctionCommentUnitTest. |
4
|
|
|
* |
5
|
|
|
* PHP version 5 |
6
|
|
|
* |
7
|
|
|
* @category PHP |
8
|
|
|
* @package PHP_CodeSniffer |
9
|
|
|
* @author Greg Sherwood <[email protected]> |
10
|
|
|
* @author Marc McIntyre <[email protected]> |
11
|
|
|
* @author Alexander Obuhovich <[email protected]> |
12
|
|
|
* @license https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause |
13
|
|
|
* @link https://github.com/aik099/CodingStandard |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace CodingStandard\Tests\Commenting; |
17
|
|
|
|
18
|
|
|
use PHP_CodeSniffer\Config; |
19
|
|
|
use TestSuite\AbstractSniffUnitTest; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Unit test class for FunctionCommentSniff. |
23
|
|
|
* |
24
|
|
|
* @category PHP |
25
|
|
|
* @package PHP_CodeSniffer |
26
|
|
|
* @author Greg Sherwood <[email protected]> |
27
|
|
|
* @author Marc McIntyre <[email protected]> |
28
|
|
|
* @author Alexander Obuhovich <[email protected]> |
29
|
|
|
* @license https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause |
30
|
|
|
* @link https://github.com/aik099/CodingStandard |
31
|
|
|
*/ |
32
|
|
|
class FunctionCommentUnitTest extends AbstractSniffUnitTest |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Returns the lines where errors should occur. |
37
|
|
|
* |
38
|
|
|
* The key of the array should represent the line number and the value |
39
|
|
|
* should represent the number of errors that should occur on that line. |
40
|
|
|
* |
41
|
|
|
* @param string $testFile Name of the file with test data. |
42
|
|
|
* |
43
|
|
|
* @return array(int => int) |
44
|
|
|
*/ |
45
|
|
|
public function getErrorList($testFile) |
46
|
|
|
{ |
47
|
|
|
if ($testFile === 'FunctionCommentUnitTest.1.inc') { |
48
|
|
|
$errors = array( |
49
|
|
|
5 => 1, |
50
|
|
|
10 => 3, |
51
|
|
|
12 => 2, |
52
|
|
|
13 => 2, |
53
|
|
|
14 => 1, |
54
|
|
|
15 => 1, |
55
|
|
|
28 => 1, |
56
|
|
|
43 => 1, |
57
|
|
|
76 => 1, |
58
|
|
|
87 => 1, |
59
|
|
|
103 => 1, |
60
|
|
|
109 => 1, |
61
|
|
|
112 => 1, |
62
|
|
|
122 => 1, |
63
|
|
|
123 => 3, |
64
|
|
|
124 => 2, |
65
|
|
|
125 => 1, |
66
|
|
|
126 => 1, |
67
|
|
|
137 => 4, |
68
|
|
|
138 => 4, |
69
|
|
|
139 => 4, |
70
|
|
|
143 => 2, |
71
|
|
|
152 => 1, |
72
|
|
|
155 => 2, |
73
|
|
|
159 => 1, |
74
|
|
|
166 => 1, |
75
|
|
|
173 => 1, |
76
|
|
|
183 => 1, |
77
|
|
|
190 => 2, |
78
|
|
|
193 => 2, |
79
|
|
|
196 => 1, |
80
|
|
|
199 => 2, |
81
|
|
|
210 => 1, |
82
|
|
|
211 => 1, |
83
|
|
|
222 => 1, |
84
|
|
|
223 => 1, |
85
|
|
|
224 => 1, |
86
|
|
|
225 => 1, |
87
|
|
|
226 => 1, |
88
|
|
|
227 => 1, |
89
|
|
|
230 => 2, |
90
|
|
|
232 => 2, |
91
|
|
|
246 => 1, |
92
|
|
|
248 => 4, |
93
|
|
|
261 => 1, |
94
|
|
|
263 => 1, |
95
|
|
|
276 => 1, |
96
|
|
|
277 => 1, |
97
|
|
|
278 => 1, |
98
|
|
|
279 => 1, |
99
|
|
|
280 => 1, |
100
|
|
|
281 => 1, |
101
|
|
|
284 => 1, |
102
|
|
|
286 => 7, |
103
|
|
|
294 => 1, |
104
|
|
|
302 => 1, |
105
|
|
|
312 => 1, |
106
|
|
|
358 => 1, |
107
|
|
|
359 => 2, |
108
|
|
|
372 => 1, |
109
|
|
|
373 => 1, |
110
|
|
|
387 => 1, |
111
|
|
|
407 => 1, |
112
|
|
|
441 => 1, |
113
|
|
|
500 => 1, |
114
|
|
|
526 => 1, |
115
|
|
|
548 => 1, |
116
|
|
|
641 => 1, |
117
|
|
|
669 => 1, |
118
|
|
|
688 => 1, |
119
|
|
|
744 => 1, |
120
|
|
|
748 => 1, |
121
|
|
|
767 => 1, |
122
|
|
|
789 => 1, |
123
|
|
|
792 => 1, |
124
|
|
|
794 => 1, |
125
|
|
|
797 => 1, |
126
|
|
|
801 => 1, |
127
|
|
|
828 => 1, |
128
|
|
|
840 => 1, |
129
|
|
|
852 => 1, |
130
|
|
|
864 => 1, |
131
|
|
|
886 => 1, |
132
|
|
|
888 => 1, |
133
|
|
|
890 => 1, |
134
|
|
|
978 => 1, |
135
|
|
|
997 => 1, |
136
|
|
|
); |
137
|
|
|
|
138
|
|
|
// Scalar type hints only work from PHP 7 onwards. |
139
|
|
|
if (PHP_VERSION_ID >= 70000) { |
140
|
|
|
$errors[17] = 3; |
141
|
|
|
$errors[128] = 1; |
142
|
|
|
$errors[143] = 3; |
143
|
|
|
$errors[161] = 2; |
144
|
|
|
$errors[201] = 1; |
145
|
|
|
$errors[232] = 7; |
146
|
|
|
$errors[363] = 3; |
147
|
|
|
$errors[377] = 1; |
148
|
|
|
$errors[575] = 2; |
149
|
|
|
$errors[627] = 1; |
150
|
|
|
$errors[1002] = 1; |
151
|
|
|
} else { |
152
|
|
|
$errors[729] = 4; |
153
|
|
|
$errors[740] = 2; |
154
|
|
|
$errors[752] = 2; |
155
|
|
|
$errors[982] = 1; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
// Object type hints only work from PHP 7.2 onwards. |
159
|
|
|
if (PHP_VERSION_ID >= 70200) { |
160
|
|
|
$errors[627] = 2; |
161
|
|
|
} else { |
162
|
|
|
$errors[992] = 2; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
// === New error types added over existing Squiz sniff ===. |
166
|
|
|
|
167
|
|
|
// Short comment validation for non-In-Portal event methods. |
168
|
|
|
$errors[6] = 1; |
169
|
|
|
$errors[52] = 1; |
170
|
|
|
$errors[110] = 1; |
171
|
|
|
$errors[180] = 1; |
172
|
|
|
// Reports "@throws" tag usage without exception being thrown inside a method. |
173
|
|
|
$errors[15] += 1; |
174
|
|
|
$errors[199] += 1; |
175
|
|
|
$errors[669] += 1; |
176
|
|
|
|
177
|
|
|
return $errors; |
178
|
|
|
} elseif ($testFile === 'FunctionCommentUnitTest.2.inc') { |
179
|
|
|
return array( |
180
|
|
|
// Square bracket not allowed as function short description start. |
181
|
|
|
7 => 1, |
182
|
|
|
|
183
|
|
|
// Square bracket is allowed as event short description start. |
184
|
|
|
17 => 0, |
185
|
|
|
|
186
|
|
|
// Incorrect event short description start. |
187
|
|
|
27 => 1, |
188
|
|
|
); |
189
|
|
|
} elseif ($testFile === 'FunctionCommentUnitTest.3.inc') { |
190
|
|
|
$errors = array( |
191
|
|
|
// Square bracket not allowed as function short description start. |
192
|
|
|
7 => 1, |
193
|
|
|
|
194
|
|
|
// Square bracket is allowed as event short description start. |
195
|
|
|
17 => 0, |
196
|
|
|
|
197
|
|
|
// Incorrect event short description start. |
198
|
|
|
27 => 1, |
199
|
|
|
); |
200
|
|
|
|
201
|
|
|
return $errors; |
202
|
|
|
} elseif ($testFile === 'FunctionCommentUnitTest.4.inc') { |
203
|
|
|
$errors = array( |
204
|
|
|
// Return type "$this" used instead of static/self. |
205
|
|
|
6 => 1, |
206
|
|
|
); |
207
|
|
|
|
208
|
|
|
// Scalar type hints only work from PHP 7 onwards. |
209
|
|
|
if (PHP_VERSION_ID >= 70000) { |
210
|
|
|
$errors[23] = 1; |
211
|
|
|
$errors[38] = 1; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
return $errors; |
215
|
|
|
}//end if |
216
|
|
|
|
217
|
|
|
return array(); |
218
|
|
|
}//end getErrorList() |
219
|
|
|
|
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Returns the lines where warnings should occur. |
223
|
|
|
* |
224
|
|
|
* The key of the array should represent the line number and the value |
225
|
|
|
* should represent the number of warnings that should occur on that line. |
226
|
|
|
* |
227
|
|
|
* @param string $testFile Name of the file with test data. |
228
|
|
|
* |
229
|
|
|
* @return array(int => int) |
230
|
|
|
*/ |
231
|
|
|
public function getWarningList($testFile) |
232
|
|
|
{ |
233
|
|
|
return array(); |
234
|
|
|
}//end getWarningList() |
235
|
|
|
|
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Get a list of CLI values to set before the file is tested. |
239
|
|
|
* |
240
|
|
|
* @param string $filename The name of the file being tested. |
241
|
|
|
* @param Config $config The config data for the run. |
242
|
|
|
* |
243
|
|
|
* @return void |
244
|
|
|
*/ |
245
|
|
|
public function setCliValues($filename, Config $config) |
246
|
|
|
{ |
247
|
|
|
// Don't replace PHP version for test fixture from original sniff. |
248
|
|
|
if ($filename === 'FunctionCommentUnitTest.1.inc') { |
249
|
|
|
$config->setConfigData('php_version', null, true); |
250
|
|
|
return; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
// Replace PHP version for test fixture, that are custom to this standard. |
254
|
|
|
parent::setCliValues($filename, $config); |
255
|
|
|
}//end setCliValues() |
256
|
|
|
}//end class |
257
|
|
|
|