1--TEST--
2Test array_chunk() function : usage variations - different 'size' values
3--FILE--
4<?php
5/*
6 * Testing array_chunk() function with following conditions
7 *   1. -ve size value
8 *   2. size value is more than the no. of elements in the input array
9 *   3. size value is zero
10 *   4. Decimal size value
11*/
12
13echo "*** Testing array_chunk() : usage variations ***\n";
14
15// input array
16$input_array = array(1, 2, 3);
17
18// different magnitude's
19$sizes = array(-1, count($input_array) + 1, 0, 1.5);
20
21// loop through the array for size argument
22foreach ($sizes as $size){
23    echo "\n-- Testing array_chunk() when size = $size --\n";
24    try {
25        var_dump( array_chunk($input_array, $size) );
26    } catch (\ValueError $e) {
27        echo $e->getMessage() . "\n";
28    }
29    try {
30        var_dump( array_chunk($input_array, $size, true) );
31    } catch (\ValueError $e) {
32        echo $e->getMessage() . "\n";
33    }
34    try {
35        var_dump( array_chunk($input_array, $size, false) );
36    } catch (\ValueError $e) {
37        echo $e->getMessage() . "\n";
38    }
39}
40?>
41--EXPECT--
42*** Testing array_chunk() : usage variations ***
43
44-- Testing array_chunk() when size = -1 --
45array_chunk(): Argument #2 ($length) must be greater than 0
46array_chunk(): Argument #2 ($length) must be greater than 0
47array_chunk(): Argument #2 ($length) must be greater than 0
48
49-- Testing array_chunk() when size = 4 --
50array(1) {
51  [0]=>
52  array(3) {
53    [0]=>
54    int(1)
55    [1]=>
56    int(2)
57    [2]=>
58    int(3)
59  }
60}
61array(1) {
62  [0]=>
63  array(3) {
64    [0]=>
65    int(1)
66    [1]=>
67    int(2)
68    [2]=>
69    int(3)
70  }
71}
72array(1) {
73  [0]=>
74  array(3) {
75    [0]=>
76    int(1)
77    [1]=>
78    int(2)
79    [2]=>
80    int(3)
81  }
82}
83
84-- Testing array_chunk() when size = 0 --
85array_chunk(): Argument #2 ($length) must be greater than 0
86array_chunk(): Argument #2 ($length) must be greater than 0
87array_chunk(): Argument #2 ($length) must be greater than 0
88
89-- Testing array_chunk() when size = 1.5 --
90array(3) {
91  [0]=>
92  array(1) {
93    [0]=>
94    int(1)
95  }
96  [1]=>
97  array(1) {
98    [0]=>
99    int(2)
100  }
101  [2]=>
102  array(1) {
103    [0]=>
104    int(3)
105  }
106}
107array(3) {
108  [0]=>
109  array(1) {
110    [0]=>
111    int(1)
112  }
113  [1]=>
114  array(1) {
115    [1]=>
116    int(2)
117  }
118  [2]=>
119  array(1) {
120    [2]=>
121    int(3)
122  }
123}
124array(3) {
125  [0]=>
126  array(1) {
127    [0]=>
128    int(1)
129  }
130  [1]=>
131  array(1) {
132    [0]=>
133    int(2)
134  }
135  [2]=>
136  array(1) {
137    [0]=>
138    int(3)
139  }
140}
141