From d47d025881bad9e8f63db125c5276c84013eb091 Mon Sep 17 00:00:00 2001 From: Raghubansh Kumar Date: Mon, 3 Dec 2007 03:55:55 +0000 Subject: [PATCH] New testcases for array_chunk() function --- .../tests/array/array_chunk_basic1.phpt | 138 ++++++ .../tests/array/array_chunk_basic2.phpt | 222 +++++++++ .../tests/array/array_chunk_error.phpt | 46 ++ .../tests/array/array_chunk_variation1.phpt | 325 +++++++++++++ .../tests/array/array_chunk_variation2.phpt | 427 ++++++++++++++++++ .../tests/array/array_chunk_variation3.phpt | 268 +++++++++++ .../tests/array/array_chunk_variation4.phpt | 120 +++++ .../tests/array/array_chunk_variation5.phpt | 148 ++++++ .../tests/array/array_chunk_variation6.phpt | 135 ++++++ .../tests/array/array_chunk_variation7.phpt | 89 ++++ 10 files changed, 1918 insertions(+) create mode 100644 ext/standard/tests/array/array_chunk_basic1.phpt create mode 100644 ext/standard/tests/array/array_chunk_basic2.phpt create mode 100644 ext/standard/tests/array/array_chunk_error.phpt create mode 100644 ext/standard/tests/array/array_chunk_variation1.phpt create mode 100644 ext/standard/tests/array/array_chunk_variation2.phpt create mode 100644 ext/standard/tests/array/array_chunk_variation3.phpt create mode 100644 ext/standard/tests/array/array_chunk_variation4.phpt create mode 100644 ext/standard/tests/array/array_chunk_variation5.phpt create mode 100644 ext/standard/tests/array/array_chunk_variation6.phpt create mode 100644 ext/standard/tests/array/array_chunk_variation7.phpt diff --git a/ext/standard/tests/array/array_chunk_basic1.phpt b/ext/standard/tests/array/array_chunk_basic1.phpt new file mode 100644 index 0000000000..56a90f479b --- /dev/null +++ b/ext/standard/tests/array/array_chunk_basic1.phpt @@ -0,0 +1,138 @@ +--TEST-- +Test array_chunk() function : basic functionality - defualt 'preserve_keys' +--FILE-- + 1, "key2" => 2, "key3" => 3), + + // associative arrays - key as numeric + array(1 => 'one', 2 => "two", 3 => "three"), + + // array containing elements with/witout keys + array(1 => 'one','two', 3 => 'three', 4, "five" => 5) + +); + +$count = 1; +// loop through each element of the array for input +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size) ); + $count++; +} + +echo "Done" +?> +--EXPECTF-- +*** Testing array_chunk() : basic functionality *** + +-- Iteration 1 -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} + +-- Iteration 2 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [0]=> + string(6) "value3" + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +-- Iteration 4 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(1) { + [0]=> + string(5) "three" + } +} + +-- Iteration 5 -- +array(3) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(2) { + [0]=> + string(5) "three" + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_basic2.phpt b/ext/standard/tests/array/array_chunk_basic2.phpt new file mode 100644 index 0000000000..f96d863e12 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_basic2.phpt @@ -0,0 +1,222 @@ +--TEST-- +Test array_chunk() function : basic functionality - 'preserve_keys' as true/false +--FILE-- + 1, "key2" => 2, "key3" => 3), + + // associative arrays - key as numeric + array(1 => 'one', 2 => "two", 3 => "three"), + + // array containing elements with/without keys + array(1 => 'one','two', 3 => 'three', 4, "five" => 5) +); + +$count = 1; +// loop through each element of the array for input +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size, true) ); + var_dump( array_chunk($input_array, $size, false) ); + $count++; +} + +echo "Done" +?> +--EXPECTF-- +*** Testing array_chunk() : basic functionality *** + +-- Iteration 1 -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [2]=> + int(3) + [3]=> + int(4) + } + [2]=> + array(1) { + [4]=> + int(5) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} + +-- Iteration 2 -- +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [2]=> + string(6) "value3" + } +} +array(2) { + [0]=> + array(2) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + } + [1]=> + array(1) { + [0]=> + string(6) "value3" + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + ["key1"]=> + int(1) + ["key2"]=> + int(2) + } + [1]=> + array(1) { + ["key3"]=> + int(3) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(3) + } +} + +-- Iteration 4 -- +array(2) { + [0]=> + array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + } + [1]=> + array(1) { + [3]=> + string(5) "three" + } +} +array(2) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(1) { + [0]=> + string(5) "three" + } +} + +-- Iteration 5 -- +array(3) { + [0]=> + array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + } + [1]=> + array(2) { + [3]=> + string(5) "three" + [4]=> + int(4) + } + [2]=> + array(1) { + ["five"]=> + int(5) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + string(3) "one" + [1]=> + string(3) "two" + } + [1]=> + array(2) { + [0]=> + string(5) "three" + [1]=> + int(4) + } + [2]=> + array(1) { + [0]=> + int(5) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_error.phpt b/ext/standard/tests/array/array_chunk_error.phpt new file mode 100644 index 0000000000..5197945994 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_error.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_chunk() function : error conditions +--FILE-- + +--EXPECTF-- +*** Testing array_chunk() : error conditions *** + +-- Testing array_chunk() function with zero arguments -- + +Warning: array_chunk() expects at least 2 parameters, 0 given in %s on line %d +NULL + +-- Testing array_chunk() function with more than expected no. of arguments -- + +Warning: array_chunk() expects at most 3 parameters, 4 given in %s on line %d +NULL + +-- Testing array_chunk() function with less than expected no. of arguments -- + +Warning: array_chunk() expects at least 2 parameters, 1 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_chunk_variation1.phpt b/ext/standard/tests/array/array_chunk_variation1.phpt new file mode 100644 index 0000000000..caaf274dd1 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation1.phpt @@ -0,0 +1,325 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'array' argument +--FILE-- + +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Iteration 1 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 2 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 3 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 4 -- + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, integer given in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, double given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, null given in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 13 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 14 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 15 -- + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, boolean given in %s on line %d +NULL + +-- Iteration 16 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_chunk() expects parameter 1 to be array, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, object given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_chunk_variation2.phpt b/ext/standard/tests/array/array_chunk_variation2.phpt new file mode 100644 index 0000000000..8cfe994404 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation2.phpt @@ -0,0 +1,427 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'size' argument +--FILE-- + 'red', 'item' => 'pen'), + + // null data +/*11*/ NULL, + null, + + // boolean data +/*13*/ true, + false, + TRUE, + FALSE, + + // empty data +/*17*/ "", + '', + + // string data +/*19*/ "string", + 'string', + + // object data +/*21*/ new stdclass(), + + // undefined data +/*22*/ @undefined_var, + + // unset data +/*23*/ @unset_var + +); + +// loop through each element of the array for size +$count = 1; +foreach($values as $value){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input, $value) ); + var_dump( array_chunk($input, $value, true) ); + var_dump( array_chunk($input, $value, false) ); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Iteration 1 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 2 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 3 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 4 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 5 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 6 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 7 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 8 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 9 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 10 -- + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, array given in %s on line %d +NULL + +-- Iteration 11 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 12 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 13 -- +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +-- Iteration 14 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 15 -- +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } +} +array(2) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } +} + +-- Iteration 16 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 21 -- + +Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, object given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, string given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_chunk_variation3.phpt b/ext/standard/tests/array/array_chunk_variation3.phpt new file mode 100644 index 0000000000..452006a44d --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation3.phpt @@ -0,0 +1,268 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'preserve_keys' +--FILE-- + +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Iteration 1 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 2 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 3 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 4 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 5 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 6 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 7 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 8 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 9 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 10 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 11 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 12 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 13 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 14 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 15 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 16 -- + +Warning: array_chunk() expects parameter 3 to be boolean, object given in %s on line %d +NULL + +-- Iteration 17 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} + +-- Iteration 18 -- +array(1) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation4.phpt b/ext/standard/tests/array/array_chunk_variation4.phpt new file mode 100644 index 0000000000..7f04f51bff --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation4.phpt @@ -0,0 +1,120 @@ +--TEST-- +Test array_chunk() function : usage variations - array with diff. sub arrays +--FILE-- + array(), + "array2" => array(1, 2, 3), + "array3" => array(1) +); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' as defualt --\n"; +var_dump( array_chunk($input_array, $size) ); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = true --\n"; +var_dump( array_chunk($input_array, $size, true) ); + +echo "\n-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = false --\n"; +var_dump( array_chunk($input_array, $size, false) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' as defualt -- +array(2) { + [0]=> + array(2) { + [0]=> + array(0) { + } + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } + } +} + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = true -- +array(2) { + [0]=> + array(2) { + ["array1"]=> + array(0) { + } + ["array2"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + ["array3"]=> + array(1) { + [0]=> + int(1) + } + } +} + +-- Testing array_chunk() by supplying an array containing different sub arrays & 'preserve_key' = false -- +array(2) { + [0]=> + array(2) { + [0]=> + array(0) { + } + [1]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation5.phpt b/ext/standard/tests/array/array_chunk_variation5.phpt new file mode 100644 index 0000000000..8d36092822 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation5.phpt @@ -0,0 +1,148 @@ +--TEST-- +Test array_chunk() function : usage variations - different 'size' values +--FILE-- + +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() when size = -1 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Testing array_chunk() when size = 4 -- +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +-- Testing array_chunk() when size = 0 -- + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d +NULL + +-- Testing array_chunk() when size = 1.5 -- +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [1]=> + int(2) + } + [2]=> + array(1) { + [2]=> + int(3) + } +} +array(3) { + [0]=> + array(1) { + [0]=> + int(1) + } + [1]=> + array(1) { + [0]=> + int(2) + } + [2]=> + array(1) { + [0]=> + int(3) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation6.phpt b/ext/standard/tests/array/array_chunk_variation6.phpt new file mode 100644 index 0000000000..f44eb39604 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation6.phpt @@ -0,0 +1,135 @@ +--TEST-- +Test array_chunk() function : usage variations - different arrays +--FILE-- + array(), + + // array with one element + "array2" => array(1), + + // associative array with duplicate keys + "array3" => array("a" => 1, "b" => 2, "c" => 3, "a" => 4, "d" => 5) + +); + +$size = 2; +$count = 1; + +echo "\n-- Testing array_chunk() by supplying various arrays --\n"; + +// loop through the array for 'array' argument +foreach ($input_arrays as $input_array){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input_array, $size) ); + var_dump( array_chunk($input_array, $size, true) ); + var_dump( array_chunk($input_array, $size, false) ); + $count++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk() by supplying various arrays -- + +-- Iteration 1 -- +array(0) { +} +array(0) { +} +array(0) { +} + +-- Iteration 2 -- +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} +array(1) { + [0]=> + array(1) { + [0]=> + int(1) + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [0]=> + int(4) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +array(2) { + [0]=> + array(2) { + ["a"]=> + int(4) + ["b"]=> + int(2) + } + [1]=> + array(2) { + ["c"]=> + int(3) + ["d"]=> + int(5) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + int(4) + [1]=> + int(2) + } + [1]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +Done diff --git a/ext/standard/tests/array/array_chunk_variation7.phpt b/ext/standard/tests/array/array_chunk_variation7.phpt new file mode 100644 index 0000000000..c8a71964f1 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation7.phpt @@ -0,0 +1,89 @@ +--TEST-- +Test array_chunk() function : usage variations - references +--FILE-- + &$numbers[0], + "two" => &$numbers[1], + "three" => &$numbers[2], + "four" => &$numbers[3] +); + +var_dump( array_chunk($input_array, $size) ); +var_dump( array_chunk($input_array, $size, true) ); +var_dump( array_chunk($input_array, $size, false) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_chunk() : usage variations *** + +-- Testing array_chunk(), input array containing references +array(2) { + [0]=> + array(2) { + [0]=> + &int(1) + [1]=> + &int(2) + } + [1]=> + array(2) { + [0]=> + &int(3) + [1]=> + &int(4) + } +} +array(2) { + [0]=> + array(2) { + ["one"]=> + &int(1) + ["two"]=> + &int(2) + } + [1]=> + array(2) { + ["three"]=> + &int(3) + ["four"]=> + &int(4) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + &int(1) + [1]=> + &int(2) + } + [1]=> + array(2) { + [0]=> + &int(3) + [1]=> + &int(4) + } +} +Done -- 2.40.0