Skip to content

Commit e8363e0

Browse files
committed
Tests: add tests for the Util\Tokens::tokenName() method
1 parent 0b81673 commit e8363e0

File tree

1 file changed

+81
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)