Skip to content

Commit 01d1269

Browse files
authored
Merge pull request #315 from PHPCSStandards/feature/tokenizer-php-add-tests-for-resolvesimpletoken
Tokenizer/PHP::resolveSimpleToken(): add dedicated tests
2 parents dabd744 + 4e56e6f commit 01d1269

File tree

3 files changed

+502
-0
lines changed

3 files changed

+502
-0
lines changed

tests/Core/Tokenizer/AbstractTokenizerTestCase.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use PHP_CodeSniffer\Tests\ConfigDouble;
1818
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
1919
use PHPUnit\Framework\TestCase;
20+
use ReflectionProperty;
2021

2122
abstract class AbstractTokenizerTestCase extends TestCase
2223
{
@@ -102,4 +103,22 @@ protected function getTargetToken($commentString, $tokenType, $tokenContent=null
102103
}//end getTargetToken()
103104

104105

106+
/**
107+
* Clear the static "resolved tokens" cache property on the Tokenizer\PHP class.
108+
*
109+
* This method should be used selectively by tests to ensure the code under test is actually hit
110+
* by the test testing the code.
111+
*
112+
* @return void
113+
*/
114+
public static function clearResolvedTokensCache()
115+
{
116+
$property = new ReflectionProperty('PHP_CodeSniffer\Tokenizers\PHP', 'resolveTokenCache');
117+
$property->setAccessible(true);
118+
$property->setValue(null, []);
119+
$property->setAccessible(false);
120+
121+
}//end clearResolvedTokensCache()
122+
123+
105124
}//end class
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/* testBracesAndColon */
4+
switch ($var[10]) {
5+
case TEST_COLON:
6+
break;
7+
}
8+
9+
/* testNamedParamColon */
10+
callMe(name: $var);
11+
12+
/* testReturnTypeColon */
13+
$closure = function(): Type {};
14+
15+
/* testConcat */
16+
echo 'text' . $var;
17+
18+
/* testSimpleMathTokens */
19+
$a = 10 * 3 / 2 + 5 - 4 % 2;
20+
21+
/* testUnaryPlusMinus */
22+
$a = +10 / -1;
23+
24+
/* testBitwiseTokens */
25+
$a = CONST_A ^ CONST_B & CONST_C | CONST_D ~ CONST_E;
26+
27+
try {
28+
/* testBitwiseOrInCatch */
29+
} catch ( Exception_A | Exception_B $e ) {
30+
}
31+
32+
/* testLessThan */
33+
$a = 10 < $var;
34+
35+
/* testGreaterThan */
36+
$a = 10 > $var;
37+
38+
/* testBooleanNot */
39+
$a = ! $var;
40+
41+
/* testComma */
42+
echo $a, $b, $c;
43+
44+
/* testAsperand */
45+
$a = @callMe();
46+
47+
/* testDollarAndCurlies */
48+
echo ${$var};
49+
50+
/* testBacktick */
51+
$a = `ls -e`;

0 commit comments

Comments
 (0)