@@ -33,18 +33,7 @@ public function testBasicFunction()
33
33
'has_body ' => true ,
34
34
];
35
35
36
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
37
- $ function = self ::$ phpcsFile ->findPrevious (
38
- T_COMMENT ,
39
- $ start ,
40
- null ,
41
- false ,
42
- '/* testBasicFunction */ '
43
- );
44
-
45
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 2 ));
46
- unset($ found ['return_type_token ' ]);
47
- $ this ->assertSame ($ expected , $ found );
36
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
48
37
49
38
}//end testBasicFunction()
50
39
@@ -67,18 +56,7 @@ public function testReturnFunction()
67
56
'has_body ' => true ,
68
57
];
69
58
70
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
71
- $ function = self ::$ phpcsFile ->findPrevious (
72
- T_COMMENT ,
73
- $ start ,
74
- null ,
75
- false ,
76
- '/* testReturnFunction */ '
77
- );
78
-
79
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 2 ));
80
- unset($ found ['return_type_token ' ]);
81
- $ this ->assertSame ($ expected , $ found );
59
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
82
60
83
61
}//end testReturnFunction()
84
62
@@ -101,18 +79,7 @@ public function testNestedClosure()
101
79
'has_body ' => true ,
102
80
];
103
81
104
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
105
- $ function = self ::$ phpcsFile ->findPrevious (
106
- T_COMMENT ,
107
- $ start ,
108
- null ,
109
- false ,
110
- '/* testNestedClosure */ '
111
- );
112
-
113
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 1 ));
114
- unset($ found ['return_type_token ' ]);
115
- $ this ->assertSame ($ expected , $ found );
82
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
116
83
117
84
}//end testNestedClosure()
118
85
@@ -135,18 +102,7 @@ public function testBasicMethod()
135
102
'has_body ' => true ,
136
103
];
137
104
138
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
139
- $ function = self ::$ phpcsFile ->findPrevious (
140
- T_COMMENT ,
141
- $ start ,
142
- null ,
143
- false ,
144
- '/* testBasicMethod */ '
145
- );
146
-
147
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 3 ));
148
- unset($ found ['return_type_token ' ]);
149
- $ this ->assertSame ($ expected , $ found );
105
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
150
106
151
107
}//end testBasicMethod()
152
108
@@ -169,18 +125,7 @@ public function testPrivateStaticMethod()
169
125
'has_body ' => true ,
170
126
];
171
127
172
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
173
- $ function = self ::$ phpcsFile ->findPrevious (
174
- T_COMMENT ,
175
- $ start ,
176
- null ,
177
- false ,
178
- '/* testPrivateStaticMethod */ '
179
- );
180
-
181
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 7 ));
182
- unset($ found ['return_type_token ' ]);
183
- $ this ->assertSame ($ expected , $ found );
128
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
184
129
185
130
}//end testPrivateStaticMethod()
186
131
@@ -203,18 +148,7 @@ public function testFinalMethod()
203
148
'has_body ' => true ,
204
149
];
205
150
206
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
207
- $ function = self ::$ phpcsFile ->findPrevious (
208
- T_COMMENT ,
209
- $ start ,
210
- null ,
211
- false ,
212
- '/* testFinalMethod */ '
213
- );
214
-
215
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 7 ));
216
- unset($ found ['return_type_token ' ]);
217
- $ this ->assertSame ($ expected , $ found );
151
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
218
152
219
153
}//end testFinalMethod()
220
154
@@ -237,18 +171,7 @@ public function testProtectedReturnMethod()
237
171
'has_body ' => true ,
238
172
];
239
173
240
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
241
- $ function = self ::$ phpcsFile ->findPrevious (
242
- T_COMMENT ,
243
- $ start ,
244
- null ,
245
- false ,
246
- '/* testProtectedReturnMethod */ '
247
- );
248
-
249
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 5 ));
250
- unset($ found ['return_type_token ' ]);
251
- $ this ->assertSame ($ expected , $ found );
174
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
252
175
253
176
}//end testProtectedReturnMethod()
254
177
@@ -271,18 +194,7 @@ public function testPublicReturnMethod()
271
194
'has_body ' => true ,
272
195
];
273
196
274
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
275
- $ function = self ::$ phpcsFile ->findPrevious (
276
- T_COMMENT ,
277
- $ start ,
278
- null ,
279
- false ,
280
- '/* testPublicReturnMethod */ '
281
- );
282
-
283
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 5 ));
284
- unset($ found ['return_type_token ' ]);
285
- $ this ->assertSame ($ expected , $ found );
197
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
286
198
287
199
}//end testPublicReturnMethod()
288
200
@@ -305,18 +217,7 @@ public function testNullableReturnMethod()
305
217
'has_body ' => true ,
306
218
];
307
219
308
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
309
- $ function = self ::$ phpcsFile ->findPrevious (
310
- T_COMMENT ,
311
- $ start ,
312
- null ,
313
- false ,
314
- '/* testNullableReturnMethod */ '
315
- );
316
-
317
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 5 ));
318
- unset($ found ['return_type_token ' ]);
319
- $ this ->assertSame ($ expected , $ found );
220
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
320
221
321
222
}//end testNullableReturnMethod()
322
223
@@ -339,18 +240,7 @@ public function testMessyNullableReturnMethod()
339
240
'has_body ' => true ,
340
241
];
341
242
342
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
343
- $ function = self ::$ phpcsFile ->findPrevious (
344
- T_COMMENT ,
345
- $ start ,
346
- null ,
347
- false ,
348
- '/* testMessyNullableReturnMethod */ '
349
- );
350
-
351
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 5 ));
352
- unset($ found ['return_type_token ' ]);
353
- $ this ->assertSame ($ expected , $ found );
243
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
354
244
355
245
}//end testMessyNullableReturnMethod()
356
246
@@ -373,18 +263,7 @@ public function testReturnNamespace()
373
263
'has_body ' => true ,
374
264
];
375
265
376
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
377
- $ function = self ::$ phpcsFile ->findPrevious (
378
- T_COMMENT ,
379
- $ start ,
380
- null ,
381
- false ,
382
- '/* testReturnNamespace */ '
383
- );
384
-
385
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 3 ));
386
- unset($ found ['return_type_token ' ]);
387
- $ this ->assertSame ($ expected , $ found );
266
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
388
267
389
268
}//end testReturnNamespace()
390
269
@@ -407,18 +286,7 @@ public function testReturnMultilineNamespace()
407
286
'has_body ' => true ,
408
287
];
409
288
410
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
411
- $ function = self ::$ phpcsFile ->findPrevious (
412
- T_COMMENT ,
413
- $ start ,
414
- null ,
415
- false ,
416
- '/* testReturnMultilineNamespace */ '
417
- );
418
-
419
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 3 ));
420
- unset($ found ['return_type_token ' ]);
421
- $ this ->assertSame ($ expected , $ found );
289
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
422
290
423
291
}//end testReturnMultilineNamespace()
424
292
@@ -441,18 +309,7 @@ public function testAbstractMethod()
441
309
'has_body ' => false ,
442
310
];
443
311
444
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
445
- $ function = self ::$ phpcsFile ->findPrevious (
446
- T_COMMENT ,
447
- $ start ,
448
- null ,
449
- false ,
450
- '/* testAbstractMethod */ '
451
- );
452
-
453
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 5 ));
454
- unset($ found ['return_type_token ' ]);
455
- $ this ->assertSame ($ expected , $ found );
312
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
456
313
457
314
}//end testAbstractMethod()
458
315
@@ -475,18 +332,7 @@ public function testAbstractReturnMethod()
475
332
'has_body ' => false ,
476
333
];
477
334
478
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
479
- $ function = self ::$ phpcsFile ->findPrevious (
480
- T_COMMENT ,
481
- $ start ,
482
- null ,
483
- false ,
484
- '/* testAbstractReturnMethod */ '
485
- );
486
-
487
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 7 ));
488
- unset($ found ['return_type_token ' ]);
489
- $ this ->assertSame ($ expected , $ found );
335
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
490
336
491
337
}//end testAbstractReturnMethod()
492
338
@@ -509,20 +355,27 @@ public function testInterfaceMethod()
509
355
'has_body ' => false ,
510
356
];
511
357
512
- $ start = (self ::$ phpcsFile ->numTokens - 1 );
513
- $ function = self ::$ phpcsFile ->findPrevious (
514
- T_COMMENT ,
515
- $ start ,
516
- null ,
517
- false ,
518
- '/* testInterfaceMethod */ '
519
- );
520
-
521
- $ found = self ::$ phpcsFile ->getMethodProperties (($ function + 3 ));
522
- unset($ found ['return_type_token ' ]);
523
- $ this ->assertSame ($ expected , $ found );
358
+ $ this ->getMethodPropertiesTestHelper ('/* ' .__FUNCTION__ .' */ ' , $ expected );
524
359
525
360
}//end testInterfaceMethod()
526
361
527
362
363
+ /**
364
+ * Test helper.
365
+ *
366
+ * @param string $commentString The comment which preceeds the test.
367
+ * @param array $expected The expected function output.
368
+ *
369
+ * @return void
370
+ */
371
+ private function getMethodPropertiesTestHelper ($ commentString , $ expected )
372
+ {
373
+ $ function = $ this ->getTargetToken ($ commentString , [T_FUNCTION , T_CLOSURE ]);
374
+ $ found = self ::$ phpcsFile ->getMethodProperties ($ function );
375
+
376
+ $ this ->assertArraySubset ($ expected , $ found , true );
377
+
378
+ }//end getMethodPropertiesTestHelper()
379
+
380
+
528
381
}//end class
0 commit comments