Skip to content

Commit 0cf9a85

Browse files
authored
Merge pull request #270 from PHPCSStandards/passedparameters/test-document-behaviour-empty-list-items
Tests/PassedParameters::getParameters(): document behaviour with empty list items
2 parents 4968182 + 6d1ef62 commit 0cf9a85

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.inc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@ $foo = array( 1, 2 );
1010
$foo = [ 'a' => 1, 'b' => 2 ];
1111

1212
/* testShortList */
13-
[ 'a' => 1, 'b' => 2 ] = $array;
13+
[ 'a' => $a, 'b' => $b ] = $array;
1414

1515
/* testArrayAssign */
1616
$array[] = 'foo';
1717

1818
/* testArrayAccess */
1919
$foo = $array[$keys['key']];
20+
21+
/* testShortListWithEmptyItemsBefore */
22+
[, , $a] = $array;
23+
24+
/* testShortListWithEmptyItemsAfter */
25+
[$a,,] = $array;
26+
27+
/* testShortListWithAllEmptyItems */
28+
// Not allowed, but not our concern.
29+
[,,] = $array;

Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ public function dataTestCases()
165165
1 => [
166166
'start' => 1,
167167
'end' => 6,
168-
'raw' => "'a' => 1",
168+
'raw' => '\'a\' => $a',
169169
],
170170
2 => [
171171
'start' => 8,
172172
'end' => 14,
173-
'raw' => "'b' => 2",
173+
'raw' => '\'b\' => $b',
174174
],
175175
],
176176
],
@@ -192,6 +192,62 @@ public function dataTestCases()
192192
],
193193
],
194194
],
195+
'short-list-with-empties-before' => [
196+
'/* testShortListWithEmptyItemsBefore */',
197+
\T_OPEN_SHORT_ARRAY,
198+
true,
199+
[
200+
1 => [
201+
'start' => 1,
202+
'end' => 0,
203+
'raw' => '',
204+
],
205+
2 => [
206+
'start' => 2,
207+
'end' => 2,
208+
'raw' => '',
209+
],
210+
3 => [
211+
'start' => 4,
212+
'end' => 5,
213+
'raw' => '$a',
214+
],
215+
],
216+
],
217+
'short-list-with-empties-after' => [
218+
'/* testShortListWithEmptyItemsAfter */',
219+
\T_OPEN_SHORT_ARRAY,
220+
true,
221+
[
222+
1 => [
223+
'start' => 1,
224+
'end' => 1,
225+
'raw' => '$a',
226+
],
227+
2 => [
228+
'start' => 3,
229+
'end' => 2,
230+
'raw' => '',
231+
],
232+
],
233+
],
234+
'short-list-with-all-empties' => [
235+
'/* testShortListWithAllEmptyItems */',
236+
\T_OPEN_SHORT_ARRAY,
237+
true,
238+
[
239+
1 => [
240+
'start' => 1,
241+
'end' => 0,
242+
'raw' => '',
243+
],
244+
2 => [
245+
'start' => 2,
246+
'end' => 1,
247+
'raw' => '',
248+
],
249+
],
250+
],
195251
];
196252
}
197253
}

0 commit comments

Comments
 (0)