Skip to content

Commit

Permalink
Merge pull request #315 from PHPCSStandards/feature/tokenizer-php-add…
Browse files Browse the repository at this point in the history
…-tests-for-resolvesimpletoken

Tokenizer/PHP::resolveSimpleToken(): add dedicated tests
  • Loading branch information
jrfnl authored Jan 29, 2024
2 parents dabd744 + 4e56e6f commit 01d1269
Show file tree
Hide file tree
Showing 3 changed files with 502 additions and 0 deletions.
19 changes: 19 additions & 0 deletions tests/Core/Tokenizer/AbstractTokenizerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PHP_CodeSniffer\Tests\ConfigDouble;
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;

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


/**
* Clear the static "resolved tokens" cache property on the Tokenizer\PHP class.
*
* This method should be used selectively by tests to ensure the code under test is actually hit
* by the test testing the code.
*
* @return void
*/
public static function clearResolvedTokensCache()
{
$property = new ReflectionProperty('PHP_CodeSniffer\Tokenizers\PHP', 'resolveTokenCache');
$property->setAccessible(true);
$property->setValue(null, []);
$property->setAccessible(false);

}//end clearResolvedTokensCache()


}//end class
51 changes: 51 additions & 0 deletions tests/Core/Tokenizer/ResolveSimpleTokenTest.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/* testBracesAndColon */
switch ($var[10]) {
case TEST_COLON:
break;
}

/* testNamedParamColon */
callMe(name: $var);

/* testReturnTypeColon */
$closure = function(): Type {};

/* testConcat */
echo 'text' . $var;

/* testSimpleMathTokens */
$a = 10 * 3 / 2 + 5 - 4 % 2;

/* testUnaryPlusMinus */
$a = +10 / -1;

/* testBitwiseTokens */
$a = CONST_A ^ CONST_B & CONST_C | CONST_D ~ CONST_E;

try {
/* testBitwiseOrInCatch */
} catch ( Exception_A | Exception_B $e ) {
}

/* testLessThan */
$a = 10 < $var;

/* testGreaterThan */
$a = 10 > $var;

/* testBooleanNot */
$a = ! $var;

/* testComma */
echo $a, $b, $c;

/* testAsperand */
$a = @callMe();

/* testDollarAndCurlies */
echo ${$var};

/* testBacktick */
$a = `ls -e`;
Loading

0 comments on commit 01d1269

Please sign in to comment.