1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
<?php
/**
* Tests for the \PHP_CodeSniffer\Util\Tokens::tokenName() method.
*
* @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl>
* @copyright 2024 PHPCSStandards and contributors
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
*/
namespace PHP_CodeSniffer\Tests\Core\Util\Tokens;
use PHP_CodeSniffer\Util\Tokens;
use PHPUnit\Framework\TestCase;
/**
* Tests for the \PHP_CodeSniffer\Util\Tokens::tokenName() method.
*
* @covers \PHP_CodeSniffer\Util\Tokens::tokenName
*/
final class TokenNameTest extends TestCase
{
/**
* Test the method.
*
* @param int|string $tokenCode The PHP/PHPCS token code to get the name for.
* @param string $expected The expected token name.
*
* @dataProvider dataTokenName
*
* @return void
*/
public function testTokenName($tokenCode, $expected)
{
$this->assertSame($expected, Tokens::tokenName($tokenCode));
}//end testTokenName()
/**
* Data provider.
*
* @return array<string, array<string, int|string>>
*/
public static function dataTokenName()
{
return [
'PHP native token: T_ECHO' => [
'tokenCode' => T_ECHO,
'expected' => 'T_ECHO',
],
'PHP native token: T_FUNCTION' => [
'tokenCode' => T_FUNCTION,
'expected' => 'T_FUNCTION',
],
'PHPCS native token: T_CLOSURE' => [
'tokenCode' => T_CLOSURE,
'expected' => 'T_CLOSURE',
],
'PHPCS native token: T_STRING_CONCAT' => [
'tokenCode' => T_STRING_CONCAT,
'expected' => 'T_STRING_CONCAT',
],
// Document the current behaviour for invalid input.
// This behaviour is subject to change.
'Non-token integer passed' => [
'tokenCode' => 100000,
'expected' => 'UNKNOWN',
],
'Non-token string passed' => [
'tokenCode' => 'something',
'expected' => 'ing',
],
];
}//end dataTokenName()
}//end class
|