Skip to content

Commit 9860504

Browse files
committed
Tests/EnumCaseTest: 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. Includes making the data type in the docblock more specific.
1 parent 7e13933 commit 9860504

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

tests/Core/Tokenizer/EnumCaseTest.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ public function testEnumCases($testMarker)
4747
*
4848
* @see testEnumCases()
4949
*
50-
* @return array
50+
* @return array<string, array<string>>
5151
*/
5252
public static function dataEnumCases()
5353
{
5454
return [
55-
['/* testPureEnumCase */'],
56-
['/* testBackingIntegerEnumCase */'],
57-
['/* testBackingStringEnumCase */'],
58-
['/* testEnumCaseInComplexEnum */'],
59-
['/* testEnumCaseIsCaseInsensitive */'],
60-
['/* testEnumCaseAfterSwitch */'],
61-
['/* testEnumCaseAfterSwitchWithEndSwitch */'],
55+
'enum case, no value' => ['/* testPureEnumCase */'],
56+
'enum case, integer value' => ['/* testBackingIntegerEnumCase */'],
57+
'enum case, string value' => ['/* testBackingStringEnumCase */'],
58+
'enum case, integer value in more complex enum' => ['/* testEnumCaseInComplexEnum */'],
59+
'enum case, keyword in mixed case' => ['/* testEnumCaseIsCaseInsensitive */'],
60+
'enum case, after switch statement' => ['/* testEnumCaseAfterSwitch */'],
61+
'enum case, after switch statement using alternative syntax' => ['/* testEnumCaseAfterSwitchWithEndSwitch */'],
6262
];
6363

6464
}//end dataEnumCases()
@@ -96,18 +96,18 @@ public function testNotEnumCases($testMarker)
9696
*
9797
* @see testNotEnumCases()
9898
*
99-
* @return array
99+
* @return array<string, array<string>>
100100
*/
101101
public static function dataNotEnumCases()
102102
{
103103
return [
104-
['/* testCaseWithSemicolonIsNotEnumCase */'],
105-
['/* testCaseWithConstantIsNotEnumCase */'],
106-
['/* testCaseWithConstantAndIdenticalIsNotEnumCase */'],
107-
['/* testCaseWithAssigmentToConstantIsNotEnumCase */'],
108-
['/* testIsNotEnumCaseIsCaseInsensitive */'],
109-
['/* testCaseInSwitchWhenCreatingEnumInSwitch1 */'],
110-
['/* testCaseInSwitchWhenCreatingEnumInSwitch2 */'],
104+
'switch case with constant, semicolon condition end' => ['/* testCaseWithSemicolonIsNotEnumCase */'],
105+
'switch case with constant, colon condition end' => ['/* testCaseWithConstantIsNotEnumCase */'],
106+
'switch case with constant, comparison' => ['/* testCaseWithConstantAndIdenticalIsNotEnumCase */'],
107+
'switch case with constant, assignment' => ['/* testCaseWithAssigmentToConstantIsNotEnumCase */'],
108+
'switch case with constant, keyword in mixed case' => ['/* testIsNotEnumCaseIsCaseInsensitive */'],
109+
'switch case, body in curlies declares enum' => ['/* testCaseInSwitchWhenCreatingEnumInSwitch1 */'],
110+
'switch case, body after semicolon declares enum' => ['/* testCaseInSwitchWhenCreatingEnumInSwitch2 */'],
111111
];
112112

113113
}//end dataNotEnumCases()
@@ -140,18 +140,18 @@ public function testKeywordAsEnumCaseNameShouldBeString($testMarker)
140140
*
141141
* @see testKeywordAsEnumCaseNameShouldBeString()
142142
*
143-
* @return array
143+
* @return array<string, array<string>>
144144
*/
145145
public static function dataKeywordAsEnumCaseNameShouldBeString()
146146
{
147147
return [
148-
['/* testKeywordAsEnumCaseNameShouldBeString1 */'],
149-
['/* testKeywordAsEnumCaseNameShouldBeString2 */'],
150-
['/* testKeywordAsEnumCaseNameShouldBeString3 */'],
151-
['/* testKeywordAsEnumCaseNameShouldBeString4 */'],
152-
['/* testKeywordAsEnumCaseNameShouldBeString5 */'],
153-
['/* testKeywordAsEnumCaseNameShouldBeString6 */'],
154-
['/* testKeywordAsEnumCaseNameShouldBeString7 */'],
148+
'"interface" as case name' => ['/* testKeywordAsEnumCaseNameShouldBeString1 */'],
149+
'"trait" as case name' => ['/* testKeywordAsEnumCaseNameShouldBeString2 */'],
150+
'"enum" as case name' => ['/* testKeywordAsEnumCaseNameShouldBeString3 */'],
151+
'"function" as case name' => ['/* testKeywordAsEnumCaseNameShouldBeString4 */'],
152+
'"false" as case name' => ['/* testKeywordAsEnumCaseNameShouldBeString5 */'],
153+
'"default" as case name' => ['/* testKeywordAsEnumCaseNameShouldBeString6 */'],
154+
'"array" as case name' => ['/* testKeywordAsEnumCaseNameShouldBeString7 */'],
155155
];
156156

157157
}//end dataKeywordAsEnumCaseNameShouldBeString()

0 commit comments

Comments
 (0)