Skip to content

Commit 075ab2c

Browse files
committed
Tests/DoubleQuotedStringTest: 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 c7218d5 commit 075ab2c

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

tests/Core/Tokenizer/DoubleQuotedStringTest.php

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,90 +40,98 @@ public function testDoubleQuotedString($testMarker, $expectedContent)
4040
/**
4141
* Data provider.
4242
*
43+
* Type reference:
44+
* 1. Directly embedded variables.
45+
* 2. Braces outside the variable.
46+
* 3. Braces after the dollar sign.
47+
* 4. Variable variables and expressions.
48+
*
49+
* @link https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation
50+
*
4351
* @see testDoubleQuotedString()
4452
*
45-
* @return array
53+
* @return array<string, array<string, string>>
4654
*/
4755
public static function dataDoubleQuotedString()
4856
{
4957
return [
50-
[
58+
'Type 1: simple variable' => [
5159
'testMarker' => '/* testSimple1 */',
5260
'expectedContent' => '"$foo"',
5361
],
54-
[
62+
'Type 2: simple variable' => [
5563
'testMarker' => '/* testSimple2 */',
5664
'expectedContent' => '"{$foo}"',
5765
],
58-
[
66+
'Type 3: simple variable' => [
5967
'testMarker' => '/* testSimple3 */',
6068
'expectedContent' => '"${foo}"',
6169
],
62-
[
70+
'Type 1: array offset' => [
6371
'testMarker' => '/* testDIM1 */',
6472
'expectedContent' => '"$foo[bar]"',
6573
],
66-
[
74+
'Type 2: array offset' => [
6775
'testMarker' => '/* testDIM2 */',
6876
'expectedContent' => '"{$foo[\'bar\']}"',
6977
],
70-
[
78+
'Type 3: array offset' => [
7179
'testMarker' => '/* testDIM3 */',
7280
'expectedContent' => '"${foo[\'bar\']}"',
7381
],
74-
[
82+
'Type 1: object property' => [
7583
'testMarker' => '/* testProperty1 */',
7684
'expectedContent' => '"$foo->bar"',
7785
],
78-
[
86+
'Type 2: object property' => [
7987
'testMarker' => '/* testProperty2 */',
8088
'expectedContent' => '"{$foo->bar}"',
8189
],
82-
[
90+
'Type 2: object method call' => [
8391
'testMarker' => '/* testMethod1 */',
8492
'expectedContent' => '"{$foo->bar()}"',
8593
],
86-
[
94+
'Type 2: closure function call' => [
8795
'testMarker' => '/* testClosure1 */',
8896
'expectedContent' => '"{$foo()}"',
8997
],
90-
[
98+
'Type 2: chaining various syntaxes' => [
9199
'testMarker' => '/* testChain1 */',
92100
'expectedContent' => '"{$foo[\'bar\']->baz()()}"',
93101
],
94-
[
102+
'Type 4: variable variables' => [
95103
'testMarker' => '/* testVariableVar1 */',
96104
'expectedContent' => '"${$bar}"',
97105
],
98-
[
106+
'Type 4: variable constants' => [
99107
'testMarker' => '/* testVariableVar2 */',
100108
'expectedContent' => '"${(foo)}"',
101109
],
102-
[
110+
'Type 4: object property' => [
103111
'testMarker' => '/* testVariableVar3 */',
104112
'expectedContent' => '"${foo->bar}"',
105113
],
106-
[
114+
'Type 4: variable variable nested in array offset' => [
107115
'testMarker' => '/* testNested1 */',
108116
'expectedContent' => '"${foo["${bar}"]}"',
109117
],
110-
[
118+
'Type 4: variable array offset nested in array offset' => [
111119
'testMarker' => '/* testNested2 */',
112120
'expectedContent' => '"${foo["${bar[\'baz\']}"]}"',
113121
],
114-
[
122+
'Type 4: variable object property' => [
115123
'testMarker' => '/* testNested3 */',
116124
'expectedContent' => '"${foo->{$baz}}"',
117125
],
118-
[
126+
'Type 4: variable object property - complex with single quotes' => [
119127
'testMarker' => '/* testNested4 */',
120128
'expectedContent' => '"${foo->{${\'a\'}}}"',
121129
],
122-
[
130+
'Type 4: variable object property - complex with single and double quotes' => [
123131
'testMarker' => '/* testNested5 */',
124132
'expectedContent' => '"${foo->{"${\'a\'}"}}"',
125133
],
126-
[
134+
'Type 4: live coding/parse error' => [
127135
'testMarker' => '/* testParseError */',
128136
'expectedContent' => '"${foo["${bar
129137
',

0 commit comments

Comments
 (0)