From 6d1ef62c7947012cd23b34df679023c160d8f243 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 20 May 2021 10:50:55 +0200 Subject: [PATCH] Tests/PassedParameters::getParameters(): document behaviour with empty list items ... when using the `$isShortArray = true` parameter. Includes fixing a small error in one of the existing tests. --- .../GetParametersSkipShortArrayCheckTest.inc | 12 +++- .../GetParametersSkipShortArrayCheckTest.php | 60 ++++++++++++++++++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.inc b/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.inc index 0642fb0a..876260d4 100644 --- a/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.inc +++ b/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.inc @@ -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; diff --git a/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php b/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php index edee0e54..8b2eae5b 100644 --- a/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php +++ b/Tests/Utils/PassedParameters/GetParametersSkipShortArrayCheckTest.php @@ -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', ], ], ], @@ -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' => '', + ], + ], + ], ]; } }