From b2def646b6d5fa24e4c7a3cc3e1934c80b107e4f Mon Sep 17 00:00:00 2001 From: Raghubansh Kumar Date: Tue, 11 Dec 2007 10:45:25 +0000 Subject: New testcases for array_walk() function --- ext/standard/tests/array/array_walk_basic1.phpt | 80 ++++++ ext/standard/tests/array/array_walk_basic2.phpt | 105 ++++++++ ext/standard/tests/array/array_walk_error1.phpt | 48 ++++ ext/standard/tests/array/array_walk_error2.phpt | 59 +++++ ext/standard/tests/array/array_walk_object1.phpt | Bin 0 -> 1391 bytes ext/standard/tests/array/array_walk_object2.phpt | 104 ++++++++ .../tests/array/array_walk_variation1.phpt | 250 +++++++++++++++++++ .../tests/array/array_walk_variation2.phpt | 268 +++++++++++++++++++++ .../tests/array/array_walk_variation3.phpt | 123 ++++++++++ .../tests/array/array_walk_variation4.phpt | 87 +++++++ .../tests/array/array_walk_variation5.phpt | 64 +++++ .../tests/array/array_walk_variation6.phpt | 143 +++++++++++ .../tests/array/array_walk_variation7.phpt | 93 +++++++ .../tests/array/array_walk_variation8.phpt | 42 ++++ .../tests/array/array_walk_variation9.phpt | 99 ++++++++ 15 files changed, 1565 insertions(+) create mode 100644 ext/standard/tests/array/array_walk_basic1.phpt create mode 100644 ext/standard/tests/array/array_walk_basic2.phpt create mode 100644 ext/standard/tests/array/array_walk_error1.phpt create mode 100644 ext/standard/tests/array/array_walk_error2.phpt create mode 100644 ext/standard/tests/array/array_walk_object1.phpt create mode 100644 ext/standard/tests/array/array_walk_object2.phpt create mode 100644 ext/standard/tests/array/array_walk_variation1.phpt create mode 100644 ext/standard/tests/array/array_walk_variation2.phpt create mode 100644 ext/standard/tests/array/array_walk_variation3.phpt create mode 100644 ext/standard/tests/array/array_walk_variation4.phpt create mode 100644 ext/standard/tests/array/array_walk_variation5.phpt create mode 100644 ext/standard/tests/array/array_walk_variation6.phpt create mode 100644 ext/standard/tests/array/array_walk_variation7.phpt create mode 100644 ext/standard/tests/array/array_walk_variation8.phpt create mode 100644 ext/standard/tests/array/array_walk_variation9.phpt (limited to 'ext/standard') diff --git a/ext/standard/tests/array/array_walk_basic1.phpt b/ext/standard/tests/array/array_walk_basic1.phpt new file mode 100644 index 0000000000..e4bdf1b895 --- /dev/null +++ b/ext/standard/tests/array/array_walk_basic1.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_walk() function : basic functionality - regular array +--FILE-- + +--EXPECT-- +*** Testing array_walk() : basic functionality *** +-- Using array_walk() with default parameters to show array contents -- +string(5) "lemon" +int(0) + +string(6) "orange" +int(1) + +string(6) "banana" +int(2) + +string(5) "apple" +int(3) + +bool(true) +-- Using array_walk() with all parameters -- +string(5) "lemon" +int(0) +string(5) "Added" + +string(6) "orange" +int(1) +string(5) "Added" + +string(6) "banana" +int(2) +string(5) "Added" + +string(5) "apple" +int(3) +string(5) "Added" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_basic2.phpt b/ext/standard/tests/array/array_walk_basic2.phpt new file mode 100644 index 0000000000..e856b580ba --- /dev/null +++ b/ext/standard/tests/array/array_walk_basic2.phpt @@ -0,0 +1,105 @@ +--TEST-- +Test array_walk() function : basic functionality - associative array +--FILE-- + "lemon", "a" => "orange", "b" => "banana", "c" => "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 with default parameters to show array contents --\n"; +var_dump(array_walk($fruits, 'test_print')); + +echo "-- Using array_walk with one optional parameter to modify contents --\n"; +var_dump (array_walk($fruits, 'test_alter', 'fruit')); + +echo "-- Using array_walk with default parameters to show modified array contents --\n"; +var_dump (array_walk($fruits, 'test_print')); + +echo "Done"; +?> +--EXPECT-- +*** Testing array_walk() : basic functionality *** +-- Using array_walk with default parameters to show array contents -- +string(5) "lemon" +string(1) "d" + +string(6) "orange" +string(1) "a" + +string(6) "banana" +string(1) "b" + +string(5) "apple" +string(1) "c" + +bool(true) +-- Using array_walk with one optional parameter to modify contents -- +string(5) "lemon" +string(1) "d" +string(5) "fruit" + +string(6) "orange" +string(1) "a" +string(5) "fruit" + +string(6) "banana" +string(1) "b" +string(5) "fruit" + +string(5) "apple" +string(1) "c" +string(5) "fruit" + +bool(true) +-- Using array_walk with default parameters to show modified array contents -- +string(5) "lemon" +string(1) "d" + +string(6) "orange" +string(1) "a" + +string(6) "banana" +string(1) "b" + +string(5) "apple" +string(1) "c" + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_error1.phpt b/ext/standard/tests/array/array_walk_error1.phpt new file mode 100644 index 0000000000..ac64cbfd1f --- /dev/null +++ b/ext/standard/tests/array/array_walk_error1.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_walk() function : error conditions(Bug#43558) +--FILE-- + +--EXPECTF-- +*** Testing array_walk() : error conditions *** +-- Testing array_walk() function with zero arguments -- + +Warning: array_walk() expects at least 2 parameters, 0 given in %s on line %d +NULL +-- Testing array_walk() function with one argument -- + +Warning: array_walk() expects at least 2 parameters, 1 given in %s on line %d +NULL +-- Testing array_walk() function with non existent callback function -- + +Warning: array_walk() 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_error2.phpt b/ext/standard/tests/array/array_walk_error2.phpt new file mode 100644 index 0000000000..e1bd2a5d46 --- /dev/null +++ b/ext/standard/tests/array/array_walk_error2.phpt @@ -0,0 +1,59 @@ +--TEST-- +Test array_walk() function : error conditions - callback parameters(Bug#43558) +--FILE-- + +--EXPECTF-- +*** Testing array_walk() : 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() function with too many callback parameters -- + +Warning: array_walk() expects at most 3 parameters, 4 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_walk_object1.phpt b/ext/standard/tests/array/array_walk_object1.phpt new file mode 100644 index 0000000000..9a76410c62 Binary files /dev/null and b/ext/standard/tests/array/array_walk_object1.phpt differ diff --git a/ext/standard/tests/array/array_walk_object2.phpt b/ext/standard/tests/array/array_walk_object2.phpt new file mode 100644 index 0000000000..61d0529753 --- /dev/null +++ b/ext/standard/tests/array/array_walk_object2.phpt @@ -0,0 +1,104 @@ +--TEST-- +Test array_walk() function : object functionality - array of objects +--FILE-- +getValue()); + 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 ( + new MyClass(3), + new MyClass(10), + new MyClass(20), + new MyClass(-10) +); + +echo "-- For private member --\n"; +var_dump( array_walk($input, "callback_private", 1)); +echo "-- For public member --\n"; +var_dump( array_walk($input, "callback_public")); +echo "-- For protected member --\n"; +var_dump( array_walk($input, "callback_protected")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : array of objects *** +-- For private member -- +value : int(3) +key : int(0) +value : int(10) +key : int(1) +value : int(20) +key : int(2) +value : int(-10) +key : int(3) +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_variation1.phpt b/ext/standard/tests/array/array_walk_variation1.phpt new file mode 100644 index 0000000000..ca0effd4f2 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation1.phpt @@ -0,0 +1,250 @@ +--TEST-- +Test array_walk() function : usage variations - unexpected values for 'input' argument +--FILE-- + +--EXPECTF-- +*** Testing array_walk() : unexpected values for 'input' argument *** +-- Iteration 1 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) + +Warning: array_walk(): The argument should be an array in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_walk_variation2.phpt b/ext/standard/tests/array/array_walk_variation2.phpt new file mode 100644 index 0000000000..1b76639e28 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation2.phpt @@ -0,0 +1,268 @@ +--TEST-- +Test array_walk() 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($input, $funcname_values[$count]) ); + var_dump( array_walk($input, $funcname_values[$count], $user_data )); +} + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : unexpected values for 'funcname' argument *** +-- Iteration 1 -- + +Warning: array_walk() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_walk() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_walk() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_walk() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, integer given in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_walk() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_walk() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_walk() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_walk() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_walk() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, double given in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_walk() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_walk() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_walk() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_walk() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, array given in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_walk() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_walk() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_walk() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_walk() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_walk() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_walk() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, boolean given in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_walk() expects parameter 2 to be valid callback, string given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, string given in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: array_walk() expects parameter 2 to be valid callback, string given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, string given in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: array_walk() expects parameter 2 to be valid callback, object given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, object given in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_walk() expects parameter 2 to be valid callback, resource given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, resource given in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: array_walk() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) + +Warning: array_walk() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) +-- Iteration 25 -- + +Warning: array_walk() expects parameter 2 to be valid callback, null given in %s on line %d +bool(false) + +Warning: array_walk() 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_variation3.phpt b/ext/standard/tests/array/array_walk_variation3.phpt new file mode 100644 index 0000000000..9ff7d5dfac --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation3.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' array with different values +--FILE-- + +--EXPECTF-- +*** Testing array_walk() : 'input' array with different values*** + +-- Iteration 1 -- +1 : 0 1 +1 : 1 0 +1 : 2 -10 +1 : 3 19 +1 : 4 -33 +1 : 5 90 +1 : 6 31 +1 : 7 -110 +bool(true) + +-- Iteration 2 -- +2 : 0 3.4 +2 : 1 0.8 +2 : 2 -2.9 +2 : 3 625 +2 : 4 0.0082 +bool(true) + +-- Iteration 3 -- +3 : 0 Mango +3 : 1 Apple +3 : 2 Orange +3 : 3 Lemon +bool(true) + +-- Iteration 4 -- +4 : 0 1 +4 : 1 +4 : 2 1 +4 : 3 +bool(true) + +-- Iteration 5 -- +5 : 0 +5 : 1 +bool(true) + +-- Iteration 6 -- +bool(true) + +-- Iteration 7 -- +7 : 0 binary +bool(true) + +-- Iteration 8 -- +8 : 0 16 +8 : 1 8.345 +8 : 2 Fruits +8 : 3 1 +8 : 4 +8 : 5 +8 : 6 -98 +8 : 7 0.005 +8 : 8 banana +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation4.phpt b/ext/standard/tests/array/array_walk_variation4.phpt new file mode 100644 index 0000000000..868732daaf --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation4.phpt @@ -0,0 +1,87 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' array with subarray +--FILE-- + +--EXPECTF-- +*** Testing array_walk() : array with subarray *** +int(0) +array(0) { +} + +int(1) +array(1) { + [0]=> + int(1) +} + +int(2) +array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} + +int(3) +array(2) { + [0]=> + string(5) "Mango" + [1]=> + string(6) "Orange" +} + +int(4) +array(1) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + } +} + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation5.phpt b/ext/standard/tests/array/array_walk_variation5.phpt new file mode 100644 index 0000000000..b5d262a733 --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation5.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' argument containing reference variables +--FILE-- + +--EXPECTF-- +*** Testing array_walk() : array with references *** +int(0) +int(10) + +int(1) +int(-20) + +int(2) +int(-35) + +int(3) +int(10) + +int(4) +int(0) + +int(5) +int(50) + +bool(true) +Done diff --git a/ext/standard/tests/array/array_walk_variation6.phpt b/ext/standard/tests/array/array_walk_variation6.phpt new file mode 100644 index 0000000000..c1f23233ec --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation6.phpt @@ -0,0 +1,143 @@ +--TEST-- +Test array_walk() function : usage variations - 'input' argument as diff. associative arrays +--FILE-- + 25, 5 => 12, 0 => -80, -2 => 100, 5 => 30); +echo "-- Associative array with numeric keys --\n"; +var_dump( array_walk($input, "for_numeric", 10)); + +// String keys +$input = array( "a" => "Apple", 'b' => 'Bananna', "c" => "carrot", 'o' => "Orange"); +echo "-- Associative array with string keys --\n"; +var_dump( array_walk($input, "for_string")); + +// binary keys +$input = array( b"a" => "Apple", b"b" => "Banana"); +echo "-- Associative array with binary keys --\n"; +var_dump( array_walk($input, "for_string")); + +// Mixed keys - numeric/string +$input = array( 0 => 1, 1 => 2, "a" => "Apple", "b" => "Banana", 2 =>3); +echo "-- Associative array with numeric/string keys --\n"; +var_dump( array_walk($input, "for_mixed")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : 'input' as an associative array *** +-- Associative array with numeric keys -- +int(1) +int(25) +int(10) + +int(5) +int(30) +int(10) + +int(0) +int(-80) +int(10) + +int(-2) +int(100) +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_variation7.phpt b/ext/standard/tests/array/array_walk_variation7.phpt new file mode 100644 index 0000000000..da85958b8e --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation7.phpt @@ -0,0 +1,93 @@ +--TEST-- +Test array_walk() function : usage variations - anonymous callback function +--FILE-- + +--EXPECTF-- +*** Testing array_walk() : 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(2) +int(10) + +int(3) +int(0) + +bool(true) +-- Anonymous function with three arguments -- +int(0) +int(2) +int(10) + +int(1) +int(5) +int(10) + +int(2) +int(10) +int(10) + +int(3) +int(0) +int(10) + +bool(true) +-- Anonymous function with one more argument -- + +Warning: array_walk() 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_variation8.phpt b/ext/standard/tests/array/array_walk_variation8.phpt new file mode 100644 index 0000000000..97b1a1c86f --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation8.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_walk() function : usage variations - buit-in function as callback(Bug#43558) +--FILE-- + 1, 65, 98, 100, 6 => -4); + +echo "-- With 'pow' built-in function --\n"; +var_dump( array_walk($input, 'pow')); + +echo "-- With 'min' built-in function --\n"; +var_dump( array_walk($input, "min")); + +echo "-- With 'echo' language construct --\n"; +var_dump( array_walk($input, "echo")); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_walk() : 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() 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_variation9.phpt b/ext/standard/tests/array/array_walk_variation9.phpt new file mode 100644 index 0000000000..37077841af --- /dev/null +++ b/ext/standard/tests/array/array_walk_variation9.phpt @@ -0,0 +1,99 @@ +--TEST-- +Test array_walk() function : usage variations - different callback functions +--FILE-- + +--EXPECTF-- +*** Testing array_walk() : callback function variation *** +-- callback function with both parameters -- +int(0) +string(5) "Apple" + +int(1) +string(6) "Banana" + +int(2) +string(5) "Mango" + +int(3) +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(2) +string(5) "Mango" + +int(3) +string(6) "Orange" + +bool(true) +Done -- cgit v1.2.1