Skip to content

Commit 074ad2a

Browse files
authored
Merge pull request #274 from PHPCSStandards/feature/tests-tokenizer-use-named-data-sets
Tests/Tokenizer/various: use named data sets
2 parents ef01f55 + 2c32a6e commit 074ad2a

17 files changed

+1155
-1035
lines changed

tests/Core/Tokenizer/AnonClassParenthesisOwnerTest.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,17 @@ public function testAnonClassNoParenthesesNextOpenClose($testMarker)
7070
* @see testAnonClassNoParentheses()
7171
* @see testAnonClassNoParenthesesNextOpenClose()
7272
*
73-
* @return array
73+
* @return array<string, array<string, string>>
7474
*/
7575
public static function dataAnonClassNoParentheses()
7676
{
7777
return [
78-
['/* testNoParentheses */'],
79-
['/* testNoParenthesesAndEmptyTokens */'],
78+
'plain' => [
79+
'testMarker' => '/* testNoParentheses */',
80+
],
81+
'declaration contains comments and extra whitespace' => [
82+
'testMarker' => '/* testNoParenthesesAndEmptyTokens */',
83+
],
8084
];
8185

8286
}//end dataAnonClassNoParentheses()
@@ -129,13 +133,17 @@ public function testAnonClassWithParentheses($testMarker)
129133
*
130134
* @see testAnonClassWithParentheses()
131135
*
132-
* @return array
136+
* @return array<string, array<string, string>>
133137
*/
134138
public static function dataAnonClassWithParentheses()
135139
{
136140
return [
137-
['/* testWithParentheses */'],
138-
['/* testWithParenthesesAndEmptyTokens */'],
141+
'plain' => [
142+
'testMarker' => '/* testWithParentheses */',
143+
],
144+
'declaration contains comments and extra whitespace' => [
145+
'testMarker' => '/* testWithParenthesesAndEmptyTokens */',
146+
],
139147
];
140148

141149
}//end dataAnonClassWithParentheses()

tests/Core/Tokenizer/ArrayKeywordTest.php

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,27 @@ public function testArrayKeyword($testMarker, $testContent='array')
4949
*
5050
* @see testArrayKeyword()
5151
*
52-
* @return array
52+
* @return array<string, array<string, string>>
5353
*/
5454
public static function dataArrayKeyword()
5555
{
5656
return [
57-
'empty array' => ['/* testEmptyArray */'],
58-
'array with space before parenthesis' => ['/* testArrayWithSpace */'],
57+
'empty array' => [
58+
'testMarker' => '/* testEmptyArray */',
59+
],
60+
'array with space before parenthesis' => [
61+
'testMarker' => '/* testArrayWithSpace */',
62+
],
5963
'array with comment before parenthesis' => [
60-
'/* testArrayWithComment */',
61-
'Array',
64+
'testMarker' => '/* testArrayWithComment */',
65+
'testContent' => 'Array',
66+
],
67+
'nested: outer array' => [
68+
'testMarker' => '/* testNestingArray */',
69+
],
70+
'nested: inner array' => [
71+
'testMarker' => '/* testNestedArray */',
6272
],
63-
'nested: outer array' => ['/* testNestingArray */'],
64-
'nested: inner array' => ['/* testNestedArray */'],
6573
];
6674

6775
}//end dataArrayKeyword()
@@ -101,17 +109,21 @@ public function testArrayType($testMarker, $testContent='array')
101109
*
102110
* @see testArrayType()
103111
*
104-
* @return array
112+
* @return array<string, array<string, string>>
105113
*/
106114
public static function dataArrayType()
107115
{
108116
return [
109117
'closure return type' => [
110-
'/* testClosureReturnType */',
111-
'Array',
118+
'testMarker' => '/* testClosureReturnType */',
119+
'testContent' => 'Array',
120+
],
121+
'function param type' => [
122+
'testMarker' => '/* testFunctionDeclarationParamType */',
123+
],
124+
'function union return type' => [
125+
'testMarker' => '/* testFunctionDeclarationReturnType */',
112126
],
113-
'function param type' => ['/* testFunctionDeclarationParamType */'],
114-
'function union return type' => ['/* testFunctionDeclarationReturnType */'],
115127
];
116128

117129
}//end dataArrayType()
@@ -152,16 +164,18 @@ public function testNotArrayKeyword($testMarker, $testContent='array')
152164
*
153165
* @see testNotArrayKeyword()
154166
*
155-
* @return array
167+
* @return array<string, array<string, string>>
156168
*/
157169
public static function dataNotArrayKeyword()
158170
{
159171
return [
160172
'class-constant-name' => [
161-
'/* testClassConst */',
162-
'ARRAY',
173+
'testMarker' => '/* testClassConst */',
174+
'testContent' => 'ARRAY',
175+
],
176+
'class-method-name' => [
177+
'testMarker' => '/* testClassMethod */',
163178
],
164-
'class-method-name' => ['/* testClassMethod */'],
165179
];
166180

167181
}//end dataNotArrayKeyword()

