diff options
author | Raghubansh Kumar <kraghuba@php.net> | 2007-12-03 03:52:06 +0000 |
---|---|---|
committer | Raghubansh Kumar <kraghuba@php.net> | 2007-12-03 03:52:06 +0000 |
commit | 91ea43e4112b993d1ac266e4f0c04ad7919d1a46 (patch) | |
tree | 2af45111c6b11f21ea1626523db666193981c7df | |
parent | a0bfc242ca78d3570e6521aef02d840447381c83 (diff) | |
download | php-git-91ea43e4112b993d1ac266e4f0c04ad7919d1a46.tar.gz |
New testcases for array_chunk() function
-rw-r--r-- | ext/standard/tests/array/array_chunk_basic1.phpt | 235 | ||||
-rw-r--r-- | ext/standard/tests/array/array_chunk_basic2.phpt | 403 | ||||
-rw-r--r-- | ext/standard/tests/array/array_chunk_error.phpt | 64 | ||||
-rw-r--r-- | ext/standard/tests/array/array_chunk_variation1.phpt | 570 | ||||
-rw-r--r-- | ext/standard/tests/array/array_chunk_variation2.phpt | 773 | ||||
-rw-r--r-- | ext/standard/tests/array/array_chunk_variation3.phpt | 463 | ||||
-rw-r--r-- | ext/standard/tests/array/array_chunk_variation4.phpt | 204 | ||||
-rw-r--r-- | ext/standard/tests/array/array_chunk_variation5.phpt | 261 | ||||
-rw-r--r-- | ext/standard/tests/array/array_chunk_variation6.phpt | 221 | ||||
-rw-r--r-- | ext/standard/tests/array/array_chunk_variation7.phpt | 142 |
10 files changed, 3336 insertions, 0 deletions
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..68be1ce8c2 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_basic1.phpt @@ -0,0 +1,235 @@ +--TEST-- +Test array_chunk() function : basic functionality - defualt 'preserve_keys' +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Chunks an array into size large chunks. + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_chunk() : basic functionality ***\n"; +$size = 2; + +$input_arrays = array ( + // array with default keys - numeric values + array(1, 2, 3, 4, 5), + + // array with default keys - string values + array('value1', "value2", "value3"), + + // associative arrays - key as string + array('key1' => 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 +--UEXPECTF-- +*** 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]=> + unicode(6) "value1" + [1]=> + unicode(6) "value2" + } + [1]=> + array(1) { + [0]=> + unicode(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]=> + unicode(3) "one" + [1]=> + unicode(3) "two" + } + [1]=> + array(1) { + [0]=> + unicode(5) "three" + } +} + +-- Iteration 5 -- +array(3) { + [0]=> + array(2) { + [0]=> + unicode(3) "one" + [1]=> + unicode(3) "two" + } + [1]=> + array(2) { + [0]=> + unicode(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..75e41888a6 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_basic2.phpt @@ -0,0 +1,403 @@ +--TEST-- +Test array_chunk() function : basic functionality - 'preserve_keys' as true/false +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Chunks an array into size large chunks. + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_chunk() : basic functionality ***\n"; +$size = 2; + +$input_arrays = array( + // array with default keys - numeric values + array(1, 2, 3, 4, 5), + + // array with default keys - string values + array('value1', "value2", "value3"), + + // associative arrays - key as string + array('key1' => 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 +--UEXPECTF-- +*** 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]=> + unicode(6) "value1" + [1]=> + unicode(6) "value2" + } + [1]=> + array(1) { + [2]=> + unicode(6) "value3" + } +} +array(2) { + [0]=> + array(2) { + [0]=> + unicode(6) "value1" + [1]=> + unicode(6) "value2" + } + [1]=> + array(1) { + [0]=> + unicode(6) "value3" + } +} + +-- Iteration 3 -- +array(2) { + [0]=> + array(2) { + [u"key1"]=> + int(1) + [u"key2"]=> + int(2) + } + [1]=> + array(1) { + [u"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]=> + unicode(3) "one" + [2]=> + unicode(3) "two" + } + [1]=> + array(1) { + [3]=> + unicode(5) "three" + } +} +array(2) { + [0]=> + array(2) { + [0]=> + unicode(3) "one" + [1]=> + unicode(3) "two" + } + [1]=> + array(1) { + [0]=> + unicode(5) "three" + } +} + +-- Iteration 5 -- +array(3) { + [0]=> + array(2) { + [1]=> + unicode(3) "one" + [2]=> + unicode(3) "two" + } + [1]=> + array(2) { + [3]=> + unicode(5) "three" + [4]=> + int(4) + } + [2]=> + array(1) { + [u"five"]=> + int(5) + } +} +array(3) { + [0]=> + array(2) { + [0]=> + unicode(3) "one" + [1]=> + unicode(3) "two" + } + [1]=> + array(2) { + [0]=> + unicode(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..18cd4a0af1 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_error.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_chunk() function : error conditions +--FILE-- +<?php +/* Prototype : array array_chunk(array input, int size [, bool preserve_keys]) + * Description: Split array into chunks + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_chunk() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing array_chunk() function with zero arguments --\n"; +var_dump( array_chunk() ); + +echo "\n-- Testing array_chunk() function with more than expected no. of arguments --\n"; +$input = array(1, 2); +$size = 10; +$preserve_keys = true; +$extra_arg = 10; +var_dump( array_chunk($input,$size,$preserve_keys, $extra_arg) ); + +echo "\n-- Testing array_chunk() function with less than expected no. of arguments --\n"; +$input = array(1, 2); +var_dump( array_chunk($input) ); + +echo "Done"; +?> +--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 +--UEXPECTF-- +*** 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..954a39fdb3 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation1.phpt @@ -0,0 +1,570 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'array' argument +--FILE-- +<?php +/* Prototype : proto array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Chunks an array into size large chunks. + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function with unexpected values for 'array' argument +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// Initialise function arguments +$size = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + + // object data +/*20*/ new stdclass(), + + // undefined data +/*21*/ @undefined_var, + + // unset data +/*22*/ @unset_var + +); + +$count = 1; +// loop through each element of the array for input +foreach($values as $value){ + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($value, $size) ); + var_dump( array_chunk($value, $size, true) ); + var_dump( array_chunk($value, $size, false) ); + $count++; +} + +echo "Done"; +?> +--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 +--UEXPECTF-- +*** 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, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 17 -- + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode 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, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +-- Iteration 22 -- + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 1 to be array, Unicode 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..a131fefb68 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation2.phpt @@ -0,0 +1,773 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'size' argument +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function with unexpected values for 'size' argument +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input = array(1, 2); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array ( + + // float data +/*1*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // array data +/*6*/ array(), + array(0), + array(1), + array(1, 2), + array('color' => '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 +--UEXPECTF-- +*** 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, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +-- Iteration 18 -- + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +-- Iteration 19 -- + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +-- Iteration 20 -- + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode 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, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +-- Iteration 23 -- + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode string given in %s on line %d +NULL + +Warning: array_chunk() expects parameter 2 to be long, Unicode 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..e9911bd8bd --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation3.phpt @@ -0,0 +1,463 @@ +--TEST-- +Test array_chunk() function : usage variations - unexpected values for 'preserve_keys' +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function with unexpected values for 'preserve_keys' +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input = array(1, 2); +$size = 10; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//array of values to iterate over +$values = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // empty data +/*12*/ "", + '', + + // string data +/*14*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var + +); + +$count = 1; + +// loop through each element of the array for preserve_keys +foreach($values as $value) { + echo "\n-- Iteration $count --\n"; + var_dump( array_chunk($input, $size, $value) ); + $count++; +} + +echo "Done"; +?> +--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 +--UEXPECTF-- +*** 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..7049d22697 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation4.phpt @@ -0,0 +1,204 @@ +--TEST-- +Test array_chunk() function : usage variations - array with diff. sub arrays +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_chunk() function - input array containing different sub arrays +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +$size = 2; + +// input array +$input_array = array ( + "array1" => 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 +--UEXPECTF-- +*** 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) { + [u"array1"]=> + array(0) { + } + [u"array2"]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } + } + [1]=> + array(1) { + [u"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..730ef6aa87 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation5.phpt @@ -0,0 +1,261 @@ +--TEST-- +Test array_chunk() function : usage variations - different 'size' values +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_chunk() function with following conditions + * 1. -ve size value + * 2. size value is more than the no. of elements in the input array + * 3. size value is zero + * 4. Decimal size value +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input_array = array(1, 2, 3); + +// different magnitude's +$sizes = array(-1, count($input_array) + 1, 0, 1.5); + +// loop through the array for size argument +foreach ($sizes as $size){ + echo "\n-- Testing array_chunk() when size = $size --\n"; + 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() 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 +--UEXPECTF-- +*** 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..4e93c3d9eb --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation6.phpt @@ -0,0 +1,221 @@ +--TEST-- +Test array_chunk() function : usage variations - different arrays +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_chunk() function with following conditions + * 1. array without elements + * 2. associative array with duplicate keys + * 3. array with one element +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +// input array +$input_arrays = array ( + + // array without elements + "array1" => 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 +--UEXPECTF-- +*** 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) { + [u"a"]=> + int(4) + [u"b"]=> + int(2) + } + [1]=> + array(2) { + [u"c"]=> + int(3) + [u"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..ac70969cd5 --- /dev/null +++ b/ext/standard/tests/array/array_chunk_variation7.phpt @@ -0,0 +1,142 @@ +--TEST-- +Test array_chunk() function : usage variations - references +--FILE-- +<?php +/* Prototype : array array_chunk(array $array, int $size [, bool $preserve_keys]) + * Description: Split array into chunks + * : Chunks an array into size large chunks + * Source code: ext/standard/array.c +*/ + +/* + * Testing array_chunk() function with following conditions + * 1. input array containing references +*/ + +echo "*** Testing array_chunk() : usage variations ***\n"; + +$size = 2; + +echo "\n-- Testing array_chunk(), input array containing references \n"; + +$numbers=array(1, 2, 3, 4); +// reference array +$input_array = array ( + "one" => &$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 +--UEXPECTF-- +*** 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) { + [u"one"]=> + &int(1) + [u"two"]=> + &int(2) + } + [1]=> + array(2) { + [u"three"]=> + &int(3) + [u"four"]=> + &int(4) + } +} +array(2) { + [0]=> + array(2) { + [0]=> + &int(1) + [1]=> + &int(2) + } + [1]=> + array(2) { + [0]=> + &int(3) + [1]=> + &int(4) + } +} +Done |