7
7
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
8
8
*/
9
9
10
- namespace PHP_CodeSniffer \Tests \Core \Tokenizer ;
10
+ namespace PHP_CodeSniffer \Tests \Core \Tokenizer \ PHP ;
11
11
12
+ use PHP_CodeSniffer \Tests \Core \Tokenizer \AbstractTokenizerTestCase ;
12
13
use PHP_CodeSniffer \Util \Tokens ;
13
14
14
15
final class DNFTypesTest extends AbstractTokenizerTestCase
@@ -18,17 +19,16 @@ final class DNFTypesTest extends AbstractTokenizerTestCase
18
19
/**
19
20
* Test that parentheses when **not** used in a type declaration are correctly tokenized.
20
21
*
21
- * @param string $testMarker The comment prefacing the target token.
22
- * @param int|false $owner Optional. The parentheses owner or false when no parentheses owner is expected.
23
- * @param bool $skipCheckInside Optional. Skip checking correct token type inside the parentheses.
24
- * Use judiciously for combined normal + DNF tests only.
22
+ * @param string $testMarker The comment prefacing the target token.
23
+ * @param bool $skipCheckInside Optional. Skip checking correct token type inside the parentheses.
24
+ * Use judiciously for combined normal + DNF tests only.
25
25
*
26
26
* @dataProvider dataNormalParentheses
27
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createParenthesisNestingMap
27
+ * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
28
28
*
29
29
* @return void
30
30
*/
31
- public function testNormalParentheses ($ testMarker , $ owner = false , $ skipCheckInside =false )
31
+ public function testNormalParentheses ($ testMarker , $ skipCheckInside =false )
32
32
{
33
33
$ tokens = $ this ->phpcsFile ->getTokens ();
34
34
@@ -39,40 +39,14 @@ public function testNormalParentheses($testMarker, $owner=false, $skipCheckInsid
39
39
$ this ->assertSame (T_OPEN_PARENTHESIS , $ opener ['code ' ], 'Token tokenized as ' .$ opener ['type ' ].', not T_OPEN_PARENTHESIS (code) ' );
40
40
$ this ->assertSame ('T_OPEN_PARENTHESIS ' , $ opener ['type ' ], 'Token tokenized as ' .$ opener ['type ' ].', not T_OPEN_PARENTHESIS (type) ' );
41
41
42
- if ($ owner !== false ) {
43
- $ this ->assertArrayHasKey ('parenthesis_owner ' , $ opener , 'Parenthesis owner is not set ' );
44
- $ this ->assertSame (($ openPtr + $ owner ), $ opener ['parenthesis_owner ' ], 'Opener parenthesis owner is not the expected token ' );
45
- } else {
46
- $ this ->assertArrayNotHasKey ('parenthesis_owner ' , $ opener , 'Parenthesis owner is set ' );
47
- }
48
-
49
- $ this ->assertArrayHasKey ('parenthesis_opener ' , $ opener , 'Parenthesis opener is not set ' );
50
- $ this ->assertArrayHasKey ('parenthesis_closer ' , $ opener , 'Parenthesis closer is not set ' );
51
- $ this ->assertSame ($ openPtr , $ opener ['parenthesis_opener ' ], 'Parenthesis opener is not the expected token ' );
52
-
53
42
$ closePtr = $ opener ['parenthesis_closer ' ];
54
43
$ closer = $ tokens [$ closePtr ];
55
44
56
45
$ this ->assertSame (') ' , $ closer ['content ' ], 'Content of type close parenthesis is not ")" ' );
57
46
$ this ->assertSame (T_CLOSE_PARENTHESIS , $ closer ['code ' ], 'Token tokenized as ' .$ closer ['type ' ].', not T_CLOSE_PARENTHESIS (code) ' );
58
47
$ this ->assertSame ('T_CLOSE_PARENTHESIS ' , $ closer ['type ' ], 'Token tokenized as ' .$ closer ['type ' ].', not T_CLOSE_PARENTHESIS (type) ' );
59
48
60
- if ($ owner !== false ) {
61
- $ this ->assertArrayHasKey ('parenthesis_owner ' , $ closer , 'Parenthesis owner is not set ' );
62
- $ this ->assertSame (($ openPtr + $ owner ), $ closer ['parenthesis_owner ' ], 'Closer parenthesis owner is not the expected token ' );
63
- } else {
64
- $ this ->assertArrayNotHasKey ('parenthesis_owner ' , $ closer , 'Parenthesis owner is set ' );
65
- }
66
-
67
- $ this ->assertArrayHasKey ('parenthesis_opener ' , $ closer , 'Parenthesis opener is not set ' );
68
- $ this ->assertArrayHasKey ('parenthesis_closer ' , $ closer , 'Parenthesis closer is not set ' );
69
- $ this ->assertSame ($ closePtr , $ closer ['parenthesis_closer ' ], 'Parenthesis closer is not the expected token ' );
70
-
71
49
for ($ i = ($ openPtr + 1 ); $ i < $ closePtr ; $ i ++) {
72
- $ this ->assertArrayHasKey ('nested_parenthesis ' , $ tokens [$ i ], "Nested parenthesis key not set on token $ i ( {$ tokens [$ i ]['type ' ]}) " );
73
- $ this ->assertArrayHasKey ($ openPtr , $ tokens [$ i ]['nested_parenthesis ' ], 'Nested parenthesis is missing target parentheses set ' );
74
- $ this ->assertSame ($ closePtr , $ tokens [$ i ]['nested_parenthesis ' ][$ openPtr ], 'Nested parenthesis closer not set correctly ' );
75
-
76
50
// If there are ampersands, make sure these are tokenized as bitwise and.
77
51
if ($ skipCheckInside === false && $ tokens [$ i ]['content ' ] === '& ' ) {
78
52
$ this ->assertSame (T_BITWISE_AND , $ tokens [$ i ]['code ' ], 'Token tokenized as ' .$ tokens [$ i ]['type ' ].', not T_BITWISE_AND (code) ' );
@@ -133,44 +107,36 @@ public static function dataNormalParentheses()
133
107
],
134
108
'parens with owner: function; & in default value ' => [
135
109
'testMarker ' => '/* testParensOwnerFunctionAmpersandInDefaultValue */ ' ,
136
- 'owner ' => -3 ,
137
110
],
138
111
'parens with owner: closure; param declared by & ref ' => [
139
112
'testMarker ' => '/* testParensOwnerClosureAmpersandParamRef */ ' ,
140
- 'owner ' => -1 ,
141
113
],
142
114
'parens with owner: if ' => [
143
115
'testMarker ' => '/* testParensOwnerIf */ ' ,
144
- 'owner ' => -2 ,
145
116
],
146
117
'parens without owner in if condition ' => [
147
118
'testMarker ' => '/* testParensNoOwnerInIfCondition */ ' ,
148
119
],
149
120
'parens with owner: for ' => [
150
121
'testMarker ' => '/* testParensOwnerFor */ ' ,
151
- 'owner ' => -2 ,
152
122
],
153
123
'parens without owner in for condition ' => [
154
124
'testMarker ' => '/* testParensNoOwnerInForCondition */ ' ,
155
125
],
156
126
'parens with owner: match ' => [
157
127
'testMarker ' => '/* testParensOwnerMatch */ ' ,
158
- 'owner ' => -1 ,
159
128
],
160
129
'parens with owner: array ' => [
161
130
'testMarker ' => '/* testParensOwnerArray */ ' ,
162
- 'owner ' => -2 ,
163
131
],
164
132
'parens without owner in array; function call with & in callable ' => [
165
133
'testMarker ' => '/* testParensNoOwnerFunctionCallWithAmpersandInCallable */ ' ,
166
134
],
167
135
'parens with owner: fn; & in return value ' => [
168
136
'testMarker ' => '/* testParensOwnerArrowFn */ ' ,
169
- 'owner ' => -1 ,
170
137
],
171
138
'parens with owner: list with reference vars ' => [
172
139
'testMarker ' => '/* testParensOwnerListWithRefVars */ ' ,
173
- 'owner ' => -1 ,
174
140
],
175
141
'parens without owner, function call with DNF look-a-like param ' => [
176
142
'testMarker ' => '/* testParensNoOwnerFunctionCallwithDNFLookALikeParam */ ' ,
@@ -199,11 +165,9 @@ public static function dataNormalParentheses()
199
165
],
200
166
'parens with owner: closure; & in default value ' => [
201
167
'testMarker ' => '/* testParensOwnerClosureAmpersandInDefaultValue */ ' ,
202
- 'owner ' => -2 ,
203
168
],
204
169
'parens with owner: fn; dnf used within ' => [
205
170
'testMarker ' => '/* testParensOwnerArrowDNFUsedWithin */ ' ,
206
- 'owner ' => -2 ,
207
171
'skipCheckInside ' => true ,
208
172
],
209
173
'parens without owner: default value for param in arrow function ' => [
@@ -228,7 +192,6 @@ public static function dataNormalParentheses()
228
192
*
229
193
* @dataProvider dataDNFTypeParentheses
230
194
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
231
- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createParenthesisNestingMap
232
195
*
233
196
* @return void
234
197
*/
@@ -243,29 +206,15 @@ public function testDNFTypeParentheses($testMarker)
243
206
$ this ->assertSame (T_TYPE_OPEN_PARENTHESIS , $ opener ['code ' ], 'Token tokenized as ' .$ opener ['type ' ].', not T_TYPE_OPEN_PARENTHESIS (code) ' );
244
207
$ this ->assertSame ('T_TYPE_OPEN_PARENTHESIS ' , $ opener ['type ' ], 'Token tokenized as ' .$ opener ['type ' ].', not T_TYPE_OPEN_PARENTHESIS (type) ' );
245
208
246
- $ this ->assertArrayNotHasKey ('parenthesis_owner ' , $ opener , 'Parenthesis owner is set ' );
247
- $ this ->assertArrayHasKey ('parenthesis_opener ' , $ opener , 'Parenthesis opener is not set ' );
248
- $ this ->assertArrayHasKey ('parenthesis_closer ' , $ opener , 'Parenthesis closer is not set ' );
249
- $ this ->assertSame ($ openPtr , $ opener ['parenthesis_opener ' ], 'Parenthesis opener is not the expected token ' );
250
-
251
209
$ closePtr = $ opener ['parenthesis_closer ' ];
252
210
$ closer = $ tokens [$ closePtr ];
253
211
254
212
$ this ->assertSame (') ' , $ closer ['content ' ], 'Content of type close parenthesis is not ")" ' );
255
213
$ this ->assertSame (T_TYPE_CLOSE_PARENTHESIS , $ closer ['code ' ], 'Token tokenized as ' .$ closer ['type ' ].', not T_TYPE_CLOSE_PARENTHESIS (code) ' );
256
214
$ this ->assertSame ('T_TYPE_CLOSE_PARENTHESIS ' , $ closer ['type ' ], 'Token tokenized as ' .$ closer ['type ' ].', not T_TYPE_CLOSE_PARENTHESIS (type) ' );
257
215
258
- $ this ->assertArrayNotHasKey ('parenthesis_owner ' , $ closer , 'Parenthesis owner is set ' );
259
- $ this ->assertArrayHasKey ('parenthesis_opener ' , $ closer , 'Parenthesis opener is not set ' );
260
- $ this ->assertArrayHasKey ('parenthesis_closer ' , $ closer , 'Parenthesis closer is not set ' );
261
- $ this ->assertSame ($ closePtr , $ closer ['parenthesis_closer ' ], 'Parenthesis closer is not the expected token ' );
262
-
263
216
$ intersectionCount = 0 ;
264
217
for ($ i = ($ openPtr + 1 ); $ i < $ closePtr ; $ i ++) {
265
- $ this ->assertArrayHasKey ('nested_parenthesis ' , $ tokens [$ i ], "Nested parenthesis key not set on token $ i ( {$ tokens [$ i ]['type ' ]}) " );
266
- $ this ->assertArrayHasKey ($ openPtr , $ tokens [$ i ]['nested_parenthesis ' ], 'Nested parenthesis is missing target parentheses set ' );
267
- $ this ->assertSame ($ closePtr , $ tokens [$ i ]['nested_parenthesis ' ][$ openPtr ], 'Nested parenthesis closer not set correctly ' );
268
-
269
218
if ($ tokens [$ i ]['content ' ] === '& ' ) {
270
219
$ this ->assertSame (
271
220
T_TYPE_INTERSECTION ,
0 commit comments