Skip to content

Commit 34bdfaa

Browse files
committed
Tests/NamedFunctionCallArgumentsTest: 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. Include making the data type in the docblock more specific.
1 parent fc1b8c6 commit 34bdfaa

File tree

1 file changed

+107
-107
lines changed

1 file changed

+107
-107
lines changed

tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php

Lines changed: 107 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ final class NamedFunctionCallArgumentsTest extends AbstractMethodUnitTest
2020
* Verify that parameter labels are tokenized as T_PARAM_NAME and that
2121
* the colon after it is tokenized as a T_COLON.
2222
*
23-
* @param string $testMarker The comment prefacing the target token.
24-
* @param array $parameters The token content for each parameter label to look for.
23+
* @param string $testMarker The comment prefacing the target token.
24+
* @param array<string> $parameters The token content for each parameter label to look for.
2525
*
2626
* @dataProvider dataNamedFunctionCallArguments
2727
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
@@ -74,206 +74,206 @@ public function testNamedFunctionCallArguments($testMarker, $parameters)
7474
*
7575
* @see testNamedFunctionCallArguments()
7676
*
77-
* @return array
77+
* @return array<string, array<string, string|array<string>>>
7878
*/
7979
public static function dataNamedFunctionCallArguments()
8080
{
8181
return [
82-
[
83-
'/* testNamedArgs */',
84-
[
82+
'function call, single line, all named args' => [
83+
'testMarker' => '/* testNamedArgs */',
84+
'parameters' => [
8585
'start_index',
8686
'count',
8787
'value',
8888
],
8989
],
90-
[
91-
'/* testNamedArgsMultiline */',
92-
[
90+
'function call, multi-line, all named args' => [
91+
'testMarker' => '/* testNamedArgsMultiline */',
92+
'parameters' => [
9393
'start_index',
9494
'count',
9595
'value',
9696
],
9797
],
98-
[
99-
'/* testNamedArgsWithWhitespaceAndComments */',
100-
[
98+
'function call, single line, all named args; comments and whitespace' => [
99+
'testMarker' => '/* testNamedArgsWithWhitespaceAndComments */',
100+
'parameters' => [
101101
'start_index',
102102
'count',
103103
'value',
104104
],
105105
],
106-
[
107-
'/* testMixedPositionalAndNamedArgs */',
108-
[
106+
'function call, single line, mixed positional and named args' => [
107+
'testMarker' => '/* testMixedPositionalAndNamedArgs */',
108+
'parameters' => [
109109
'double_encode',
110110
],
111111
],
112-
[
113-
'/* testNestedFunctionCallOuter */',
114-
[
112+
'function call containing nested function call values' => [
113+
'testMarker' => '/* testNestedFunctionCallOuter */',
114+
'parameters' => [
115115
'start_index',
116116
'count',
117117
'value',
118118
],
119119
],
120-
[
121-
'/* testNestedFunctionCallInner1 */',
122-
[
120+
'function call nested in named arg [1]' => [
121+
'testMarker' => '/* testNestedFunctionCallInner1 */',
122+
'parameters' => [
123123
'skip',
124124
],
125125
],
126-
[
127-
'/* testNestedFunctionCallInner2 */',
128-
[
126+
'function call nested in named arg [2]' => [
127+
'testMarker' => '/* testNestedFunctionCallInner2 */',
128+
'parameters' => [
129129
'array_or_countable',
130130
],
131131
],
132-
[
133-
'/* testNamespaceRelativeFunction */',
134-
[
132+
'namespace relative function call' => [
133+
'testMarker' => '/* testNamespaceRelativeFunction */',
134+
'parameters' => [
135135
'label',
136136
'more',
137137
],
138138
],
139-
[
140-
'/* testPartiallyQualifiedFunction */',
141-
[
139+
'partially qualified function call' => [
140+
'testMarker' => '/* testPartiallyQualifiedFunction */',
141+
'parameters' => [
142142
'label',
143143
'more',
144144
],
145145
],
146-
[
147-
'/* testFullyQualifiedFunction */',
148-
[
146+
'fully qualified function call' => [
147+
'testMarker' => '/* testFullyQualifiedFunction */',
148+
'parameters' => [
149149
'label',
150150
'more',
151151
],
152152
],
153-
[
154-
'/* testVariableFunction */',
155-
[
153+
'variable function call' => [
154+
'testMarker' => '/* testVariableFunction */',
155+
'parameters' => [
156156
'label',
157157
'more',
158158
],
159159
],
160-
[
161-
'/* testVariableVariableFunction */',
162-
[
160+
'variable variable function call' => [
161+
'testMarker' => '/* testVariableVariableFunction */',
162+
'parameters' => [
163163
'label',
164164
'more',
165165
],
166166
],
167-
[
168-
'/* testMethodCall */',
169-
[
167+
'method call' => [
168+
'testMarker' => '/* testMethodCall */',
169+
'parameters' => [
170170
'label',
171171
'more',
172172
],
173173
],
174-
[
175-
'/* testVariableMethodCall */',
176-
[
174+
'variable method call' => [
175+
'testMarker' => '/* testVariableMethodCall */',
176+
'parameters' => [
177177
'label',
178178
'more',
179179
],
180180
],
181-
[
182-
'/* testClassInstantiation */',
183-
[
181+
'class instantiation' => [
182+
'testMarker' => '/* testClassInstantiation */',
183+
'parameters' => [
184184
'label',
185185
'more',
186186
],
187187
],
188-
[
189-
'/* testClassInstantiationSelf */',
190-
[
188+
'class instantiation with "self"' => [
189+
'testMarker' => '/* testClassInstantiationSelf */',
190+
'parameters' => [
191191
'label',
192192
'more',
193193
],
194194
],
195-
[
196-
'/* testClassInstantiationStatic */',
197-
[
195+
'class instantiation with "static"' => [
196+
'testMarker' => '/* testClassInstantiationStatic */',
197+
'parameters' => [
198198
'label',
199199
'more',
200200
],
201201
],
202-
[
203-
'/* testAnonClass */',
204-
[
202+
'anonymous class instantiation' => [
203+
'testMarker' => '/* testAnonClass */',
204+
'parameters' => [
205205
'label',
206206
'more',
207207
],
208208
],
209-
[
210-
'/* testNonAsciiNames */',
211-
[
209+
'function call with non-ascii characters in the variable name labels' => [
210+
'testMarker' => '/* testNonAsciiNames */',
211+
'parameters' => [
212212
'💩💩💩',
213213
'Пасха',
214214
'_valid',
215215
],
216216
],
217217

218218
// Coding errors which should still be handled.
219-
[
220-
'/* testCompileErrorNamedBeforePositional */',
221-
[
219+
'invalid: named arg before positional (compile error)' => [
220+
'testMarker' => '/* testCompileErrorNamedBeforePositional */',
221+
'parameters' => [
222222
'param',
223223
],
224224
],
225-
[
226-
'/* testDuplicateName1 */',
227-
[
225+
'invalid: duplicate parameter name [1]' => [
226+
'testMarker' => '/* testDuplicateName1 */',
227+
'parameters' => [
228228
'param',
229229
],
230230
],
231-
[
232-
'/* testDuplicateName2 */',
233-
[
231+
'invalid: duplicate parameter name [2]' => [
232+
'testMarker' => '/* testDuplicateName2 */',
233+
'parameters' => [
234234
'param',
235235
],
236236
],
237-
[
238-
'/* testIncorrectOrderWithVariadic */',
239-
[
237+
'invalid: named arg before variadic (error exception)' => [
238+
'testMarker' => '/* testIncorrectOrderWithVariadic */',
239+
'parameters' => [
240240
'start_index',
241241
],
242242
],
243-
[
244-
'/* testCompileErrorIncorrectOrderWithVariadic */',
245-
[
243+
'invalid: named arg after variadic (compile error)' => [
244+
'testMarker' => '/* testCompileErrorIncorrectOrderWithVariadic */',
245+
'parameters' => [
246246
'param',
247247
],
248248
],
249-
[
250-
'/* testParseErrorNoValue */',
251-
[
249+
'invalid: named arg without value (parse error)' => [
250+
'testMarker' => '/* testParseErrorNoValue */',
251+
'parameters' => [
252252
'param1',
253253
'param2',
254254
],
255255
],
256-
[
257-
'/* testParseErrorExit */',
258-
[
256+
'invalid: named arg in exit() (parse error)' => [
257+
'testMarker' => '/* testParseErrorExit */',
258+
'parameters' => [
259259
'status',
260260
],
261261
],
262-
[
263-
'/* testParseErrorEmpty */',
264-
[
262+
'invalid: named arg in empty() (parse error)' => [
263+
'testMarker' => '/* testParseErrorEmpty */',
264+
'parameters' => [
265265
'variable',
266266
],
267267
],
268-
[
269-
'/* testParseErrorEval */',
270-
[
268+
'invalid: named arg in eval() (parse error)' => [
269+
'testMarker' => '/* testParseErrorEval */',
270+
'parameters' => [
271271
'code',
272272
],
273273
],
274-
[
275-
'/* testParseErrorArbitraryParentheses */',
276-
[
274+
'invalid: named arg in arbitrary parentheses (parse error)' => [
275+
'testMarker' => '/* testParseErrorArbitraryParentheses */',
276+
'parameters' => [
277277
'something',
278278
],
279279
],
@@ -318,26 +318,26 @@ public function testOtherTstringInFunctionCall($testMarker, $content)
318318
*
319319
* @see testOtherTstringInFunctionCall()
320320
*
321-
* @return array
321+
* @return array<string, array<string, string>>
322322
*/
323323
public static function dataOtherTstringInFunctionCall()
324324
{
325325
return [
326-
[
327-
'/* testPositionalArgs */',
328-
'START_INDEX',
326+
'not arg name - global constant' => [
327+
'testMarker' => '/* testPositionalArgs */',
328+
'content' => 'START_INDEX',
329329
],
330-
[
331-
'/* testPositionalArgs */',
332-
'COUNT',
330+
'not arg name - fully qualified constant' => [
331+
'testMarker' => '/* testPositionalArgs */',
332+
'content' => 'COUNT',
333333
],
334-
[
335-
'/* testPositionalArgs */',
336-
'VALUE',
334+
'not arg name - namespace relative constant' => [
335+
'testMarker' => '/* testPositionalArgs */',
336+
'content' => 'VALUE',
337337
],
338-
[
339-
'/* testNestedFunctionCallInner2 */',
340-
'count',
338+
'not arg name - unqualified function call' => [
339+
'testMarker' => '/* testNestedFunctionCallInner2 */',
340+
'content' => 'count',
341341
],
342342
];
343343

@@ -716,9 +716,9 @@ public function testParseErrorVariableLabel()
716716
* Verify that reserved keywords used as a parameter label are tokenized as T_PARAM_NAME
717717
* and that the colon after it is tokenized as a T_COLON.
718718
*
719-
* @param string $testMarker The comment prefacing the target token.
720-
* @param array $tokenTypes The token codes to look for.
721-
* @param string $tokenContent The token content to look for.
719+
* @param string $testMarker The comment prefacing the target token.
720+
* @param array<string|int> $tokenTypes The token codes to look for.
721+
* @param string $tokenContent The token content to look for.
722722
*
723723
* @dataProvider dataReservedKeywordsAsName
724724
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
@@ -768,7 +768,7 @@ public function testReservedKeywordsAsName($testMarker, $tokenTypes, $tokenConte
768768
*
769769
* @see testReservedKeywordsAsName()
770770
*
771-
* @return array
771+
* @return array<string, array<string|array<string|int>>>
772772
*/
773773
public static function dataReservedKeywordsAsName()
774774
{

0 commit comments

Comments
 (0)