Skip to content

Commit af03a22

Browse files
committed
Implement use of the new AbstractTokenizerTestCase class
1 parent 921285e commit af03a22

27 files changed

+122
-168
lines changed

tests/Core/Tokenizer/AnonClassParenthesisOwnerTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core\Tokenizer;
1111

12-
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
13-
14-
final class AnonClassParenthesisOwnerTest extends AbstractMethodUnitTest
12+
final class AnonClassParenthesisOwnerTest extends AbstractTokenizerTestCase
1513
{
1614

1715

@@ -27,7 +25,7 @@ final class AnonClassParenthesisOwnerTest extends AbstractMethodUnitTest
2725
*/
2826
public function testAnonClassNoParentheses($testMarker)
2927
{
30-
$tokens = self::$phpcsFile->getTokens();
28+
$tokens = $this->phpcsFile->getTokens();
3129

3230
$anonClass = $this->getTargetToken($testMarker, T_ANON_CLASS);
3331
$this->assertFalse(array_key_exists('parenthesis_owner', $tokens[$anonClass]));
@@ -50,7 +48,7 @@ public function testAnonClassNoParentheses($testMarker)
5048
*/
5149
public function testAnonClassNoParenthesesNextOpenClose($testMarker)
5250
{
53-
$tokens = self::$phpcsFile->getTokens();
51+
$tokens = $this->phpcsFile->getTokens();
5452
$function = $this->getTargetToken($testMarker, T_FUNCTION);
5553

5654
$opener = $this->getTargetToken($testMarker, T_OPEN_PARENTHESIS);
@@ -99,7 +97,7 @@ public static function dataAnonClassNoParentheses()
9997
*/
10098
public function testAnonClassWithParentheses($testMarker)
10199
{
102-
$tokens = self::$phpcsFile->getTokens();
100+
$tokens = $this->phpcsFile->getTokens();
103101
$anonClass = $this->getTargetToken($testMarker, T_ANON_CLASS);
104102
$opener = $this->getTargetToken($testMarker, T_OPEN_PARENTHESIS);
105103
$closer = $this->getTargetToken($testMarker, T_CLOSE_PARENTHESIS);

tests/Core/Tokenizer/ArrayKeywordTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core\Tokenizer;
1111

12-
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
13-
14-
final class ArrayKeywordTest extends AbstractMethodUnitTest
12+
final class ArrayKeywordTest extends AbstractTokenizerTestCase
1513
{
1614

1715

@@ -29,7 +27,7 @@ final class ArrayKeywordTest extends AbstractMethodUnitTest
2927
*/
3028
public function testArrayKeyword($testMarker, $testContent='array')
3129
{
32-
$tokens = self::$phpcsFile->getTokens();
30+
$tokens = $this->phpcsFile->getTokens();
3331

3432
$token = $this->getTargetToken($testMarker, [T_ARRAY, T_STRING], $testContent);
3533
$tokenArray = $tokens[$token];
@@ -89,7 +87,7 @@ public static function dataArrayKeyword()
8987
*/
9088
public function testArrayType($testMarker, $testContent='array')
9189
{
92-
$tokens = self::$phpcsFile->getTokens();
90+
$tokens = $this->phpcsFile->getTokens();
9391

9492
$token = $this->getTargetToken($testMarker, [T_ARRAY, T_STRING], $testContent);
9593
$tokenArray = $tokens[$token];
@@ -144,7 +142,7 @@ public static function dataArrayType()
144142
*/
145143
public function testNotArrayKeyword($testMarker, $testContent='array')
146144
{
147-
$tokens = self::$phpcsFile->getTokens();
145+
$tokens = $this->phpcsFile->getTokens();
148146

149147
$token = $this->getTargetToken($testMarker, [T_ARRAY, T_STRING], $testContent);
150148
$tokenArray = $tokens[$token];

tests/Core/Tokenizer/AttributesTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core\Tokenizer;
1111

12-
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
13-
14-
final class AttributesTest extends AbstractMethodUnitTest
12+
final class AttributesTest extends AbstractTokenizerTestCase
1513
{
1614

1715

@@ -31,7 +29,7 @@ final class AttributesTest extends AbstractMethodUnitTest
3129
*/
3230
public function testAttribute($testMarker, $length, $tokenCodes)
3331
{
34-
$tokens = self::$phpcsFile->getTokens();
32+
$tokens = $this->phpcsFile->getTokens();
3533

3634
$attribute = $this->getTargetToken($testMarker, T_ATTRIBUTE);
3735
$this->assertArrayHasKey('attribute_closer', $tokens[$attribute]);
@@ -294,7 +292,7 @@ public static function dataAttribute()
294292
*/
295293
public function testTwoAttributesOnTheSameLine()
296294
{
297-
$tokens = self::$phpcsFile->getTokens();
295+
$tokens = $this->phpcsFile->getTokens();
298296

299297
$attribute = $this->getTargetToken('/* testTwoAttributeOnTheSameLine */', T_ATTRIBUTE);
300298
$this->assertArrayHasKey('attribute_closer', $tokens[$attribute]);
@@ -318,7 +316,7 @@ public function testTwoAttributesOnTheSameLine()
318316
*/
319317
public function testAttributeAndLineComment()
320318
{
321-
$tokens = self::$phpcsFile->getTokens();
319+
$tokens = $this->phpcsFile->getTokens();
322320

323321
$attribute = $this->getTargetToken('/* testAttributeAndCommentOnTheSameLine */', T_ATTRIBUTE);
324322
$this->assertArrayHasKey('attribute_closer', $tokens[$attribute]);
@@ -348,7 +346,7 @@ public function testAttributeAndLineComment()
348346
*/
349347
public function testAttributeOnParameters($testMarker, $position, $length, array $tokenCodes)
350348
{
351-
$tokens = self::$phpcsFile->getTokens();
349+
$tokens = $this->phpcsFile->getTokens();
352350

353351
$function = $this->getTargetToken($testMarker, T_FUNCTION);
354352
$attribute = ($function + $position);
@@ -455,7 +453,7 @@ public static function dataAttributeOnParameters()
455453
*/
456454
public function testAttributeContainingTextLookingLikeCloseTag($testMarker, $length, array $expectedTokensAttribute, array $expectedTokensAfter)
457455
{
458-
$tokens = self::$phpcsFile->getTokens();
456+
$tokens = $this->phpcsFile->getTokens();
459457

460458
$attribute = $this->getTargetToken($testMarker, T_ATTRIBUTE);
461459

@@ -601,7 +599,7 @@ public static function dataAttributeOnTextLookingLikeCloseTag()
601599
*/
602600
public function testInvalidAttribute()
603601
{
604-
$tokens = self::$phpcsFile->getTokens();
602+
$tokens = $this->phpcsFile->getTokens();
605603

606604
$attribute = $this->getTargetToken('/* testInvalidAttribute */', T_ATTRIBUTE);
607605

@@ -622,7 +620,7 @@ public function testInvalidAttribute()
622620
*/
623621
public function testNestedAttributes()
624622
{
625-
$tokens = self::$phpcsFile->getTokens();
623+
$tokens = $this->phpcsFile->getTokens();
626624
$tokenCodes = [
627625
T_STRING,
628626
T_NS_SEPARATOR,

tests/Core/Tokenizer/BackfillEnumTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core\Tokenizer;
1111

12-
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
13-
14-
final class BackfillEnumTest extends AbstractMethodUnitTest
12+
final class BackfillEnumTest extends AbstractTokenizerTestCase
1513
{
1614

1715

@@ -30,7 +28,7 @@ final class BackfillEnumTest extends AbstractMethodUnitTest
3028
*/
3129
public function testEnums($testMarker, $testContent, $openerOffset, $closerOffset)
3230
{
33-
$tokens = self::$phpcsFile->getTokens();
31+
$tokens = $this->phpcsFile->getTokens();
3432
$enum = $this->getTargetToken($testMarker, [T_ENUM, T_STRING], $testContent);
3533
$tokenArray = $tokens[$enum];
3634

@@ -138,7 +136,7 @@ public static function dataEnums()
138136
*/
139137
public function testNotEnums($testMarker, $testContent)
140138
{
141-
$tokens = self::$phpcsFile->getTokens();
139+
$tokens = $this->phpcsFile->getTokens();
142140
$target = $this->getTargetToken($testMarker, [T_ENUM, T_STRING], $testContent);
143141
$tokenArray = $tokens[$target];
144142

tests/Core/Tokenizer/BackfillExplicitOctalNotationTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core\Tokenizer;
1111

12-
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
13-
14-
final class BackfillExplicitOctalNotationTest extends AbstractMethodUnitTest
12+
final class BackfillExplicitOctalNotationTest extends AbstractTokenizerTestCase
1513
{
1614

1715

@@ -30,7 +28,7 @@ final class BackfillExplicitOctalNotationTest extends AbstractMethodUnitTest
3028
*/
3129
public function testExplicitOctalNotation($marker, $value, $nextToken, $nextContent)
3230
{
33-
$tokens = self::$phpcsFile->getTokens();
31+
$tokens = $this->phpcsFile->getTokens();
3432

3533
$number = $this->getTargetToken($marker, [T_LNUMBER]);
3634

tests/Core/Tokenizer/BackfillFnTokenTest.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core\Tokenizer;
1111

12-
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
13-
14-
final class BackfillFnTokenTest extends AbstractMethodUnitTest
12+
final class BackfillFnTokenTest extends AbstractTokenizerTestCase
1513
{
1614

1715

@@ -106,7 +104,7 @@ public function testNestedOuter()
106104
*/
107105
public function testNestedInner()
108106
{
109-
$tokens = self::$phpcsFile->getTokens();
107+
$tokens = $this->phpcsFile->getTokens();
110108

111109
$token = $this->getTargetToken('/* testNestedInner */', T_FN);
112110
$this->backfillHelper($token, true);
@@ -137,7 +135,7 @@ public function testNestedInner()
137135
*/
138136
public function testNestedSharedCloser()
139137
{
140-
$tokens = self::$phpcsFile->getTokens();
138+
$tokens = $this->phpcsFile->getTokens();
141139

142140
$token = $this->getTargetToken('/* testNestedSharedCloserOuter */', T_FN);
143141
$this->backfillHelper($token);
@@ -380,7 +378,7 @@ public function testNamespaceOperatorInTypes()
380378
*/
381379
public function testKeywordReturnTypes()
382380
{
383-
$tokens = self::$phpcsFile->getTokens();
381+
$tokens = $this->phpcsFile->getTokens();
384382

385383
$testMarkers = [
386384
'Self',
@@ -453,7 +451,7 @@ public function testUnionReturnType()
453451
*/
454452
public function testTernary()
455453
{
456-
$tokens = self::$phpcsFile->getTokens();
454+
$tokens = $this->phpcsFile->getTokens();
457455

458456
$token = $this->getTargetToken('/* testTernary */', T_FN);
459457
$this->backfillHelper($token);
@@ -505,7 +503,7 @@ public function testTernary()
505503
*/
506504
public function testTernaryWithTypes()
507505
{
508-
$tokens = self::$phpcsFile->getTokens();
506+
$tokens = $this->phpcsFile->getTokens();
509507

510508
$token = $this->getTargetToken('/* testTernaryWithTypes */', T_FN);
511509
$this->backfillHelper($token);
@@ -563,7 +561,7 @@ public function testWithMatchValueAndMore()
563561
*/
564562
public function testInMatchValue($testMarker, $openerOffset, $closerOffset, $expectedCloserType, $expectedCloserFriendlyName)
565563
{
566-
$tokens = self::$phpcsFile->getTokens();
564+
$tokens = $this->phpcsFile->getTokens();
567565

568566
$token = $this->getTargetToken($testMarker, T_FN);
569567
$this->backfillHelper($token);
@@ -647,7 +645,7 @@ public function testNestedInMethod()
647645
*/
648646
public function testNotAnArrowFunction($testMarker, $testContent='fn')
649647
{
650-
$tokens = self::$phpcsFile->getTokens();
648+
$tokens = $this->phpcsFile->getTokens();
651649

652650
$token = $this->getTargetToken($testMarker, [T_STRING, T_FN], $testContent);
653651
$tokenArray = $tokens[$token];
@@ -745,7 +743,7 @@ public static function dataNotAnArrowFunction()
745743
*/
746744
private function backfillHelper($token, $skipScopeCloserCheck=false)
747745
{
748-
$tokens = self::$phpcsFile->getTokens();
746+
$tokens = $this->phpcsFile->getTokens();
749747

750748
$this->assertTrue(array_key_exists('scope_condition', $tokens[$token]), 'Scope condition is not set');
751749
$this->assertTrue(array_key_exists('scope_opener', $tokens[$token]), 'Scope opener is not set');
@@ -797,7 +795,7 @@ private function backfillHelper($token, $skipScopeCloserCheck=false)
797795
*/
798796
private function scopePositionTestHelper($token, $openerOffset, $closerOffset, $expectedCloserType='semicolon')
799797
{
800-
$tokens = self::$phpcsFile->getTokens();
798+
$tokens = $this->phpcsFile->getTokens();
801799
$expectedScopeOpener = ($token + $openerOffset);
802800
$expectedScopeCloser = ($token + $closerOffset);
803801

tests/Core/Tokenizer/BackfillMatchTokenTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010

1111
namespace PHP_CodeSniffer\Tests\Core\Tokenizer;
1212

13-
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
1413
use PHP_CodeSniffer\Util\Tokens;
1514

16-
final class BackfillMatchTokenTest extends AbstractMethodUnitTest
15+
final class BackfillMatchTokenTest extends AbstractTokenizerTestCase
1716
{
1817

1918

@@ -32,7 +31,7 @@ final class BackfillMatchTokenTest extends AbstractMethodUnitTest
3231
*/
3332
public function testMatchExpression($testMarker, $openerOffset, $closerOffset, $testContent='match')
3433
{
35-
$tokens = self::$phpcsFile->getTokens();
34+
$tokens = $this->phpcsFile->getTokens();
3635

3736
$token = $this->getTargetToken($testMarker, [T_STRING, T_MATCH], $testContent);
3837
$tokenArray = $tokens[$token];
@@ -213,7 +212,7 @@ public static function dataMatchExpression()
213212
*/
214213
public function testNotAMatchStructure($testMarker, $testContent='match')
215214
{
216-
$tokens = self::$phpcsFile->getTokens();
215+
$tokens = $this->phpcsFile->getTokens();
217216

218217
$token = $this->getTargetToken($testMarker, [T_STRING, T_MATCH], $testContent);
219218
$tokenArray = $tokens[$token];
@@ -228,7 +227,7 @@ public function testNotAMatchStructure($testMarker, $testContent='match')
228227
$this->assertArrayNotHasKey('parenthesis_opener', $tokenArray, 'Parenthesis opener is set');
229228
$this->assertArrayNotHasKey('parenthesis_closer', $tokenArray, 'Parenthesis closer is set');
230229

231-
$next = self::$phpcsFile->findNext(Tokens::$emptyTokens, ($token + 1), null, true);
230+
$next = $this->phpcsFile->findNext(Tokens::$emptyTokens, ($token + 1), null, true);
232231
if ($next !== false && $tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
233232
$this->assertArrayNotHasKey('parenthesis_owner', $tokenArray, 'Parenthesis owner is set for opener after');
234233
}
@@ -477,7 +476,7 @@ public static function dataSwitchCaseVersusMatch()
477476
*/
478477
private function scopeTestHelper($token, $openerOffset, $closerOffset, $skipScopeCloserCheck=false)
479478
{
480-
$tokens = self::$phpcsFile->getTokens();
479+
$tokens = $this->phpcsFile->getTokens();
481480
$tokenArray = $tokens[$token];
482481
$tokenType = $tokenArray['type'];
483482
$expectedScopeOpener = ($token + $openerOffset);
@@ -532,7 +531,7 @@ private function scopeTestHelper($token, $openerOffset, $closerOffset, $skipScop
532531
*/
533532
private function parenthesisTestHelper($token)
534533
{
535-
$tokens = self::$phpcsFile->getTokens();
534+
$tokens = $this->phpcsFile->getTokens();
536535
$tokenArray = $tokens[$token];
537536
$tokenType = $tokenArray['type'];
538537

tests/Core/Tokenizer/BackfillNumericSeparatorTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core\Tokenizer;
1111

12-
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
1312
use PHP_CodeSniffer\Util\Tokens;
1413

15-
final class BackfillNumericSeparatorTest extends AbstractMethodUnitTest
14+
final class BackfillNumericSeparatorTest extends AbstractTokenizerTestCase
1615
{
1716

1817

@@ -30,7 +29,7 @@ final class BackfillNumericSeparatorTest extends AbstractMethodUnitTest
3029
*/
3130
public function testBackfill($marker, $type, $value)
3231
{
33-
$tokens = self::$phpcsFile->getTokens();
32+
$tokens = $this->phpcsFile->getTokens();
3433
$number = $this->getTargetToken($marker, [T_LNUMBER, T_DNUMBER]);
3534
$tokenArray = $tokens[$number];
3635

@@ -150,7 +149,7 @@ public static function dataTestBackfill()
150149
*/
151150
public function testNoBackfill($testMarker, $expectedTokens)
152151
{
153-
$tokens = self::$phpcsFile->getTokens();
152+
$tokens = $this->phpcsFile->getTokens();
154153
$number = $this->getTargetToken($testMarker, [T_LNUMBER, T_DNUMBER]);
155154

156155
foreach ($expectedTokens as $key => $expectedToken) {

0 commit comments

Comments
 (0)