Skip to content

Commit b223027

Browse files
committed
Tests/NullsafeObjectOperatorTest: 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 minor array normalization. Include making the data type in the docblock more specific.
1 parent 4298671 commit b223027

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

tests/Core/Tokenizer/NullsafeObjectOperatorTest.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class NullsafeObjectOperatorTest extends AbstractMethodUnitTest
1818
/**
1919
* Tokens to search for.
2020
*
21-
* @var array
21+
* @var array<int|string>
2222
*/
2323
protected $find = [
2424
T_NULLSAFE_OBJECT_OPERATOR,
@@ -71,13 +71,13 @@ public function testNullsafeObjectOperator($testMarker)
7171
*
7272
* @see testNullsafeObjectOperator()
7373
*
74-
* @return array
74+
* @return array<string, array<string>>
7575
*/
7676
public static function dataNullsafeObjectOperator()
7777
{
7878
return [
79-
['/* testNullsafeObjectOperator */'],
80-
['/* testNullsafeObjectOperatorWriteContext */'],
79+
'nullsafe operator' => ['/* testNullsafeObjectOperator */'],
80+
'illegal nullsafe operator (write context)' => ['/* testNullsafeObjectOperatorWriteContext */'],
8181
];
8282

8383
}//end dataNullsafeObjectOperator()
@@ -117,21 +117,25 @@ public function testTernaryThen($testMarker, $testObjectOperator=false)
117117
*
118118
* @see testTernaryThen()
119119
*
120-
* @return array
120+
* @return array<string, array<string, string|bool>>
121121
*/
122122
public static function dataTernaryThen()
123123
{
124124
return [
125-
['/* testTernaryThen */'],
126-
[
127-
'/* testParseErrorWhitespaceNotAllowed */',
128-
true,
125+
'ternary then' => [
126+
'testMarker' => '/* testTernaryThen */',
129127
],
130-
[
131-
'/* testParseErrorCommentNotAllowed */',
132-
true,
128+
'whitespace between question mark and object operator' => [
129+
'testMarker' => '/* testParseErrorWhitespaceNotAllowed */',
130+
'testObjectOperator' => true,
131+
],
132+
'comment between question mark and object operator' => [
133+
'testMarker' => '/* testParseErrorCommentNotAllowed */',
134+
'testObjectOperator' => true,
135+
],
136+
'parse error/live coding' => [
137+
'testMarker' => '/* testLiveCoding */',
133138
],
134-
['/* testLiveCoding */'],
135139
];
136140

137141
}//end dataTernaryThen()

0 commit comments

Comments
 (0)