]> granicus.if.org Git - php/commitdiff
New testcases for array_chunk() function
authorRaghubansh Kumar <kraghuba@php.net>
Mon, 3 Dec 2007 03:55:55 +0000 (03:55 +0000)
committerRaghubansh Kumar <kraghuba@php.net>
Mon, 3 Dec 2007 03:55:55 +0000 (03:55 +0000)
ext/standard/tests/array/array_chunk_basic1.phpt [new file with mode: 0644]
ext/standard/tests/array/array_chunk_basic2.phpt [new file with mode: 0644]
ext/standard/tests/array/array_chunk_error.phpt [new file with mode: 0644]
ext/standard/tests/array/array_chunk_variation1.phpt [new file with mode: 0644]
ext/standard/tests/array/array_chunk_variation2.phpt [new file with mode: 0644]
ext/standard/tests/array/array_chunk_variation3.phpt [new file with mode: 0644]
ext/standard/tests/array/array_chunk_variation4.phpt [new file with mode: 0644]
ext/standard/tests/array/array_chunk_variation5.phpt [new file with mode: 0644]
ext/standard/tests/array/array_chunk_variation6.phpt [new file with mode: 0644]
ext/standard/tests/array/array_chunk_variation7.phpt [new file with mode: 0644]

diff --git a/ext/standard/tests/array/array_chunk_basic1.phpt b/ext/standard/tests/array/array_chunk_basic1.phpt
new file mode 100644 (file)
index 0000000..56a90f4
--- /dev/null
@@ -0,0 +1,138 @@
+--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
diff --git a/ext/standard/tests/array/array_chunk_basic2.phpt b/ext/standard/tests/array/array_chunk_basic2.phpt
new file mode 100644 (file)
index 0000000..f96d863
--- /dev/null
@@ -0,0 +1,222 @@
+--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
diff --git a/ext/standard/tests/array/array_chunk_error.phpt b/ext/standard/tests/array/array_chunk_error.phpt
new file mode 100644 (file)
index 0000000..5197945
--- /dev/null
@@ -0,0 +1,46 @@
+--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
diff --git a/ext/standard/tests/array/array_chunk_variation1.phpt b/ext/standard/tests/array/array_chunk_variation1.phpt
new file mode 100644 (file)
index 0000000..caaf274
--- /dev/null
@@ -0,0 +1,325 @@
+--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
diff --git a/ext/standard/tests/array/array_chunk_variation2.phpt b/ext/standard/tests/array/array_chunk_variation2.phpt
new file mode 100644 (file)
index 0000000..8cfe994
--- /dev/null
@@ -0,0 +1,427 @@
+--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
diff --git a/ext/standard/tests/array/array_chunk_variation3.phpt b/ext/standard/tests/array/array_chunk_variation3.phpt
new file mode 100644 (file)
index 0000000..452006a
--- /dev/null
@@ -0,0 +1,268 @@
+--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
diff --git a/ext/standard/tests/array/array_chunk_variation4.phpt b/ext/standard/tests/array/array_chunk_variation4.phpt
new file mode 100644 (file)
index 0000000..7f04f51
--- /dev/null
@@ -0,0 +1,120 @@
+--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
diff --git a/ext/standard/tests/array/array_chunk_variation5.phpt b/ext/standard/tests/array/array_chunk_variation5.phpt
new file mode 100644 (file)
index 0000000..8d36092
--- /dev/null
@@ -0,0 +1,148 @@
+--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
diff --git a/ext/standard/tests/array/array_chunk_variation6.phpt b/ext/standard/tests/array/array_chunk_variation6.phpt
new file mode 100644 (file)
index 0000000..f44eb39
--- /dev/null
@@ -0,0 +1,135 @@
+--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
diff --git a/ext/standard/tests/array/array_chunk_variation7.phpt b/ext/standard/tests/array/array_chunk_variation7.phpt
new file mode 100644 (file)
index 0000000..c8a7196
--- /dev/null
@@ -0,0 +1,89 @@
+--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