tests/Core/Tokenizer/BackfillEnumTest.inc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,6 @@ enum /* comment */ Name
6666
case SOME_CASE;
6767
}
6868

69-
enum /* testEnumUsedAsEnumName */ Enum
70-
{
71-
}
72-
7369
/* testEnumUsedAsNamespaceName */
7470
namespace Enum;
7571
/* testEnumUsedAsPartOfNamespaceName */

tests/Core/Tokenizer/BackfillEnumTest.php

Lines changed: 88 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -73,52 +73,52 @@ public function testEnums($testMarker, $testContent, $openerOffset, $closerOffse
7373
*
7474
* @see testEnums()
7575
*
76-
* @return array
76+
* @return array<string, array<string, string|int>>
7777
*/
7878
public static function dataEnums()
7979
{
8080
return [
81-
[
82-
'/* testPureEnum */',
83-
'enum',
84-
4,
85-
12,
86-
],
87-
[
88-
'/* testBackedIntEnum */',
89-
'enum',
90-
7,
91-
29,
92-
],
93-
[
94-
'/* testBackedStringEnum */',
95-
'enum',
96-
8,
97-
30,
98-
],
99-
[
100-
'/* testComplexEnum */',
101-
'enum',
102-
11,
103-
72,
104-
],
105-
[
106-
'/* testEnumWithEnumAsClassName */',
107-
'enum',
108-
6,
109-
7,
110-
],
111-
[
112-
'/* testEnumIsCaseInsensitive */',
113-
'EnUm',
114-
4,
115-
5,
116-
],
117-
[
118-
'/* testDeclarationContainingComment */',
119-
'enum',
120-
6,
121-
14,
81+
'enum - pure' => [
82+
'testMarker' => '/* testPureEnum */',
83+
'testContent' => 'enum',
84+
'openerOffset' => 4,
85+
'closerOffset' => 12,
86+
],
87+
'enum - backed int' => [
88+
'testMarker' => '/* testBackedIntEnum */',
89+
'testContent' => 'enum',
90+
'openerOffset' => 7,
91+
'closerOffset' => 29,
92+
],
93+
'enum - backed string' => [
94+
'testMarker' => '/* testBackedStringEnum */',
95+
'testContent' => 'enum',
96+
'openerOffset' => 8,
97+
'closerOffset' => 30,
98+
],
99+
'enum - backed int + implements' => [
100+
'testMarker' => '/* testComplexEnum */',
101+
'testContent' => 'enum',
102+
'openerOffset' => 11,
103+
'closerOffset' => 72,
104+
],
105+
'enum keyword when "enum" is the name for the construct (yes, this is allowed)' => [
106+
'testMarker' => '/* testEnumWithEnumAsClassName */',
107+
'testContent' => 'enum',
108+
'openerOffset' => 6,
109+
'closerOffset' => 7,
110+
],
111+
'enum - keyword is case insensitive' => [
112+
'testMarker' => '/* testEnumIsCaseInsensitive */',
113+
'testContent' => 'EnUm',
114+
'openerOffset' => 4,
115+
'closerOffset' => 5,
116+
],
117+
'enum - declaration containing comment' => [
118+
'testMarker' => '/* testDeclarationContainingComment */',
119+
'testContent' => 'enum',
120+
'openerOffset' => 6,
121+
'closerOffset' => 14,
122122
],
123123
];
124124

@@ -152,74 +152,70 @@ public function testNotEnums($testMarker, $testContent)
152152
*
153153
* @see testNotEnums()
154154
*
155-
* @return array
155+
* @return array<string, array<string, string>>
156156
*/
157157
public static function dataNotEnums()
158158
{
159159
return [
160-
[
161-
'/* testEnumAsClassNameAfterEnumKeyword */',
162-
'Enum',
160+
'not enum - construct named enum' => [
161+
'testMarker' => '/* testEnumAsClassNameAfterEnumKeyword */',
162+
'testContent' => 'Enum',
163163
],
164-
[
165-
'/* testEnumUsedAsClassName */',
166-
'Enum',
164+
'not enum - class named enum' => [
165+
'testMarker' => '/* testEnumUsedAsClassName */',
166+
'testContent' => 'Enum',
167167
],
168-
[
169-
'/* testEnumUsedAsClassConstantName */',
170-
'ENUM',
168+
'not enum - class constant named enum' => [
169+
'testMarker' => '/* testEnumUsedAsClassConstantName */',
170+
'testContent' => 'ENUM',
171171
],
172-
[
173-
'/* testEnumUsedAsMethodName */',
174-
'enum',
172+
'not enum - method named enum' => [
173+
'testMarker' => '/* testEnumUsedAsMethodName */',
174+
'testContent' => 'enum',
175175
],
176-
[
177-
'/* testEnumUsedAsPropertyName */',
178-
'enum',
176+
'not enum - class property named enum' => [
177+
'testMarker' => '/* testEnumUsedAsPropertyName */',
178+
'testContent' => 'enum',
179179
],
180-
[
181-
'/* testEnumUsedAsFunctionName */',
182-
'enum',
180+
'not enum - global function named enum' => [
181+
'testMarker' => '/* testEnumUsedAsFunctionName */',
182+
'testContent' => 'enum',
183183
],
184-
[
185-
'/* testEnumUsedAsEnumName */',
186-
'Enum',
184+
'not enum - namespace named enum' => [
185+
'testMarker' => '/* testEnumUsedAsNamespaceName */',
186+
'testContent' => 'Enum',
187187
],
188-
[
189-
'/* testEnumUsedAsNamespaceName */',
190-
'Enum',
188+
'not enum - part of namespace named enum' => [
189+
'testMarker' => '/* testEnumUsedAsPartOfNamespaceName */',
190+
'testContent' => 'Enum',
191191
],
192-
[
193-
'/* testEnumUsedAsPartOfNamespaceName */',
194-
'Enum',
192+
'not enum - class instantiation for class enum' => [
193+
'testMarker' => '/* testEnumUsedInObjectInitialization */',
194+
'testContent' => 'Enum',
195195
],
196-
[
197-
'/* testEnumUsedInObjectInitialization */',
198-
'Enum',
196+
'not enum - function call' => [
197+
'testMarker' => '/* testEnumAsFunctionCall */',
198+
'testContent' => 'enum',
199199
],
200-
[
201-
'/* testEnumAsFunctionCall */',
202-
'enum',
200+
'not enum - namespace relative function call' => [
201+
'testMarker' => '/* testEnumAsFunctionCallWithNamespace */',
202+
'testContent' => 'enum',
203203
],
204-
[
205-
'/* testEnumAsFunctionCallWithNamespace */',
206-
'enum',
204+
'not enum - class constant fetch with enum as class name' => [
205+
'testMarker' => '/* testClassConstantFetchWithEnumAsClassName */',
206+
'testContent' => 'Enum',
207207
],
208-
[
209-
'/* testClassConstantFetchWithEnumAsClassName */',
210-
'Enum',
208+
'not enum - class constant fetch with enum as constant name' => [
209+
'testMarker' => '/* testClassConstantFetchWithEnumAsConstantName */',
210+
'testContent' => 'ENUM',
211211
],
212-
[
213-
'/* testClassConstantFetchWithEnumAsConstantName */',
214-
'ENUM',
212+
'parse error, not enum - enum declaration without name' => [
213+
'testMarker' => '/* testParseErrorMissingName */',
214+
'testContent' => 'enum',
215215
],
216-
[
217-
'/* testParseErrorMissingName */',
218-
'enum',
219-
],
220-
[
221-
'/* testParseErrorLiveCoding */',
222-
'enum',
216+
'parse error, not enum - enum declaration with curlies' => [
217+
'testMarker' => '/* testParseErrorLiveCoding */',
218+
'testContent' => 'enum',
223219
],
224220
];
225221

0 commit comments

Comments
 (0)