-
-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathTokenNameTest.php
More file actions
163 lines (149 loc) · 5.99 KB
/
TokenNameTest.php
File metadata and controls
163 lines (149 loc) · 5.99 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?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/HEAD/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
* @covers \PHP_CodeSniffer\Util\Tokens::polyfillTokenizerConstants
*/
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
* @dataProvider dataPolyfilledPHPNativeTokens
*
* @return void
*/
public function testTokenName($tokenCode, $expected)
{
$this->assertSame($expected, Tokens::tokenName($tokenCode));
}
/**
* 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',
],
];
}
/**
* Data provider.
*
* @return array<string, array<string, int|string>>
*/
public static function dataPolyfilledPHPNativeTokens()
{
return [
'PHP 7.4 native token, polyfilled: T_COALESCE_EQUAL' => [
'tokenCode' => T_COALESCE_EQUAL,
'expected' => 'T_COALESCE_EQUAL',
],
'PHP 7.4 native token, polyfilled: T_BAD_CHARACTER' => [
'tokenCode' => T_BAD_CHARACTER,
'expected' => 'T_BAD_CHARACTER',
],
'PHP 7.4 native token, polyfilled: T_FN' => [
'tokenCode' => T_FN,
'expected' => 'T_FN',
],
'PHP 8.0 native token, polyfilled: T_NULLSAFE_OBJECT_OPERATOR' => [
'tokenCode' => T_NULLSAFE_OBJECT_OPERATOR,
'expected' => 'T_NULLSAFE_OBJECT_OPERATOR',
],
'PHP 8.0 native token, polyfilled: T_NAME_QUALIFIED' => [
'tokenCode' => T_NAME_QUALIFIED,
'expected' => 'T_NAME_QUALIFIED',
],
'PHP 8.0 native token, polyfilled: T_NAME_FULLY_QUALIFIED' => [
'tokenCode' => T_NAME_FULLY_QUALIFIED,
'expected' => 'T_NAME_FULLY_QUALIFIED',
],
'PHP 8.0 native token, polyfilled: T_NAME_RELATIVE' => [
'tokenCode' => T_NAME_RELATIVE,
'expected' => 'T_NAME_RELATIVE',
],
'PHP 8.0 native token, polyfilled: T_MATCH' => [
'tokenCode' => T_MATCH,
'expected' => 'T_MATCH',
],
'PHP 8.0 native token, polyfilled: T_ATTRIBUTE' => [
'tokenCode' => T_ATTRIBUTE,
'expected' => 'T_ATTRIBUTE',
],
'PHP 8.1 native token, polyfilled: T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG' => [
'tokenCode' => T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG,
'expected' => 'T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG',
],
'PHP 8.1 native token, polyfilled: T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG' => [
'tokenCode' => T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG,
'expected' => 'T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG',
],
'PHP 8.1 native token, polyfilled: T_READONLY' => [
'tokenCode' => T_READONLY,
'expected' => 'T_READONLY',
],
'PHP 8.1 native token, polyfilled: T_ENUM' => [
'tokenCode' => T_ENUM,
'expected' => 'T_ENUM',
],
'PHP 8.4 native token, polyfilled: T_PUBLIC_SET' => [
'tokenCode' => T_PUBLIC_SET,
'expected' => 'T_PUBLIC_SET',
],
'PHP 8.4 native token, polyfilled: T_PROTECTED_SET' => [
'tokenCode' => T_PROTECTED_SET,
'expected' => 'T_PROTECTED_SET',
],
'PHP 8.4 native token, polyfilled: T_PRIVATE_SET' => [
'tokenCode' => T_PRIVATE_SET,
'expected' => 'T_PRIVATE_SET',
],
'PHP 8.5 native token, polyfilled: T_VOID_CAST' => [
'tokenCode' => T_VOID_CAST,
'expected' => 'T_VOID_CAST',
],
];
}
}