Skip to content

Commit c7218d5

Browse files
committed
Tests/DefaultKeywordTest: use named data within data sets
This commit adds the parameter name for each item in the data set 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 array normalization. Includes making the data type in the docblocks more specific.
1 parent c504bea commit c7218d5

File tree

1 file changed

+102
-58
lines changed

1 file changed

+102
-58
lines changed

tests/Core/Tokenizer/DefaultKeywordTest.php

Lines changed: 102 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -53,40 +53,50 @@ public function testMatchDefault($testMarker, $testContent='default')
5353
*
5454
* @see testMatchDefault()
5555
*
56-
* @return array
56+
* @return array<string, array<string, string>>
5757
*/
5858
public static function dataMatchDefault()
5959
{
6060
return [
61-
'simple_match_default' => ['/* testSimpleMatchDefault */'],
62-
'match_default_in_switch_case_1' => ['/* testMatchDefaultNestedInSwitchCase1 */'],
63-
'match_default_in_switch_case_2' => ['/* testMatchDefaultNestedInSwitchCase2 */'],
64-
'match_default_in_switch_default' => ['/* testMatchDefaultNestedInSwitchDefault */'],
65-
'match_default_containing_switch' => ['/* testMatchDefault */'],
61+
'simple_match_default' => [
62+
'testMarker' => '/* testSimpleMatchDefault */',
63+
],
64+
'match_default_in_switch_case_1' => [
65+
'testMarker' => '/* testMatchDefaultNestedInSwitchCase1 */',
66+
],
67+
'match_default_in_switch_case_2' => [
68+
'testMarker' => '/* testMatchDefaultNestedInSwitchCase2 */',
69+
],
70+
'match_default_in_switch_default' => [
71+
'testMarker' => '/* testMatchDefaultNestedInSwitchDefault */',
72+
],
73+
'match_default_containing_switch' => [
74+
'testMarker' => '/* testMatchDefault */',
75+
],
6676

6777
'match_default_with_nested_long_array_and_default_key' => [
68-
'/* testMatchDefaultWithNestedLongArrayWithClassConstantKey */',
69-
'DEFAULT',
78+
'testMarker' => '/* testMatchDefaultWithNestedLongArrayWithClassConstantKey */',
79+
'testContent' => 'DEFAULT',
7080
],
7181
'match_default_with_nested_long_array_and_default_key_2' => [
72-
'/* testMatchDefaultWithNestedLongArrayWithClassConstantKeyLevelDown */',
73-
'DEFAULT',
82+
'testMarker' => '/* testMatchDefaultWithNestedLongArrayWithClassConstantKeyLevelDown */',
83+
'testContent' => 'DEFAULT',
7484
],
7585
'match_default_with_nested_short_array_and_default_key' => [
76-
'/* testMatchDefaultWithNestedShortArrayWithClassConstantKey */',
77-
'DEFAULT',
86+
'testMarker' => '/* testMatchDefaultWithNestedShortArrayWithClassConstantKey */',
87+
'testContent' => 'DEFAULT',
7888
],
7989
'match_default_with_nested_short_array_and_default_key_2' => [
80-
'/* testMatchDefaultWithNestedShortArrayWithClassConstantKeyLevelDown */',
81-
'DEFAULT',
90+
'testMarker' => '/* testMatchDefaultWithNestedShortArrayWithClassConstantKeyLevelDown */',
91+
'testContent' => 'DEFAULT',
8292
],
8393
'match_default_in_long_array' => [
84-
'/* testMatchDefaultNestedInLongArray */',
85-
'DEFAULT',
94+
'testMarker' => '/* testMatchDefaultNestedInLongArray */',
95+
'testContent' => 'DEFAULT',
8696
],
8797
'match_default_in_short_array' => [
88-
'/* testMatchDefaultNestedInShortArray */',
89-
'DEFAULT',
98+
'testMarker' => '/* testMatchDefaultNestedInShortArray */',
99+
'testContent' => 'DEFAULT',
90100
],
91101
];
92102

@@ -169,40 +179,40 @@ public function testSwitchDefault($testMarker, $openerOffset, $closerOffset, $co
169179
*
170180
* @see testSwitchDefault()
171181
*
172-
* @return array
182+
* @return array<string, array<string, string|int>>
173183
*/
174184
public static function dataSwitchDefault()
175185
{
176186
return [
177187
'simple_switch_default' => [
178-
'/* testSimpleSwitchDefault */',
179-
1,
180-
4,
188+
'testMarker' => '/* testSimpleSwitchDefault */',
189+
'openerOffset' => 1,
190+
'closerOffset' => 4,
181191
],
182192
'simple_switch_default_with_curlies' => [
183193
// For a default structure with curly braces, the scope opener
184194
// will be the open curly and the closer the close curly.
185195
// However, scope conditions will not be set for open to close,
186196
// but only for the open token up to the "break/return/continue" etc.
187-
'/* testSimpleSwitchDefaultWithCurlies */',
188-
3,
189-
12,
190-
6,
197+
'testMarker' => '/* testSimpleSwitchDefaultWithCurlies */',
198+
'openerOffset' => 3,
199+
'closerOffset' => 12,
200+
'conditionStop' => 6,
191201
],
192202
'switch_default_toplevel' => [
193-
'/* testSwitchDefault */',
194-
1,
195-
43,
203+
'testMarker' => '/* testSwitchDefault */',
204+
'openerOffset' => 1,
205+
'closerOffset' => 43,
196206
],
197207
'switch_default_nested_in_match_case' => [
198-
'/* testSwitchDefaultNestedInMatchCase */',
199-
1,
200-
20,
208+
'testMarker' => '/* testSwitchDefaultNestedInMatchCase */',
209+
'openerOffset' => 1,
210+
'closerOffset' => 20,
201211
],
202212
'switch_default_nested_in_match_default' => [
203-
'/* testSwitchDefaultNestedInMatchDefault */',
204-
1,
205-
18,
213+
'testMarker' => '/* testSwitchDefaultNestedInMatchDefault */',
214+
'openerOffset' => 1,
215+
'closerOffset' => 18,
206216
],
207217
];
208218

@@ -244,34 +254,68 @@ public function testNotDefaultKeyword($testMarker, $testContent='DEFAULT')
244254
*
245255
* @see testNotDefaultKeyword()
246256
*
247-
* @return array
257+
* @return array<string, array<string, string>>
248258
*/
249259
public static function dataNotDefaultKeyword()
250260
{
251261
return [
252-
'class-constant-as-short-array-key' => ['/* testClassConstantAsShortArrayKey */'],
253-
'class-property-as-short-array-key' => ['/* testClassPropertyAsShortArrayKey */'],
254-
'namespaced-constant-as-short-array-key' => ['/* testNamespacedConstantAsShortArrayKey */'],
255-
'fqn-global-constant-as-short-array-key' => ['/* testFQNGlobalConstantAsShortArrayKey */'],
256-
'class-constant-as-long-array-key' => ['/* testClassConstantAsLongArrayKey */'],
257-
'class-constant-as-yield-key' => ['/* testClassConstantAsYieldKey */'],
258-
259-
'class-constant-as-long-array-key-nested-in-match' => ['/* testClassConstantAsLongArrayKeyNestedInMatch */'],
260-
'class-constant-as-long-array-key-nested-in-match-2' => ['/* testClassConstantAsLongArrayKeyNestedInMatchLevelDown */'],
261-
'class-constant-as-short-array-key-nested-in-match' => ['/* testClassConstantAsShortArrayKeyNestedInMatch */'],
262-
'class-constant-as-short-array-key-nested-in-match-2' => ['/* testClassConstantAsShortArrayKeyNestedInMatchLevelDown */'],
263-
'class-constant-as-long-array-key-with-nested-match' => ['/* testClassConstantAsLongArrayKeyWithNestedMatch */'],
264-
'class-constant-as-short-array-key-with-nested-match' => ['/* testClassConstantAsShortArrayKeyWithNestedMatch */'],
265-
266-
'class-constant-in-switch-case' => ['/* testClassConstantInSwitchCase */'],
267-
'class-property-in-switch-case' => ['/* testClassPropertyInSwitchCase */'],
268-
'namespaced-constant-in-switch-case' => ['/* testNamespacedConstantInSwitchCase */'],
269-
'namespace-relative-constant-in-switch-case' => ['/* testNamespaceRelativeConstantInSwitchCase */'],
270-
271-
'class-constant-declaration' => ['/* testClassConstant */'],
262+
'class-constant-as-short-array-key' => [
263+
'testMarker' => '/* testClassConstantAsShortArrayKey */',
264+
],
265+
'class-property-as-short-array-key' => [
266+
'testMarker' => '/* testClassPropertyAsShortArrayKey */',
267+
],
268+
'namespaced-constant-as-short-array-key' => [
269+
'testMarker' => '/* testNamespacedConstantAsShortArrayKey */',
270+
],
271+
'fqn-global-constant-as-short-array-key' => [
272+
'testMarker' => '/* testFQNGlobalConstantAsShortArrayKey */',
273+
],
274+
'class-constant-as-long-array-key' => [
275+
'testMarker' => '/* testClassConstantAsLongArrayKey */',
276+
],
277+
'class-constant-as-yield-key' => [
278+
'testMarker' => '/* testClassConstantAsYieldKey */',
279+
],
280+
281+
'class-constant-as-long-array-key-nested-in-match' => [
282+
'testMarker' => '/* testClassConstantAsLongArrayKeyNestedInMatch */',
283+
],
284+
'class-constant-as-long-array-key-nested-in-match-2' => [
285+
'testMarker' => '/* testClassConstantAsLongArrayKeyNestedInMatchLevelDown */',
286+
],
287+
'class-constant-as-short-array-key-nested-in-match' => [
288+
'testMarker' => '/* testClassConstantAsShortArrayKeyNestedInMatch */',
289+
],
290+
'class-constant-as-short-array-key-nested-in-match-2' => [
291+
'testMarker' => '/* testClassConstantAsShortArrayKeyNestedInMatchLevelDown */',
292+
],
293+
'class-constant-as-long-array-key-with-nested-match' => [
294+
'testMarker' => '/* testClassConstantAsLongArrayKeyWithNestedMatch */',
295+
],
296+
'class-constant-as-short-array-key-with-nested-match' => [
297+
'testMarker' => '/* testClassConstantAsShortArrayKeyWithNestedMatch */',
298+
],
299+
300+
'class-constant-in-switch-case' => [
301+
'testMarker' => '/* testClassConstantInSwitchCase */',
302+
],
303+
'class-property-in-switch-case' => [
304+
'testMarker' => '/* testClassPropertyInSwitchCase */',
305+
],
306+
'namespaced-constant-in-switch-case' => [
307+
'testMarker' => '/* testNamespacedConstantInSwitchCase */',
308+
],
309+
'namespace-relative-constant-in-switch-case' => [
310+
'testMarker' => '/* testNamespaceRelativeConstantInSwitchCase */',
311+
],
312+
313+
'class-constant-declaration' => [
314+
'testMarker' => '/* testClassConstant */',
315+
],
272316
'class-method-declaration' => [
273-
'/* testMethodDeclaration */',
274-
'default',
317+
'testMarker' => '/* testMethodDeclaration */',
318+
'testContent' => 'default',
275319
],
276320
];
277321

0 commit comments

Comments
 (0)