Skip to content

Commit 6e895dd

Browse files
committed
Tests/GotoLabelTest: 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.
1 parent 0e094e7 commit 6e895dd

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

tests/Core/Tokenizer/GotoLabelTest.php

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ public function testGotoStatement($testMarker, $testContent)
4343
*
4444
* @see testGotoStatement()
4545
*
46-
* @return array
46+
* @return array<string, array<string, string>>
4747
*/
4848
public static function dataGotoStatement()
4949
{
5050
return [
51-
[
52-
'/* testGotoStatement */',
53-
'marker',
51+
'label for goto statement' => [
52+
'testMarker' => '/* testGotoStatement */',
53+
'testContent' => 'marker',
5454
],
55-
[
56-
'/* testGotoStatementInLoop */',
57-
'end',
55+
'label for goto statement in loop, keyword capitalized' => [
56+
'testMarker' => '/* testGotoStatementInLoop */',
57+
'testContent' => 'end',
5858
],
5959
];
6060

@@ -89,18 +89,18 @@ public function testGotoDeclaration($testMarker, $testContent)
8989
*
9090
* @see testGotoDeclaration()
9191
*
92-
* @return array
92+
* @return array<string, array<string, string>>
9393
*/
9494
public static function dataGotoDeclaration()
9595
{
9696
return [
97-
[
98-
'/* testGotoDeclaration */',
99-
'marker:',
97+
'label in goto declaration - marker' => [
98+
'testMarker' => '/* testGotoDeclaration */',
99+
'testContent' => 'marker:',
100100
],
101-
[
102-
'/* testGotoDeclarationOutsideLoop */',
103-
'end:',
101+
'label in goto declaration - end' => [
102+
'testMarker' => '/* testGotoDeclarationOutsideLoop */',
103+
'testContent' => 'end:',
104104
],
105105
];
106106

@@ -134,38 +134,38 @@ public function testNotAGotoDeclaration($testMarker, $testContent)
134134
*
135135
* @see testNotAGotoDeclaration()
136136
*
137-
* @return array
137+
* @return array<string, array<string, string>>
138138
*/
139139
public static function dataNotAGotoDeclaration()
140140
{
141141
return [
142-
[
143-
'/* testNotGotoDeclarationGlobalConstant */',
144-
'CONSTANT',
142+
'not goto label - global constant followed by switch-case colon' => [
143+
'testMarker' => '/* testNotGotoDeclarationGlobalConstant */',
144+
'testContent' => 'CONSTANT',
145145
],
146-
[
147-
'/* testNotGotoDeclarationNamespacedConstant */',
148-
'CONSTANT',
146+
'not goto label - namespaced constant followed by switch-case colon' => [
147+
'testMarker' => '/* testNotGotoDeclarationNamespacedConstant */',
148+
'testContent' => 'CONSTANT',
149149
],
150-
[
151-
'/* testNotGotoDeclarationClassConstant */',
152-
'CONSTANT',
150+
'not goto label - class constant followed by switch-case colon' => [
151+
'testMarker' => '/* testNotGotoDeclarationClassConstant */',
152+
'testContent' => 'CONSTANT',
153153
],
154-
[
155-
'/* testNotGotoDeclarationClassProperty */',
156-
'property',
154+
'not goto label - class property use followed by switch-case colon' => [
155+
'testMarker' => '/* testNotGotoDeclarationClassProperty */',
156+
'testContent' => 'property',
157157
],
158-
[
159-
'/* testNotGotoDeclarationGlobalConstantInTernary */',
160-
'CONST_A',
158+
'not goto label - global constant followed by ternary else' => [
159+
'testMarker' => '/* testNotGotoDeclarationGlobalConstantInTernary */',
160+
'testContent' => 'CONST_A',
161161
],
162-
[
163-
'/* testNotGotoDeclarationGlobalConstantInTernary */',
164-
'CONST_B',
162+
'not goto label - global constant after ternary else' => [
163+
'testMarker' => '/* testNotGotoDeclarationGlobalConstantInTernary */',
164+
'testContent' => 'CONST_B',
165165
],
166-
[
167-
'/* testNotGotoDeclarationEnumWithType */',
168-
'Suit',
166+
'not goto label - name of backed enum' => [
167+
'testMarker' => '/* testNotGotoDeclarationEnumWithType */',
168+
'testContent' => 'Suit',
169169
],
170170
];
171171

0 commit comments

Comments
 (0)