Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokenizer/PHP::resolveSimpleToken(): add dedicated tests #315

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading