@@ -32,23 +32,7 @@ public function testPassByReference()
32
32
'nullable_type ' => false ,
33
33
];
34
34
35
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
36
- $ function = self ::$ phpcsFile ->findPrevious (
37
- T_COMMENT ,
38
- $ start ,
39
- null ,
40
- false ,
41
- '/* testPassByReference */ '
42
- );
43
-
44
- $ found = self ::$ phpcsFile ->getMethodParameters (($ function + 2 ));
45
- unset($ found [0 ]['token ' ]);
46
- unset($ found [0 ]['type_hint_token ' ]);
47
- unset($ found [0 ]['type_hint_end_token ' ]);
48
- unset($ found [0 ]['comma_token ' ]);
49
- unset($ found [0 ]['reference_token ' ]);
50
- unset($ found [0 ]['variadic_token ' ]);
51
- $ this ->assertSame ($ expected , $ found );
35
+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
52
36
53
37
}//end testPassByReference()
54
38
@@ -70,23 +54,7 @@ public function testArrayHint()
70
54
'nullable_type ' => false ,
71
55
];
72
56
73
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
74
- $ function = self ::$ phpcsFile ->findPrevious (
75
- T_COMMENT ,
76
- $ start ,
77
- null ,
78
- false ,
79
- '/* testArrayHint */ '
80
- );
81
-
82
- $ found = self ::$ phpcsFile ->getMethodParameters (($ function + 2 ));
83
- unset($ found [0 ]['token ' ]);
84
- unset($ found [0 ]['type_hint_token ' ]);
85
- unset($ found [0 ]['type_hint_end_token ' ]);
86
- unset($ found [0 ]['comma_token ' ]);
87
- unset($ found [0 ]['reference_token ' ]);
88
- unset($ found [0 ]['variadic_token ' ]);
89
- $ this ->assertSame ($ expected , $ found );
57
+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
90
58
91
59
}//end testArrayHint()
92
60
@@ -117,29 +85,7 @@ public function testTypeHint()
117
85
'nullable_type ' => false ,
118
86
];
119
87
120
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
121
- $ function = self ::$ phpcsFile ->findPrevious (
122
- T_COMMENT ,
123
- $ start ,
124
- null ,
125
- false ,
126
- '/* testTypeHint */ '
127
- );
128
-
129
- $ found = self ::$ phpcsFile ->getMethodParameters (($ function + 2 ));
130
- unset($ found [0 ]['token ' ]);
131
- unset($ found [1 ]['token ' ]);
132
- unset($ found [0 ]['type_hint_token ' ]);
133
- unset($ found [1 ]['type_hint_token ' ]);
134
- unset($ found [0 ]['type_hint_end_token ' ]);
135
- unset($ found [1 ]['type_hint_end_token ' ]);
136
- unset($ found [0 ]['comma_token ' ]);
137
- unset($ found [1 ]['comma_token ' ]);
138
- unset($ found [0 ]['reference_token ' ]);
139
- unset($ found [1 ]['reference_token ' ]);
140
- unset($ found [0 ]['variadic_token ' ]);
141
- unset($ found [1 ]['variadic_token ' ]);
142
- $ this ->assertSame ($ expected , $ found );
88
+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
143
89
144
90
}//end testTypeHint()
145
91
@@ -161,23 +107,7 @@ public function testSelfTypeHint()
161
107
'nullable_type ' => false ,
162
108
];
163
109
164
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
165
- $ function = self ::$ phpcsFile ->findPrevious (
166
- T_COMMENT ,
167
- $ start ,
168
- null ,
169
- false ,
170
- '/* testSelfTypeHint */ '
171
- );
172
-
173
- $ found = self ::$ phpcsFile ->getMethodParameters (($ function + 2 ));
174
- unset($ found [0 ]['token ' ]);
175
- unset($ found [0 ]['type_hint_token ' ]);
176
- unset($ found [0 ]['type_hint_end_token ' ]);
177
- unset($ found [0 ]['comma_token ' ]);
178
- unset($ found [0 ]['reference_token ' ]);
179
- unset($ found [0 ]['variadic_token ' ]);
180
- $ this ->assertSame ($ expected , $ found );
110
+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
181
111
182
112
}//end testSelfTypeHint()
183
113
@@ -208,29 +138,7 @@ public function testNullableTypeHint()
208
138
'nullable_type ' => true ,
209
139
];
210
140
211
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
212
- $ function = self ::$ phpcsFile ->findPrevious (
213
- T_COMMENT ,
214
- $ start ,
215
- null ,
216
- false ,
217
- '/* testNullableTypeHint */ '
218
- );
219
-
220
- $ found = self ::$ phpcsFile ->getMethodParameters (($ function + 2 ));
221
- unset($ found [0 ]['token ' ]);
222
- unset($ found [1 ]['token ' ]);
223
- unset($ found [0 ]['type_hint_token ' ]);
224
- unset($ found [1 ]['type_hint_token ' ]);
225
- unset($ found [0 ]['type_hint_end_token ' ]);
226
- unset($ found [1 ]['type_hint_end_token ' ]);
227
- unset($ found [0 ]['comma_token ' ]);
228
- unset($ found [1 ]['comma_token ' ]);
229
- unset($ found [0 ]['reference_token ' ]);
230
- unset($ found [1 ]['reference_token ' ]);
231
- unset($ found [0 ]['variadic_token ' ]);
232
- unset($ found [1 ]['variadic_token ' ]);
233
- $ this ->assertSame ($ expected , $ found );
141
+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
234
142
235
143
}//end testNullableTypeHint()
236
144
@@ -252,23 +160,7 @@ public function testVariable()
252
160
'nullable_type ' => false ,
253
161
];
254
162
255
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
256
- $ function = self ::$ phpcsFile ->findPrevious (
257
- T_COMMENT ,
258
- $ start ,
259
- null ,
260
- false ,
261
- '/* testVariable */ '
262
- );
263
-
264
- $ found = self ::$ phpcsFile ->getMethodParameters (($ function + 2 ));
265
- unset($ found [0 ]['token ' ]);
266
- unset($ found [0 ]['type_hint_token ' ]);
267
- unset($ found [0 ]['type_hint_end_token ' ]);
268
- unset($ found [0 ]['comma_token ' ]);
269
- unset($ found [0 ]['reference_token ' ]);
270
- unset($ found [0 ]['variadic_token ' ]);
271
- $ this ->assertSame ($ expected , $ found );
163
+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
272
164
273
165
}//end testVariable()
274
166
@@ -291,25 +183,7 @@ public function testSingleDefaultValue()
291
183
'nullable_type ' => false ,
292
184
];
293
185
294
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
295
- $ function = self ::$ phpcsFile ->findPrevious (
296
- T_COMMENT ,
297
- $ start ,
298
- null ,
299
- false ,
300
- '/* testSingleDefaultValue */ '
301
- );
302
-
303
- $ found = self ::$ phpcsFile ->getMethodParameters (($ function + 2 ));
304
- unset($ found [0 ]['token ' ]);
305
- unset($ found [0 ]['type_hint_token ' ]);
306
- unset($ found [0 ]['type_hint_end_token ' ]);
307
- unset($ found [0 ]['comma_token ' ]);
308
- unset($ found [0 ]['reference_token ' ]);
309
- unset($ found [0 ]['variadic_token ' ]);
310
- unset($ found [0 ]['default_token ' ]);
311
- unset($ found [0 ]['default_equal_token ' ]);
312
- $ this ->assertSame ($ expected , $ found );
186
+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
313
187
314
188
}//end testSingleDefaultValue()
315
189
@@ -341,33 +215,7 @@ public function testDefaultValues()
341
215
'nullable_type ' => false ,
342
216
];
343
217
344
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
345
- $ function = self ::$ phpcsFile ->findPrevious (
346
- T_COMMENT ,
347
- $ start ,
348
- null ,
349
- false ,
350
- '/* testDefaultValues */ '
351
- );
352
-
353
- $ found = self ::$ phpcsFile ->getMethodParameters (($ function + 2 ));
354
- unset($ found [0 ]['token ' ]);
355
- unset($ found [1 ]['token ' ]);
356
- unset($ found [0 ]['type_hint_token ' ]);
357
- unset($ found [1 ]['type_hint_token ' ]);
358
- unset($ found [0 ]['type_hint_end_token ' ]);
359
- unset($ found [1 ]['type_hint_end_token ' ]);
360
- unset($ found [0 ]['comma_token ' ]);
361
- unset($ found [1 ]['comma_token ' ]);
362
- unset($ found [0 ]['reference_token ' ]);
363
- unset($ found [1 ]['reference_token ' ]);
364
- unset($ found [0 ]['variadic_token ' ]);
365
- unset($ found [1 ]['variadic_token ' ]);
366
- unset($ found [0 ]['default_token ' ]);
367
- unset($ found [1 ]['default_token ' ]);
368
- unset($ found [0 ]['default_equal_token ' ]);
369
- unset($ found [1 ]['default_equal_token ' ]);
370
- $ this ->assertSame ($ expected , $ found );
218
+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
371
219
372
220
}//end testDefaultValues()
373
221
@@ -390,27 +238,27 @@ public function testBitwiseAndConstantExpressionDefaultValue()
390
238
'nullable_type ' => false ,
391
239
];
392
240
393
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
394
- $ function = self ::$ phpcsFile ->findPrevious (
395
- T_COMMENT ,
396
- $ start ,
397
- null ,
398
- false ,
399
- '/* testBitwiseAndConstantExpressionDefaultValue */ '
400
- );
401
-
402
- $ found = self ::$ phpcsFile ->getMethodParameters (($ function + 2 ));
403
- unset($ found [0 ]['token ' ]);
404
- unset($ found [0 ]['type_hint_token ' ]);
405
- unset($ found [0 ]['type_hint_end_token ' ]);
406
- unset($ found [0 ]['comma_token ' ]);
407
- unset($ found [0 ]['reference_token ' ]);
408
- unset($ found [0 ]['variadic_token ' ]);
409
- unset($ found [0 ]['default_token ' ]);
410
- unset($ found [0 ]['default_equal_token ' ]);
411
- $ this ->assertSame ($ expected , $ found );
241
+ $ this ->getMethodParametersTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
412
242
413
243
}//end testBitwiseAndConstantExpressionDefaultValue()
414
244
415
245
246
+ /**
247
+ * Test helper.
248
+ *
249
+ * @param string $commentString The comment which preceeds the test.
250
+ * @param array $expected The expected function output.
251
+ *
252
+ * @return void
253
+ */
254
+ private function getMethodParametersTestHelper ($ commentString , $ expected )
255
+ {
256
+ $ function = $ this ->getTargetToken ($ commentString , [T_FUNCTION ]);
257
+ $ found = self ::$ phpcsFile ->getMethodParameters ($ function );
258
+
259
+ $ this ->assertArraySubset ($ expected , $ found , true );
260
+
261
+ }//end getMethodParametersTestHelper()
262
+
263
+
416
264
}//end class
0 commit comments