Skip to content

Commit

Permalink
Merge pull request #270 from PHPCSStandards/passedparameters/test-doc…
Browse files Browse the repository at this point in the history
…ument-behaviour-empty-list-items

Tests/PassedParameters::getParameters(): document behaviour with empty list items
  • Loading branch information
jrfnl committed May 20, 2021
2 parents 4968182 + 6d1ef62 commit 0cf9a85
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ $foo = array( 1, 2 );
$foo = [ 'a' => 1, 'b' => 2 ];

/* testShortList */
[ 'a' => 1, 'b' => 2 ] = $array;
[ 'a' => $a, 'b' => $b ] = $array;

/* testArrayAssign */
$array[] = 'foo';

/* testArrayAccess */
$foo = $array[$keys['key']];

/* testShortListWithEmptyItemsBefore */
[, , $a] = $array;

/* testShortListWithEmptyItemsAfter */
[$a,,] = $array;

/* testShortListWithAllEmptyItems */
// Not allowed, but not our concern.
[,,] = $array;
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ public function dataTestCases()
1 => [
'start' => 1,
'end' => 6,
'raw' => "'a' => 1",
'raw' => '\'a\' => $a',
],
2 => [
'start' => 8,
'end' => 14,
'raw' => "'b' => 2",
'raw' => '\'b\' => $b',
],
],
],
Expand All @@ -192,6 +192,62 @@ public function dataTestCases()
],
],
],
'short-list-with-empties-before' => [
'/* testShortListWithEmptyItemsBefore */',
\T_OPEN_SHORT_ARRAY,
true,
[
1 => [
'start' => 1,
'end' => 0,
'raw' => '',
],
2 => [
'start' => 2,
'end' => 2,
'raw' => '',
],
3 => [
'start' => 4,
'end' => 5,
'raw' => '$a',
],
],
],
'short-list-with-empties-after' => [
'/* testShortListWithEmptyItemsAfter */',
\T_OPEN_SHORT_ARRAY,
true,
[
1 => [
'start' => 1,
'end' => 1,
'raw' => '$a',
],
2 => [
'start' => 3,
'end' => 2,
'raw' => '',
],
],
],
'short-list-with-all-empties' => [
'/* testShortListWithAllEmptyItems */',
\T_OPEN_SHORT_ARRAY,
true,
[
1 => [
'start' => 1,
'end' => 0,
'raw' => '',
],
2 => [
'start' => 2,
'end' => 1,
'raw' => '',
],
],
],
];
}
}

0 comments on commit 0cf9a85

Please sign in to comment.