77 * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
88 */
99
10- namespace PHP_CodeSniffer \Tests \Core \Tokenizer ;
10+ namespace PHP_CodeSniffer \Tests \Core \Tokenizer \ PHP ;
1111
12+ use PHP_CodeSniffer \Tests \Core \Tokenizer \AbstractTokenizerTestCase ;
1213use PHP_CodeSniffer \Util \Tokens ;
1314
1415final class DNFTypesTest extends AbstractTokenizerTestCase
@@ -18,17 +19,16 @@ final class DNFTypesTest extends AbstractTokenizerTestCase
1819 /**
1920 * Test that parentheses when **not** used in a type declaration are correctly tokenized.
2021 *
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.
2525 *
2626 * @dataProvider dataNormalParentheses
27- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createParenthesisNestingMap
27+ * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
2828 *
2929 * @return void
3030 */
31- public function testNormalParentheses ($ testMarker , $ owner = false , $ skipCheckInside =false )
31+ public function testNormalParentheses ($ testMarker , $ skipCheckInside =false )
3232 {
3333 $ tokens = $ this ->phpcsFile ->getTokens ();
3434
@@ -39,40 +39,14 @@ public function testNormalParentheses($testMarker, $owner=false, $skipCheckInsid
3939 $ this ->assertSame (T_OPEN_PARENTHESIS , $ opener ['code ' ], 'Token tokenized as ' .$ opener ['type ' ].', not T_OPEN_PARENTHESIS (code) ' );
4040 $ this ->assertSame ('T_OPEN_PARENTHESIS ' , $ opener ['type ' ], 'Token tokenized as ' .$ opener ['type ' ].', not T_OPEN_PARENTHESIS (type) ' );
4141
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-
5342 $ closePtr = $ opener ['parenthesis_closer ' ];
5443 $ closer = $ tokens [$ closePtr ];
5544
5645 $ this ->assertSame (') ' , $ closer ['content ' ], 'Content of type close parenthesis is not ")" ' );
5746 $ this ->assertSame (T_CLOSE_PARENTHESIS , $ closer ['code ' ], 'Token tokenized as ' .$ closer ['type ' ].', not T_CLOSE_PARENTHESIS (code) ' );
5847 $ this ->assertSame ('T_CLOSE_PARENTHESIS ' , $ closer ['type ' ], 'Token tokenized as ' .$ closer ['type ' ].', not T_CLOSE_PARENTHESIS (type) ' );
5948
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-
7149 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-
7650 // If there are ampersands, make sure these are tokenized as bitwise and.
7751 if ($ skipCheckInside === false && $ tokens [$ i ]['content ' ] === '& ' ) {
7852 $ 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()
133107 ],
134108 'parens with owner: function; & in default value ' => [
135109 'testMarker ' => '/* testParensOwnerFunctionAmpersandInDefaultValue */ ' ,
136- 'owner ' => -3 ,
137110 ],
138111 'parens with owner: closure; param declared by & ref ' => [
139112 'testMarker ' => '/* testParensOwnerClosureAmpersandParamRef */ ' ,
140- 'owner ' => -1 ,
141113 ],
142114 'parens with owner: if ' => [
143115 'testMarker ' => '/* testParensOwnerIf */ ' ,
144- 'owner ' => -2 ,
145116 ],
146117 'parens without owner in if condition ' => [
147118 'testMarker ' => '/* testParensNoOwnerInIfCondition */ ' ,
148119 ],
149120 'parens with owner: for ' => [
150121 'testMarker ' => '/* testParensOwnerFor */ ' ,
151- 'owner ' => -2 ,
152122 ],
153123 'parens without owner in for condition ' => [
154124 'testMarker ' => '/* testParensNoOwnerInForCondition */ ' ,
155125 ],
156126 'parens with owner: match ' => [
157127 'testMarker ' => '/* testParensOwnerMatch */ ' ,
158- 'owner ' => -1 ,
159128 ],
160129 'parens with owner: array ' => [
161130 'testMarker ' => '/* testParensOwnerArray */ ' ,
162- 'owner ' => -2 ,
163131 ],
164132 'parens without owner in array; function call with & in callable ' => [
165133 'testMarker ' => '/* testParensNoOwnerFunctionCallWithAmpersandInCallable */ ' ,
166134 ],
167135 'parens with owner: fn; & in return value ' => [
168136 'testMarker ' => '/* testParensOwnerArrowFn */ ' ,
169- 'owner ' => -1 ,
170137 ],
171138 'parens with owner: list with reference vars ' => [
172139 'testMarker ' => '/* testParensOwnerListWithRefVars */ ' ,
173- 'owner ' => -1 ,
174140 ],
175141 'parens without owner, function call with DNF look-a-like param ' => [
176142 'testMarker ' => '/* testParensNoOwnerFunctionCallwithDNFLookALikeParam */ ' ,
@@ -199,11 +165,9 @@ public static function dataNormalParentheses()
199165 ],
200166 'parens with owner: closure; & in default value ' => [
201167 'testMarker ' => '/* testParensOwnerClosureAmpersandInDefaultValue */ ' ,
202- 'owner ' => -2 ,
203168 ],
204169 'parens with owner: fn; dnf used within ' => [
205170 'testMarker ' => '/* testParensOwnerArrowDNFUsedWithin */ ' ,
206- 'owner ' => -2 ,
207171 'skipCheckInside ' => true ,
208172 ],
209173 'parens without owner: default value for param in arrow function ' => [
@@ -228,7 +192,6 @@ public static function dataNormalParentheses()
228192 *
229193 * @dataProvider dataDNFTypeParentheses
230194 * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
231- * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::createParenthesisNestingMap
232195 *
233196 * @return void
234197 */
@@ -243,29 +206,15 @@ public function testDNFTypeParentheses($testMarker)
243206 $ this ->assertSame (T_TYPE_OPEN_PARENTHESIS , $ opener ['code ' ], 'Token tokenized as ' .$ opener ['type ' ].', not T_TYPE_OPEN_PARENTHESIS (code) ' );
244207 $ this ->assertSame ('T_TYPE_OPEN_PARENTHESIS ' , $ opener ['type ' ], 'Token tokenized as ' .$ opener ['type ' ].', not T_TYPE_OPEN_PARENTHESIS (type) ' );
245208
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-
251209 $ closePtr = $ opener ['parenthesis_closer ' ];
252210 $ closer = $ tokens [$ closePtr ];
253211
254212 $ this ->assertSame (') ' , $ closer ['content ' ], 'Content of type close parenthesis is not ")" ' );
255213 $ this ->assertSame (T_TYPE_CLOSE_PARENTHESIS , $ closer ['code ' ], 'Token tokenized as ' .$ closer ['type ' ].', not T_TYPE_CLOSE_PARENTHESIS (code) ' );
256214 $ this ->assertSame ('T_TYPE_CLOSE_PARENTHESIS ' , $ closer ['type ' ], 'Token tokenized as ' .$ closer ['type ' ].', not T_TYPE_CLOSE_PARENTHESIS (type) ' );
257215
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-
263216 $ intersectionCount = 0 ;
264217 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-
269218 if ($ tokens [$ i ]['content ' ] === '& ' ) {
270219 $ this ->assertSame (
271220 T_TYPE_INTERSECTION ,
0 commit comments