Skip to content

Commit 4298671

Browse files
committed
Tests/HeredocStringTest: 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 6e895dd commit 4298671

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

tests/Core/Tokenizer/HeredocStringTest.php

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -62,86 +62,94 @@ public function testHeredocStringWrapped($testMarker, $expectedContent)
6262
/**
6363
* Data provider.
6464
*
65+
* Type reference:
66+
* 1. Directly embedded variables.
67+
* 2. Braces outside the variable.
68+
* 3. Braces after the dollar sign.
69+
* 4. Variable variables and expressions.
70+
*
71+
* @link https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation
72+
*
6573
* @see testHeredocString()
6674
*
67-
* @return array
75+
* @return array<string, array<string, string>>
6876
*/
6977
public static function dataHeredocString()
7078
{
7179
return [
72-
[
80+
'Type 1: simple variable' => [
7381
'testMarker' => '/* testSimple1 */',
7482
'expectedContent' => '$foo',
7583
],
76-
[
84+
'Type 2: simple variable' => [
7785
'testMarker' => '/* testSimple2 */',
7886
'expectedContent' => '{$foo}',
7987
],
80-
[
88+
'Type 3: simple variable' => [
8189
'testMarker' => '/* testSimple3 */',
8290
'expectedContent' => '${foo}',
8391
],
84-
[
92+
'Type 1: array offset' => [
8593
'testMarker' => '/* testDIM1 */',
8694
'expectedContent' => '$foo[bar]',
8795
],
88-
[
96+
'Type 2: array offset' => [
8997
'testMarker' => '/* testDIM2 */',
9098
'expectedContent' => '{$foo[\'bar\']}',
9199
],
92-
[
100+
'Type 3: array offset' => [
93101
'testMarker' => '/* testDIM3 */',
94102
'expectedContent' => '${foo[\'bar\']}',
95103
],
96-
[
104+
'Type 1: object property' => [
97105
'testMarker' => '/* testProperty1 */',
98106
'expectedContent' => '$foo->bar',
99107
],
100-
[
108+
'Type 2: object property' => [
101109
'testMarker' => '/* testProperty2 */',
102110
'expectedContent' => '{$foo->bar}',
103111
],
104-
[
112+
'Type 2: object method call' => [
105113
'testMarker' => '/* testMethod1 */',
106114
'expectedContent' => '{$foo->bar()}',
107115
],
108-
[
116+
'Type 2: closure function call' => [
109117
'testMarker' => '/* testClosure1 */',
110118
'expectedContent' => '{$foo()}',
111119
],
112-
[
120+
'Type 2: chaining various syntaxes' => [
113121
'testMarker' => '/* testChain1 */',
114122
'expectedContent' => '{$foo[\'bar\']->baz()()}',
115123
],
116-
[
124+
'Type 4: variable variables' => [
117125
'testMarker' => '/* testVariableVar1 */',
118126
'expectedContent' => '${$bar}',
119127
],
120-
[
128+
'Type 4: variable constants' => [
121129
'testMarker' => '/* testVariableVar2 */',
122130
'expectedContent' => '${(foo)}',
123131
],
124-
[
132+
'Type 4: object property' => [
125133
'testMarker' => '/* testVariableVar3 */',
126134
'expectedContent' => '${foo->bar}',
127135
],
128-
[
136+
'Type 4: variable variable nested in array offset' => [
129137
'testMarker' => '/* testNested1 */',
130138
'expectedContent' => '${foo["${bar}"]}',
131139
],
132-
[
140+
'Type 4: variable array offset nested in array offset' => [
133141
'testMarker' => '/* testNested2 */',
134142
'expectedContent' => '${foo["${bar[\'baz\']}"]}',
135143
],
136-
[
144+
'Type 4: variable object property' => [
137145
'testMarker' => '/* testNested3 */',
138146
'expectedContent' => '${foo->{$baz}}',
139147
],
140-
[
148+
'Type 4: variable object property - complex with single quotes' => [
141149
'testMarker' => '/* testNested4 */',
142150
'expectedContent' => '${foo->{${\'a\'}}}',
143151
],
144-
[
152+
'Type 4: variable object property - complex with single and double quotes' => [
145153
'testMarker' => '/* testNested5 */',
146154
'expectedContent' => '${foo->{"${\'a\'}"}}',
147155
],

0 commit comments

Comments
 (0)