Skip to content

Commit 118aa7f

Browse files
committed
Tests/BackfillEnumTest: use named data sets
With non-named data sets, when a test fails, PHPUnit will display the number of the test which failed. With tests which have a _lot_ of data sets, this makes it _interesting_ (and time-consuming) to debug those, as one now has to figure out which of the data sets in the data provider corresponds to that number. Using named data sets makes debugging failing tests more straight forward as PHPUnit will display the data set name instead of the number. Using named data sets also documents what exactly each data set is testing. Aside from adding the data set name, this commit also adds the parameter name for each item in the data set, this time in an effort to make it more straight forward to update and add tests as it will be more obvious what each key in the data set signifies. Includes: * Making the data type in the docblock more specific. * Removing a duplicate test.
1 parent c5f32cd commit 118aa7f

File tree

2 files changed

+88
-96
lines changed

2 files changed

+88
-96
lines changed

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)