@@ -22,11 +22,10 @@ class FindEndOfStatementTest extends AbstractMethodUnitTest
22
22
*/
23
23
public function testSimpleAssignment ()
24
24
{
25
- $ start = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testSimpleAssignment */ ' ) + 2 );
25
+ $ start = $ this -> getTargetToken ( '/* testSimpleAssignment */ ' , T_VARIABLE );
26
26
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
27
27
28
- $ tokens = self ::$ phpcsFile ->getTokens ();
29
- $ this ->assertSame ($ tokens [($ start + 5 )], $ tokens [$ found ]);
28
+ $ this ->assertSame (($ start + 5 ), $ found );
30
29
31
30
}//end testSimpleAssignment()
32
31
@@ -38,11 +37,10 @@ public function testSimpleAssignment()
38
37
*/
39
38
public function testControlStructure ()
40
39
{
41
- $ start = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testControlStructure */ ' ) + 2 );
40
+ $ start = $ this -> getTargetToken ( '/* testControlStructure */ ' , T_WHILE );
42
41
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
43
42
44
- $ tokens = self ::$ phpcsFile ->getTokens ();
45
- $ this ->assertSame ($ tokens [($ start + 6 )], $ tokens [$ found ]);
43
+ $ this ->assertSame (($ start + 6 ), $ found );
46
44
47
45
}//end testControlStructure()
48
46
@@ -54,11 +52,10 @@ public function testControlStructure()
54
52
*/
55
53
public function testClosureAssignment ()
56
54
{
57
- $ start = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testClosureAssignment */ ' ) + 2 );
55
+ $ start = $ this -> getTargetToken ( '/* testClosureAssignment */ ' , T_VARIABLE , ' $a ' );
58
56
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
59
57
60
- $ tokens = self ::$ phpcsFile ->getTokens ();
61
- $ this ->assertSame ($ tokens [($ start + 13 )], $ tokens [$ found ]);
58
+ $ this ->assertSame (($ start + 13 ), $ found );
62
59
63
60
}//end testClosureAssignment()
64
61
@@ -71,25 +68,22 @@ public function testClosureAssignment()
71
68
public function testHeredocFunctionArg ()
72
69
{
73
70
// Find the end of the function.
74
- $ start = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testHeredocFunctionArg */ ' ) + 2 );
71
+ $ start = $ this -> getTargetToken ( '/* testHeredocFunctionArg */ ' , T_STRING , ' myFunction ' );
75
72
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
76
73
77
- $ tokens = self ::$ phpcsFile ->getTokens ();
78
- $ this ->assertSame ($ tokens [($ start + 10 )], $ tokens [$ found ]);
74
+ $ this ->assertSame (($ start + 10 ), $ found );
79
75
80
76
// Find the end of the heredoc.
81
77
$ start += 2 ;
82
78
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
83
79
84
- $ tokens = self ::$ phpcsFile ->getTokens ();
85
- $ this ->assertSame ($ tokens [($ start + 4 )], $ tokens [$ found ]);
80
+ $ this ->assertSame (($ start + 4 ), $ found );
86
81
87
82
// Find the end of the last arg.
88
83
$ start = ($ found + 2 );
89
84
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
90
85
91
- $ tokens = self ::$ phpcsFile ->getTokens ();
92
- $ this ->assertSame ($ tokens [$ start ], $ tokens [$ found ]);
86
+ $ this ->assertSame ($ start , $ found );
93
87
94
88
}//end testHeredocFunctionArg()
95
89
@@ -102,25 +96,22 @@ public function testHeredocFunctionArg()
102
96
public function testSwitch ()
103
97
{
104
98
// Find the end of the switch.
105
- $ start = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testSwitch */ ' ) + 2 );
99
+ $ start = $ this -> getTargetToken ( '/* testSwitch */ ' , T_SWITCH );
106
100
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
107
101
108
- $ tokens = self ::$ phpcsFile ->getTokens ();
109
- $ this ->assertSame ($ tokens [($ start + 28 )], $ tokens [$ found ]);
102
+ $ this ->assertSame (($ start + 28 ), $ found );
110
103
111
104
// Find the end of the case.
112
105
$ start += 9 ;
113
106
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
114
107
115
- $ tokens = self ::$ phpcsFile ->getTokens ();
116
- $ this ->assertSame ($ tokens [($ start + 8 )], $ tokens [$ found ]);
108
+ $ this ->assertSame (($ start + 8 ), $ found );
117
109
118
110
// Find the end of default case.
119
111
$ start += 11 ;
120
112
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
121
113
122
- $ tokens = self ::$ phpcsFile ->getTokens ();
123
- $ this ->assertSame ($ tokens [($ start + 6 )], $ tokens [$ found ]);
114
+ $ this ->assertSame (($ start + 6 ), $ found );
124
115
125
116
}//end testSwitch()
126
117
@@ -133,25 +124,22 @@ public function testSwitch()
133
124
public function testStatementAsArrayValue ()
134
125
{
135
126
// Test short array syntax.
136
- $ start = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testStatementAsArrayValue */ ' ) + 7 );
127
+ $ start = $ this -> getTargetToken ( '/* testStatementAsArrayValue */ ' , T_NEW );
137
128
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
138
129
139
- $ tokens = self ::$ phpcsFile ->getTokens ();
140
- $ this ->assertSame ($ tokens [($ start + 2 )], $ tokens [$ found ]);
130
+ $ this ->assertSame (($ start + 2 ), $ found );
141
131
142
132
// Test long array syntax.
143
133
$ start += 12 ;
144
134
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
145
135
146
- $ tokens = self ::$ phpcsFile ->getTokens ();
147
- $ this ->assertSame ($ tokens [($ start + 2 )], $ tokens [$ found ]);
136
+ $ this ->assertSame (($ start + 2 ), $ found );
148
137
149
138
// Test same statement outside of array.
150
139
$ start += 10 ;
151
140
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
152
141
153
- $ tokens = self ::$ phpcsFile ->getTokens ();
154
- $ this ->assertSame ($ tokens [($ start + 3 )], $ tokens [$ found ]);
142
+ $ this ->assertSame (($ start + 3 ), $ found );
155
143
156
144
}//end testStatementAsArrayValue()
157
145
@@ -163,27 +151,25 @@ public function testStatementAsArrayValue()
163
151
*/
164
152
public function testUseGroup ()
165
153
{
166
- $ start = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testUseGroup */ ' ) + 2 );
154
+ $ start = $ this -> getTargetToken ( '/* testUseGroup */ ' , T_USE );
167
155
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
168
156
169
- $ tokens = self ::$ phpcsFile ->getTokens ();
170
- $ this ->assertSame ($ tokens [($ start + 23 )], $ tokens [$ found ]);
157
+ $ this ->assertSame (($ start + 23 ), $ found );
171
158
172
159
}//end testUseGroup()
173
160
174
161
175
162
/**
176
- * Test a use group .
163
+ * Test arrow function as array value .
177
164
*
178
165
* @return void
179
166
*/
180
167
public function testArrowFunctionArrayValue ()
181
168
{
182
- $ start = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testArrowFunctionArrayValue */ ' ) + 7 );
169
+ $ start = $ this -> getTargetToken ( '/* testArrowFunctionArrayValue */ ' , T_FN );
183
170
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
184
171
185
- $ tokens = self ::$ phpcsFile ->getTokens ();
186
- $ this ->assertSame ($ tokens [($ start + 9 )], $ tokens [$ found ]);
172
+ $ this ->assertSame (($ start + 9 ), $ found );
187
173
188
174
}//end testArrowFunctionArrayValue()
189
175
@@ -195,8 +181,8 @@ public function testArrowFunctionArrayValue()
195
181
*/
196
182
public function testStaticArrowFunction ()
197
183
{
198
- $ static = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testStaticArrowFunction */ ' ) + 2 );
199
- $ fn = self :: $ phpcsFile -> findNext ( T_FN , ( $ static + 1 ) );
184
+ $ static = $ this -> getTargetToken ( '/* testStaticArrowFunction */ ' , T_STATIC );
185
+ $ fn = $ this -> getTargetToken ( ' /* testStaticArrowFunction */ ' , T_FN );
200
186
201
187
$ endOfStatementStatic = self ::$ phpcsFile ->findEndOfStatement ($ static );
202
188
$ endOfStatementFn = self ::$ phpcsFile ->findEndOfStatement ($ fn );
@@ -213,11 +199,10 @@ public function testStaticArrowFunction()
213
199
*/
214
200
public function testArrowFunctionReturnValue ()
215
201
{
216
- $ start = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testArrowFunctionReturnValue */ ' ) + 2 );
202
+ $ start = $ this -> getTargetToken ( '/* testArrowFunctionReturnValue */ ' , T_FN );
217
203
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
218
204
219
- $ tokens = self ::$ phpcsFile ->getTokens ();
220
- $ this ->assertSame ($ tokens [($ start + 18 )], $ tokens [$ found ]);
205
+ $ this ->assertSame (($ start + 18 ), $ found );
221
206
222
207
}//end testArrowFunctionReturnValue()
223
208
@@ -229,11 +214,10 @@ public function testArrowFunctionReturnValue()
229
214
*/
230
215
public function testArrowFunctionAsArgument ()
231
216
{
232
- $ start = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testArrowFunctionAsArgument */ ' ) + 10 );
217
+ $ start = $ this -> getTargetToken ( '/* testArrowFunctionAsArgument */ ' , T_FN );
233
218
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
234
219
235
- $ tokens = self ::$ phpcsFile ->getTokens ();
236
- $ this ->assertSame ($ tokens [($ start + 8 )], $ tokens [$ found ]);
220
+ $ this ->assertSame (($ start + 8 ), $ found );
237
221
238
222
}//end testArrowFunctionAsArgument()
239
223
@@ -245,11 +229,10 @@ public function testArrowFunctionAsArgument()
245
229
*/
246
230
public function testArrowFunctionWithArrayAsArgument ()
247
231
{
248
- $ start = ( self :: $ phpcsFile -> findNext ( T_COMMENT , 0 , null , false , '/* testArrowFunctionWithArrayAsArgument */ ' ) + 10 );
232
+ $ start = $ this -> getTargetToken ( '/* testArrowFunctionWithArrayAsArgument */ ' , T_FN );
249
233
$ found = self ::$ phpcsFile ->findEndOfStatement ($ start );
250
234
251
- $ tokens = self ::$ phpcsFile ->getTokens ();
252
- $ this ->assertSame ($ tokens [($ start + 17 )], $ tokens [$ found ]);
235
+ $ this ->assertSame (($ start + 17 ), $ found );
253
236
254
237
}//end testArrowFunctionWithArrayAsArgument()
255
238
0 commit comments