From b1f1baba4db703b9bc72785fbac972f92cc62f97 Mon Sep 17 00:00:00 2001 From: Raghubansh Kumar Date: Tue, 11 Dec 2007 10:45:50 +0000 Subject: [PATCH] New testcases for array_walk_recursive() function --- .../array/array_walk_recursive_basic1.phpt | 80 ++++++ .../array/array_walk_recursive_basic2.phpt | 105 +++++++ .../array/array_walk_recursive_error1.phpt | 49 ++++ .../array/array_walk_recursive_error2.phpt | 59 ++++ .../array/array_walk_recursive_object1.phpt | Bin 0 -> 1441 bytes .../array/array_walk_recursive_object2.phpt | 106 +++++++ .../array_walk_recursive_variation1.phpt | 250 ++++++++++++++++ .../array_walk_recursive_variation2.phpt | 268 ++++++++++++++++++ .../array_walk_recursive_variation3.phpt | 123 ++++++++ .../array_walk_recursive_variation4.phpt | 76 +++++ .../array_walk_recursive_variation5.phpt | 64 +++++ .../array_walk_recursive_variation6.phpt | 147 ++++++++++ .../array_walk_recursive_variation7.phpt | 93 ++++++ .../array_walk_recursive_variation8.phpt | 42 +++ .../array_walk_recursive_variation9.phpt | 99 +++++++ 15 files changed, 1561 insertions(+) create mode 100644 ext/standard/tests/array/array_walk_recursive_basic1.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_basic2.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_error1.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_error2.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_object1.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_object2.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_variation1.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_variation2.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_variation3.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_variation4.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_variation5.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_variation6.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_variation7.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_variation8.phpt create mode 100644 ext/standard/tests/array/array_walk_recursive_variation9.phpt diff --git a/ext/standard/tests/array/array_walk_recursive_basic1.phpt b/ext/standard/tests/array/array_walk_recursive_basic1.phpt new file mode 100644 index 00000000000..df192b6a796 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_basic1.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_walk_recursive() function : basic functionality - regular array +--FILE-- + +--EXPECT-- +*** Testing array_walk_recursive() : basic functionality *** +-- Using array_walk_recursive() with default parameters to show array contents -- +string(5) "lemon" +int(0) + +string(6) "orange" +int(0) + +string(6) "banana" +int(1) + +string(5) "apple" +int(0) + +bool(true) +-- Using array_walk_recursive() with all parameters -- +string(5) "lemon" +int(0) +string(5) "Added" + +string(6) "orange" +int(0) +string(5) "Added" + +string(6) "banana" +int(1) +string(5) "Added" + +string(5) "apple" +int(0) +string(5) "Added" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_basic2.phpt b/ext/standard/tests/array/array_walk_recursive_basic2.phpt new file mode 100644 index 00000000000..c71d92b4569 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_basic2.phpt @@ -0,0 +1,105 @@ +--TEST-- +Test array_walk_recursive() function : basic functionality - associative array +--FILE-- + "lemon", "b" => array( "c" => "orange", "d" => "banana"), "e" => array("f" => "apple")); + +// User defined callback functions +/* Prototype : test_alter(mixed $item, mixed $key, string $prefix) + * Parameters : item - value in key/value pair + * key - key in key/value pair + * prefix - string to be added + * Description : alters the array values by appending prefix string + */ +function test_alter(&$item, $key, $prefix) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + var_dump($prefix); // additional agument passed to callback function + echo "\n"; // new line to separate the output between each element +} + +/* Prototype : test_print(mixed $item, mixed $key) + * Parameters : item - value in key/value pair + * key - key in key/value pair + * Description : prints the array values with keys + */ +function test_print($item, $key) +{ + // dump the arguments to check that they are passed + // with proper type + var_dump($item); // value + var_dump($key); // key + echo "\n"; // new line to separate the output between each element +} + +echo "-- Using array_walk_recursive with default parameters to show array contents --\n"; +var_dump(array_walk_recursive($fruits, 'test_print')); + +echo "-- Using array_walk_recursive with one optional parameter to modify contents --\n"; +var_dump (array_walk_recursive($fruits, 'test_alter', 'fruit')); + +echo "-- Using array_walk_recursive with default parameters to show modified array contents --\n"; +var_dump (array_walk_recursive($fruits, 'test_print')); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk_recursive() : basic functionality *** +-- Using array_walk_recursive with default parameters to show array contents -- +string(5) "lemon" +string(1) "a" + +string(6) "orange" +string(1) "c" + +string(6) "banana" +string(1) "d" + +string(5) "apple" +string(1) "f" + +bool(true) +-- Using array_walk_recursive with one optional parameter to modify contents -- +string(5) "lemon" +string(1) "a" +string(5) "fruit" + +string(6) "orange" +string(1) "c" +string(5) "fruit" + +string(6) "banana" +string(1) "d" +string(5) "fruit" + +string(5) "apple" +string(1) "f" +string(5) "fruit" + +bool(true) +-- Using array_walk_recursive with default parameters to show modified array contents -- +string(5) "lemon" +string(1) "a" + +string(6) "orange" +string(1) "c" + +string(6) "banana" +string(1) "d" + +string(5) "apple" +string(1) "f" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_error1.phpt b/ext/standard/tests/array/array_walk_recursive_error1.phpt new file mode 100644 index 00000000000..f533da83926 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_error1.phpt @@ -0,0 +1,49 @@ +--TEST-- +Test array_walk_recursive() function : error conditions(Bug#43558) +--FILE-- + +--EXPECTF-- +*** Testing array_walk_recursive() : error conditions *** +-- Testing array_walk_recursive() function with zero arguments -- + +Warning: array_walk_recursive() expects at least 2 parameters, 0 given in %s on line %d +NULL +-- Testing array_walk_recursive() function with one argument -- + +Warning: array_walk_recursive() expects at least 2 parameters, 1 given in %s on line %d +NULL +-- Testing array_walk_recursive() function with non existent callback function -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, string given in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_error2.phpt b/ext/standard/tests/array/array_walk_recursive_error2.phpt new file mode 100644 index 00000000000..a1527c28ed5 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_error2.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_walk_recursive() function : error conditions - callback parameters(Bug#43558) +--FILE-- + +--EXPECTF-- +*** Testing array_walk_recursive() : error conditions - callback parameters *** + +Warning: Missing argument 3 for callback1() in %s on line %d + +callback1() invoked +bool(false) + +Warning: Missing argument 4 for callback2() in %s on line %d + +callback2() invoked +bool(false) + +callback1() invoked +bool(true) + +callback2() invoked +bool(true) +-- Testing array_walk_recursive() function with too many callback parameters -- + +Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_recursive_object1.phpt b/ext/standard/tests/array/array_walk_recursive_object1.phpt new file mode 100644 index 0000000000000000000000000000000000000000..cc1b51ca78bbdda042bbc445eaa0d2be199c116e GIT binary patch literal 1441 zcmbtUZEM>w5bkIFio+Ocn|N9FX-l@2(WWripwKV|+X%9JO}sdgk>#{z^uO;;j@`6N zVX%C#ozuNM_dIt>)5ZK|k)~pSwF7CbY?pVk+$=4s#@59SqZn=*tz2O=Ou=NoP`SY( z%fhuHO|L$Eo>P+d=heCr;{>j)amKY30>xy;l*d#1dJq=6YTO8FXA8Z8kjrVgMfg5~ zZE=q|giVb$mrnkS1tf5ZwX#LUkf!jls>&85u*-l8oB`aSZDEVsj1J5#NZo+|PH|%z zs}PjQaSC|v#_Z>zYyR8!t3erKHF%;i-pyN{Ls^7PaHLj+s2h z6Bix}RBHo4k|e;CbLtmZKTbAK4OyNfO622Ur325gr5Hz(AVz^F>4tDnK9?| z2l^7ItA6_Eyau=SjvY`|S*kT)iJtufmA!t$;10}m9gcuO)02m0$%7S(-vX#@`qyl$ zh>zph6N|6-%=Q@0zMZmOoChIPNs|L#+6#XB?3FEc(jkQOvGnOUs%o;bP-JYf10(GZ z?HP}LWzB)Ta~}FyE|t-=H;r;pSfl$YOWF|NUI0S3F6#7bs0JTk@56N;&-=nJo%aBq zo3ob1&*87K?{Ef9n6-m&QY-;w*E;EP_9H=H%0 Te0xp*_TgetValue()); + echo "key : "; + var_dump($key); +} + +function callback_public($value, $key) +{ + echo "value : "; + var_dump($value->pub_value); +} +function callback_protected($value, $key) +{ + echo "value : "; + var_dump($value->get_pro_value()); +} + +class MyClass +{ + private $pri_value; + public $pub_value; + protected $pro_value; + public function __construct($setVal) + { + $this->pri_value = $setVal; + $this->pub_value = $setVal; + $this->pro_value = $setVal; + } + public function getValue() + { + return $this->pri_value; + } + public function get_pro_value() + { + return $this->pro_value; + } +}; + +// array containing objects of MyClass +$input = array ( + array( + new MyClass(3), + new MyClass(10), + ), + new MyClass(20), + array(new MyClass(-10)) +); + +echo "-- For private member --\n"; +var_dump( array_walk_recursive($input, "callback_private", 1)); +echo "-- For public member --\n"; +var_dump( array_walk_recursive($input, "callback_public")); +echo "-- For protected member --\n"; +var_dump( array_walk_recursive($input, "callback_protected")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : array of objects *** +-- For private member -- +value : int(3) +key : int(0) +value : int(10) +key : int(1) +value : int(20) +key : int(1) +value : int(-10) +key : int(0) +bool(true) +-- For public member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +-- For protected member -- +value : int(3) +value : int(10) +value : int(20) +value : int(-10) +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation1.phpt b/ext/standard/tests/array/array_walk_recursive_variation1.phpt new file mode 100644 index 00000000000..2673df99a4f --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation1.phpt @@ -0,0 +1,250 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - unexpected values for 'input' argument +--FILE-- + +--EXPECTF-- +*** Testing array_walk_recursive() : unexpected values for 'input' argument *** +-- Iteration 1 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk_recursive(): The argument should be an array in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation2.phpt b/ext/standard/tests/array/array_walk_recursive_variation2.phpt new file mode 100644 index 00000000000..a20589d9f0f --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation2.phpt @@ -0,0 +1,268 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - unexpected values in place of 'funcname' argument(Bug#43558) +--FILE-- + 'red', 'item' => 'pen'), + + // null data +/* 14*/ NULL, + null, + + // boolean data +/* 16*/ true, + false, + TRUE, + FALSE, + + // empty data +/* 20*/ "", + '', + + // object data + new MyClass(), + + // resource data +/* 23*/ $fp = fopen(__FILE__, 'r'), + + // undefined data + @$undefined_var, + + // unset data +/* 25*/ @$unset_var, +); + +for($count = 0; $count < count($funcname_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_walk_recursive($input, $funcname_values[$count]) ); + var_dump( array_walk_recursive($input, $funcname_values[$count], $user_data )); +} + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : unexpected values for 'funcname' argument *** +-- Iteration 1 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, string given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, string given in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, string given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, string given in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, object given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, object given in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, resource given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, resource given in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) +-- Iteration 25 -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation3.phpt b/ext/standard/tests/array/array_walk_recursive_variation3.phpt new file mode 100644 index 00000000000..9abdc0b5c23 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation3.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' array with different values +--FILE-- + +--EXPECTF-- +*** Testing array_walk_recursive() : 'input' array with different values*** + +-- Iteration 1 -- +1 : 0 1 +1 : 1 0 +1 : 2 -10 +1 : 0 19 +1 : 1 -33 +1 : 0 90 +1 : 1 31 +1 : 2 -110 +bool(true) + +-- Iteration 2 -- +2 : 0 3.4 +2 : 1 0.8 +2 : 2 -2.9 +2 : 0 625 +2 : 1 0.0082 +bool(true) + +-- Iteration 3 -- +3 : 0 Mango +3 : 0 Apple +3 : 1 Orange +3 : 2 Lemon +bool(true) + +-- Iteration 4 -- +4 : 0 1 +4 : 1 +4 : 0 1 +4 : 1 +bool(true) + +-- Iteration 5 -- +5 : 0 +5 : 0 +bool(true) + +-- Iteration 6 -- +bool(true) + +-- Iteration 7 -- +7 : 0 binary +bool(true) + +-- Iteration 8 -- +8 : 0 16 +8 : 1 8.345 +8 : 0 Fruits +8 : 0 1 +8 : 1 +8 : 0 +8 : 0 -98 +8 : 1 0.005 +8 : 2 banana +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation4.phpt b/ext/standard/tests/array/array_walk_recursive_variation4.phpt new file mode 100644 index 00000000000..4db34979a4e --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation4.phpt @@ -0,0 +1,76 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' array with subarray +--FILE-- + +--EXPECTF-- +*** Testing array_walk_recursive() : array with subarray *** +int(0) +int(1) + +int(0) +int(1) + +int(1) +int(2) + +int(2) +int(3) + +int(0) +string(5) "Mango" + +int(1) +string(6) "Orange" + +int(0) +int(1) + +int(1) +int(2) + +int(2) +int(3) + +int(0) +int(1) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation5.phpt b/ext/standard/tests/array/array_walk_recursive_variation5.phpt new file mode 100644 index 00000000000..688da57f017 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation5.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' argument containing reference variables +--FILE-- + +--EXPECTF-- +*** Testing array_walk_recursive() : array with references *** +int(0) +int(10) + +int(0) +int(-20) + +int(1) +int(-35) + +int(0) +int(10) + +int(1) +int(0) + +int(0) +int(50) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation6.phpt b/ext/standard/tests/array/array_walk_recursive_variation6.phpt new file mode 100644 index 00000000000..747eb7403c4 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation6.phpt @@ -0,0 +1,147 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - 'input' argument as diff. associative arrays +--FILE-- + array(1 => 25, 5 => 12, 0 => -80), 1 => array(-2 => 100, 5 => 30)); +echo "-- Associative array with numeric keys --\n"; +var_dump( array_walk_recursive($input, "for_numeric", 10)); + +// String keys +$input = array( "a" => "Apple", 'z' => array('b' => 'Bananna', "c" => "carrot"), 'x' => array('o' => "Orange")); +echo "-- Associative array with string keys --\n"; +var_dump( array_walk_recursive($input, "for_string")); + +// binary key +$input = array( b"a" => "Apple", b"b" => "Banana"); +echo "-- Associative array with binary keys --\n"; +var_dump( array_walk_recursive($input, "for_string")); + +// Mixed keys - numeric/string +$input = array( 0 => array(0 => 1, 1 => 2), "x" => array("a" => "Apple", "b" => "Banana"), 2 =>3); +echo "-- Associative array with numeric/string keys --\n"; +var_dump( array_walk_recursive($input, "for_mixed")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : 'input' as an associative array *** +-- Associative array with numeric keys -- +int(1) +int(25) +int(10) + +int(5) +int(12) +int(10) + +int(0) +int(-80) +int(10) + +int(-2) +int(100) +int(10) + +int(5) +int(30) +int(10) + +bool(true) +-- Associative array with string keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(7) "Bananna" + +string(1) "c" +string(6) "carrot" + +string(1) "o" +string(6) "Orange" + +bool(true) +-- Associative array with binary keys -- +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +bool(true) +-- Associative array with numeric/string keys -- +int(0) +int(1) + +int(1) +int(2) + +string(1) "a" +string(5) "Apple" + +string(1) "b" +string(6) "Banana" + +int(2) +int(3) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation7.phpt b/ext/standard/tests/array/array_walk_recursive_variation7.phpt new file mode 100644 index 00000000000..0cdd6d248d5 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation7.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - anonymous callback function +--FILE-- + +--EXPECTF-- +*** Testing array_walk_recursive() : anonymous function as callback *** +-- Anonymous function with one argument -- +int(2) + +int(5) + +int(10) + +int(0) + +bool(true) +-- Anonymous function with two arguments -- +int(0) +int(2) + +int(1) +int(5) + +int(0) +int(10) + +int(1) +int(0) + +bool(true) +-- Anonymous function with three arguments -- +int(0) +int(2) +int(10) + +int(1) +int(5) +int(10) + +int(0) +int(10) +int(10) + +int(1) +int(0) +int(10) + +bool(true) +-- Anonymous function with one more argument -- + +Warning: array_walk_recursive() expects at most 3 parameters, 4 given in %s on line %d +NULL +-- Anonymous function with null argument -- +1 +1 +1 +1 +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation8.phpt b/ext/standard/tests/array/array_walk_recursive_variation8.phpt new file mode 100644 index 00000000000..df1440eefd3 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation8.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - buit-in function as callback(Bug#43558) +--FILE-- + 1, 65), array(98, 100), array(6 => -4)); + +echo "-- With 'pow' built-in function --\n"; +var_dump( array_walk_recursive($input, 'pow')); + +echo "-- With 'min' built-in function --\n"; +var_dump( array_walk_recursive($input, "min")); + +echo "-- With 'echo' language construct --\n"; +var_dump( array_walk_recursive($input, "echo")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk_recursive() : built-in function as callback *** +-- With 'pow' built-in function -- +bool(true) +-- With 'min' built-in function -- +bool(true) +-- With 'echo' language construct -- + +Warning: array_walk_recursive() expects parameter 2 to be valid callback, string given in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_walk_recursive_variation9.phpt b/ext/standard/tests/array/array_walk_recursive_variation9.phpt new file mode 100644 index 00000000000..f18fe248c11 --- /dev/null +++ b/ext/standard/tests/array/array_walk_recursive_variation9.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_walk_recursive() function : usage variations - different callback functions +--FILE-- + +--EXPECTF-- +*** Testing array_walk_recursive() : callback function variation *** +-- callback function with both parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(1) +string(5) "Mango" + +int(0) +string(6) "Orange" + +bool(true) +-- callback function with only one parameter -- +string(5) "Apple" + +string(6) "Banana" + +string(5) "Mango" + +string(6) "Orange" + +bool(true) +-- callback function without parameters -- +callback3() called +callback3() called +callback3() called +callback3() called +bool(true) +-- passing one more parameter to function with two parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(1) +string(5) "Mango" + +int(0) +string(6) "Orange" + +bool(true) +Done