From: Raghubansh Kumar Date: Thu, 3 Jan 2008 09:43:45 +0000 (+0000) Subject: new smaller testcases for array_map() function X-Git-Tag: RELEASE_1_3_1~432 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4cadbee71669169826e8dcb8bc54e5b334819462;p=php new smaller testcases for array_map() function --- diff --git a/ext/standard/tests/array/array_map_basic.phpt b/ext/standard/tests/array/array_map_basic.phpt new file mode 100644 index 0000000000..53a7bb4e26 --- /dev/null +++ b/ext/standard/tests/array/array_map_basic.phpt @@ -0,0 +1,70 @@ +--TEST-- +Test array_map() function : basic functionality +--FILE-- + +--EXPECTF-- +*** Testing array_map() : basic functionality *** +-- With two integer array -- +array(3) { + [0]=> + int(4) + [1]=> + int(10) + [2]=> + int(18) +} +-- With single integer array -- +array(3) { + [0]=> + int(1) + [1]=> + int(4) + [2]=> + int(9) +} +-- With string array -- +array(2) { + [0]=> + string(12) "one = single" + [1]=> + string(12) "two = double" +} +Done diff --git a/ext/standard/tests/array/array_map_error.phpt b/ext/standard/tests/array/array_map_error.phpt new file mode 100644 index 0000000000..7c623ec4ea --- /dev/null +++ b/ext/standard/tests/array/array_map_error.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_map() function : error conditions +--FILE-- + +--EXPECTF-- +*** Testing array_map() : error conditions *** + +-- Testing array_map() function with Zero arguments -- + +Warning: array_map() expects at least 2 parameters, 0 given in %s on line %d%d +NULL + +-- Testing array_map() function with one less than expected no. of arguments -- + +Warning: array_map() expects at least 2 parameters, 1 given in %s on line %d%d +NULL + +-- Testing array_map() function with less no. of arrays than callback function arguments -- + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: q in %s on line %d%d + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: q in %s on line %d%d +array(2) { + [0]=> + int(0) + [1]=> + int(0) +} + +-- Testing array_map() function with more no. of arrays than callback function arguments -- +array(2) { + [0]=> + int(3) + [1]=> + int(8) +} +Done diff --git a/ext/standard/tests/array/array_map_object1.phpt b/ext/standard/tests/array/array_map_object1.phpt new file mode 100644 index 0000000000..3b1ffce2e7 --- /dev/null +++ b/ext/standard/tests/array/array_map_object1.phpt @@ -0,0 +1,169 @@ +--TEST-- +Test array_map() function : usage variations - object functionality +--FILE-- + +--EXPECTF-- +*** Testing array_map() : object functionality *** +-- simple class with public variable and method -- + +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL + +-- simple class with private variable and method -- + +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL + +-- simple class with protected variable and method -- + +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL + +-- class without members -- +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL + +-- abstract class -- +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL + +-- class with final method -- +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL + +-- class with static members -- +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} + +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL + +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL +-- class implementing an interface -- +array(2) { + [0]=> + int(1) + [1]=> + int(4) +} +Done diff --git a/ext/standard/tests/array/array_map_object2.phpt b/ext/standard/tests/array/array_map_object2.phpt new file mode 100644 index 0000000000..9670d6ff86 --- /dev/null +++ b/ext/standard/tests/array/array_map_object2.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_map() function : object functionality - with non-existent class and method +--FILE-- + +--EXPECTF-- +*** Testing array_map() : with non-existent class and method *** +-- with non-existent class -- + +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL +-- with existent class and non-existent method -- + +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL +Done diff --git a/ext/standard/tests/array/array_map_object3.phpt b/ext/standard/tests/array/array_map_object3.phpt new file mode 100644 index 0000000000..6c00d56143 --- /dev/null +++ b/ext/standard/tests/array/array_map_object3.phpt @@ -0,0 +1,92 @@ +--TEST-- +Test array_map() function : object functionality - class methods as callback function +--FILE-- +parent_obj = new ParentClass(); + } + public $var2 = 5; + public static function staticChild($n) { + return $n; + } + public function nonstaticChild($n) { + return $n; + } +} + +$childobj = new ChildClass(); +$parentobj = new ParentClass(); + +echo "-- accessing parent method from child class --\n"; +var_dump( array_map(array('ChildClass', 'staticParent1'), $arr1) ); + +echo "-- accessing child method from parent class --\n"; +var_dump( array_map(array('ParentClass', 'staticChild'), $arr1) ); + +echo "-- accessing parent method using child class object --\n"; +var_dump( array_map(array($childobj, 'staticParent1'), $arr1) ); + +echo "-- accessing child method using parent class object --\n"; +var_dump( array_map(array($parentobj, 'staticChild'), $arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : class methods as callback function *** +-- accessing parent method from child class -- +array(3) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(7) +} +-- accessing child method from parent class -- + +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL +-- accessing parent method using child class object -- +array(3) { + [0]=> + int(1) + [1]=> + int(5) + [2]=> + int(7) +} +-- accessing child method using parent class object -- + +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation10.phpt b/ext/standard/tests/array/array_map_variation10.phpt new file mode 100644 index 0000000000..cc75436999 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation10.phpt @@ -0,0 +1,120 @@ +--TEST-- +Test array_map() function : usage variations - anonymous callback function +--FILE-- + +--EXPECTF-- +*** Testing array_map() : anonymous callback function *** +-- anonymous function with all parameters and body -- +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + int(3) + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + int(4) + } + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + int(5) + } +} +-- anonymous function with two parameters and passing one array -- + +Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d + +Notice: Undefined variable: b in %s(20) : runtime-created function on line %d + +Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d + +Notice: Undefined variable: b in %s(20) : runtime-created function on line %d + +Warning: Missing argument 2 for __lambda_func() in %s(20) : runtime-created function on line %d + +Notice: Undefined variable: b in %s(20) : runtime-created function on line %d +array(3) { + [0]=> + array(2) { + [0]=> + int(1) + [1]=> + NULL + } + [1]=> + array(2) { + [0]=> + int(2) + [1]=> + NULL + } + [2]=> + array(2) { + [0]=> + int(3) + [1]=> + NULL + } +} +-- anonymous function with NULL parameter -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- anonymous function with NULL body -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- passing NULL as 'arr1' -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation11.phpt b/ext/standard/tests/array/array_map_variation11.phpt new file mode 100644 index 0000000000..9cad3668d5 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation11.phpt @@ -0,0 +1,52 @@ +--TEST-- +Test array_map() function : usage variations - with recursive callback +--FILE-- + +--EXPECTF-- +*** Testing array_map() : recursive callback function *** +array(3) { + [0]=> + int(1) + [1]=> + array(3) { + [0]=> + int(4) + [1]=> + int(9) + [2]=> + array(1) { + [0]=> + int(25) + } + } + [2]=> + array(1) { + [0]=> + int(16) + } +} +Done diff --git a/ext/standard/tests/array/array_map_variation12.phpt b/ext/standard/tests/array/array_map_variation12.phpt new file mode 100644 index 0000000000..7b8a2e0b09 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation12.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_map() function : usage variations - built-in function as callback +--FILE-- + +--EXPECTF-- +*** Testing array_map() : built-in function *** +-- with built-in function 'pow' and two parameters -- +array(3) { + [0]=> + int(1) + [1]=> + int(16) + [2]=> + int(243) +} +-- with built-in function 'pow' and one parameter -- + +Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d%d + +Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d%d + +Warning: pow() expects exactly 2 parameters, 1 given in %s on line %d%d +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- with language construct -- + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation13.phpt b/ext/standard/tests/array/array_map_variation13.phpt new file mode 100644 index 0000000000..94babdf963 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation13.phpt @@ -0,0 +1,107 @@ +--TEST-- +Test array_map() function : usage variations - callback function with different return types +--FILE-- + +--EXPECTF-- +*** Testing array_map() : callback with diff return value *** +-- with integer return value -- +array(3) { + [0]=> + int(4) + [1]=> + int(6) + [2]=> + int(8) +} +-- with string return value -- +array(3) { + [0]=> + string(2) "13" + [1]=> + string(2) "24" + [2]=> + string(2) "35" +} +-- with bool return value -- +array(3) { + [0]=> + bool(true) + [1]=> + bool(true) + [2]=> + bool(true) +} +-- with null return value -- +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +-- with no return value -- +callback_without_ret called +callback_without_ret called +callback_without_ret called +array(3) { + [0]=> + NULL + [1]=> + NULL + [2]=> + NULL +} +Done diff --git a/ext/standard/tests/array/array_map_variation14.phpt b/ext/standard/tests/array/array_map_variation14.phpt new file mode 100644 index 0000000000..0a0eb15551 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation14.phpt @@ -0,0 +1,125 @@ +--TEST-- +Test array_map() function : usage variations - null value for 'callback' argument +--FILE-- + +--EXPECTF-- +*** Testing array_map() : null value for 'callback' argument *** +-- with null -- +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +-- with unset variable -- +array(2) { + [0]=> + array(3) { + [0]=> + int(1) + [1]=> + string(3) "one" + [2]=> + float(1.1) + } + [1]=> + array(3) { + [0]=> + int(2) + [1]=> + string(3) "two" + [2]=> + float(2.2) + } +} +-- with undefined variable -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- with empty string -- + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL +-- with empty array -- + +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation15.phpt b/ext/standard/tests/array/array_map_variation15.phpt new file mode 100644 index 0000000000..c7be3b7ded --- /dev/null +++ b/ext/standard/tests/array/array_map_variation15.phpt @@ -0,0 +1,30 @@ +--TEST-- +Test array_map() function : usage variations - non existent 'callback' function +--FILE-- + +--EXPECTF-- +*** Testing array_map() : non existent 'callback' function *** + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation16.phpt b/ext/standard/tests/array/array_map_variation16.phpt new file mode 100644 index 0000000000..196bc39d2c --- /dev/null +++ b/ext/standard/tests/array/array_map_variation16.phpt @@ -0,0 +1,73 @@ +--TEST-- +Test array_map() function : usage variations - failing built-in functions & language constructs +--FILE-- + +--EXPECTF-- +*** Testing array_map() : non-permmited built-in functions *** +-- Iteration 1 -- + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL +-- Iteration 2 -- + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL +-- Iteration 3 -- + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL +-- Iteration 4 -- + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL +-- Iteration 5 -- + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL +-- Iteration 6 -- + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL +-- Iteration 7 -- + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL +-- Iteration 8 -- + +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation17.phpt b/ext/standard/tests/array/array_map_variation17.phpt new file mode 100644 index 0000000000..d0427e81cd --- /dev/null +++ b/ext/standard/tests/array/array_map_variation17.phpt @@ -0,0 +1,158 @@ +--TEST-- +Test array_map() function : usage variations - unexpected values for 'callback' argument +--FILE-- + +--EXPECTF-- +*** Testing array_map() : unexpected values for 'callback' argument *** + +-- Iteration 1 -- +Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d%d +NULL + +-- Iteration 2 -- +Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d%d +NULL + +-- Iteration 3 -- +Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d%d +NULL + +-- Iteration 4 -- +Warning: array_map() expects parameter 1 to be valid callback, integer given in %s on line %d%d +NULL + +-- Iteration 5 -- +Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d%d +NULL + +-- Iteration 6 -- +Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d%d +NULL + +-- Iteration 7 -- +Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d%d +NULL + +-- Iteration 8 -- +Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d%d +NULL + +-- Iteration 9 -- +Warning: array_map() expects parameter 1 to be valid callback, double given in %s on line %d%d +NULL + +-- Iteration 10 -- +Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d%d +NULL + +-- Iteration 11 -- +Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d%d +NULL + +-- Iteration 12 -- +Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d%d +NULL + +-- Iteration 13 -- +Warning: array_map() expects parameter 1 to be valid callback, boolean given in %s on line %d%d +NULL + +-- Iteration 14 -- +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL + +-- Iteration 15 -- +Warning: array_map() expects parameter 1 to be valid callback, string given in %s on line %d%d +NULL + +-- Iteration 16 -- +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL + +-- Iteration 17 -- +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL + +-- Iteration 18 -- +Warning: array_map() expects parameter 1 to be valid callback, array given in %s on line %d%d +NULL + +-- Iteration 19 -- +Warning: array_map() expects parameter 1 to be valid callback, object given in %s on line %d%d +NULL + +-- Iteration 20 -- +Warning: array_map() expects parameter 1 to be valid callback, resource given in %s on line %d%d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation18.phpt b/ext/standard/tests/array/array_map_variation18.phpt new file mode 100644 index 0000000000..d0a23d72c6 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation18.phpt @@ -0,0 +1,205 @@ +--TEST-- +Test array_map() function : usage variations - unexpected values for 'arr1' argument +--FILE-- + +--EXPECTF-- +*** Testing array_map() : unexpected values for 'arr1' *** +-- Iteration 1 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 2 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 3 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 4 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 5 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 6 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 7 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 8 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 9 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 10 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 11 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 12 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 13 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 14 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 15 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 16 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 17 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 18 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 19 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 20 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 21 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 22 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 23 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 24 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +-- Iteration 25 -- + +Warning: array_map(): Argument #2 should be an array in %s on line %d%d +NULL +Done diff --git a/ext/standard/tests/array/array_map_variation3.phpt b/ext/standard/tests/array/array_map_variation3.phpt new file mode 100644 index 0000000000..a0715504e9 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation3.phpt @@ -0,0 +1,227 @@ +--TEST-- +Test array_map() function : usage variations - different arrays for 'arr1' argument +--FILE-- + "one", 2 => "two", 3 => "three"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "three" => 3 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 3 => 30), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "three" => "thirty"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*13*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), + array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), + + // array with repetative keys +/*18*/ array("One" => 1, "two" => 2, "One" => 10, "two" => 20, "three" => 3) +); + +// loop through the various elements of $arrays to test array_map() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + var_dump( array_map('callback', $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : different arrays for 'arr1' argument *** +-- Iteration 1 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 2 -- +array(2) { + [0]=> + float(1.1) + [1]=> + float(2.2) +} +-- Iteration 3 -- +array(2) { + [0]=> + array(1) { + [0]=> + int(2) + } + [1]=> + array(1) { + [0]=> + int(1) + } +} +-- Iteration 4 -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 5 -- +array(0) { +} +-- Iteration 6 -- +array(1) { + [0]=> + NULL +} +-- Iteration 7 -- +array(6) { + [0]=> + string(1) "a" + [1]=> + string(4) "aaaa" + [2]=> + string(1) "b" + [3]=> + string(4) "bbbb" + [4]=> + string(1) "c" + [5]=> + string(5) "ccccc" +} +-- Iteration 8 -- +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [3]=> + string(5) "three" +} +-- Iteration 9 -- +array(3) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) +} +-- Iteration 10 -- +array(4) { + [1]=> + int(10) + [2]=> + int(20) + [4]=> + int(40) + [3]=> + int(30) +} +-- Iteration 11 -- +array(3) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" + ["three"]=> + string(6) "thirty" +} +-- Iteration 12 -- +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 13 -- +array(3) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL + ["null"]=> + NULL +} +-- Iteration 14 -- +array(4) { + [1]=> + string(4) "true" + [0]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 15 -- +array(3) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" + ["emptys"]=> + string(0) "" +} +-- Iteration 16 -- +array(6) { + [1]=> + string(0) "" + [2]=> + string(0) "" + [3]=> + NULL + [4]=> + NULL + [5]=> + bool(false) + [6]=> + bool(true) +} +-- Iteration 17 -- +array(3) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) +} +-- Iteration 18 -- +array(3) { + ["One"]=> + int(10) + ["two"]=> + int(20) + ["three"]=> + int(3) +} +Done diff --git a/ext/standard/tests/array/array_map_variation4.phpt b/ext/standard/tests/array/array_map_variation4.phpt new file mode 100644 index 0000000000..bbf975de9b --- /dev/null +++ b/ext/standard/tests/array/array_map_variation4.phpt @@ -0,0 +1,280 @@ +--TEST-- +Test array_map() function : usage variations - associative array with different keys +--FILE-- + "0"), + array(1 => "1"), + array(1 => "1", 2 => "2", 3 => "3", 4 => "4"), + + // arrays with float keys +/*5*/ array(2.3333 => "float"), + array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f3", 33333333.333333 => "f4"), + + // arrays with string keys + array('\tHello' => 111, 're\td' => 'color', '\v\fworld' => 2.2, 'pen\n' => 33), +/*8*/ array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 33), + array("hello", $heredoc => "string"), // heredoc + + // array with object, unset variable and resource variable + array(new classA() => 11, @$unset_var => "hello", $fp => 'resource'), + + // array with mixed values +/*11*/ array('hello' => 1, new classA() => 2, "fruit" => 2.2, + $fp => 'resource', 133 => "int", 444.432 => "float", + @$unset_var => "unset", $heredoc => "heredoc") +); + +// loop through the various elements of $arrays to test array_map() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + var_dump( array_map('callback', $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : associative array with diff. keys for 'arr1' argument *** + +Warning: Illegal offset type in %s on line %d%d + +Warning: Illegal offset type in %s on line %d%d + +Warning: Illegal offset type in %s on line %d%d + +Warning: Illegal offset type in %s on line %d%d +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 3 -- +array(1) { + [1]=> + string(1) "1" +} +-- Iteration 4 -- +array(4) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(1) "3" + [4]=> + string(1) "4" +} +-- Iteration 5 -- +array(1) { + [2]=> + string(5) "float" +} +-- Iteration 6 -- +array(4) { + [1]=> + string(2) "f1" + [3]=> + string(2) "f2" + [4]=> + string(2) "f3" + [33333333]=> + string(2) "f4" +} +-- Iteration 7 -- +array(4) { + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) + ["pen\n"]=> + int(33) +} +-- Iteration 8 -- +array(4) { + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + [" world"]=> + float(2.2) + ["pen +"]=> + int(33) +} +-- Iteration 9 -- +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iteration 10 -- +array(1) { + [""]=> + string(5) "hello" +} +-- Iteration 11 -- +array(6) { + ["hello"]=> + int(1) + ["fruit"]=> + float(2.2) + [133]=> + string(3) "int" + [444]=> + string(5) "float" + [""]=> + string(5) "unset" + ["Hello world"]=> + string(7) "heredoc" +} +Done +--UEXPECTF-- +*** Testing array_map() : associative array with diff. keys for 'arr1' argument *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + unicode(1) "0" +} +-- Iteration 3 -- +array(1) { + [1]=> + unicode(1) "1" +} +-- Iteration 4 -- +array(4) { + [1]=> + unicode(1) "1" + [2]=> + unicode(1) "2" + [3]=> + unicode(1) "3" + [4]=> + unicode(1) "4" +} +-- Iteration 5 -- +array(1) { + [2]=> + unicode(5) "float" +} +-- Iteration 6 -- +array(4) { + [1]=> + unicode(2) "f1" + [3]=> + unicode(2) "f2" + [4]=> + unicode(2) "f3" + [33333333]=> + unicode(2) "f4" +} +-- Iteration 7 -- +array(4) { + [u"\tHello"]=> + int(111) + [u"re\td"]=> + unicode(5) "color" + [u"\v\fworld"]=> + float(2.2) + [u"pen\n"]=> + int(33) +} +-- Iteration 8 -- +array(4) { + [u" Hello"]=> + int(111) + [u"re d"]=> + unicode(5) "color" + [u" world"]=> + float(2.2) + [u"pen +"]=> + int(33) +} +-- Iteration 9 -- +array(2) { + [0]=> + unicode(5) "hello" + [u"Hello world"]=> + unicode(6) "string" +} +-- Iteration 10 -- +array(1) { + [u""]=> + unicode(5) "hello" +} +-- Iteration 11 -- +array(6) { + [u"hello"]=> + int(1) + [u"fruit"]=> + float(2.2) + [133]=> + unicode(3) "int" + [444]=> + unicode(5) "float" + [u""]=> + unicode(5) "unset" + [u"Hello world"]=> + unicode(7) "heredoc" +} +Done diff --git a/ext/standard/tests/array/array_map_variation5.phpt b/ext/standard/tests/array/array_map_variation5.phpt new file mode 100644 index 0000000000..55f1569211 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation5.phpt @@ -0,0 +1,181 @@ +--TEST-- +Test array_map() function : usage variations - associative array with different values +--FILE-- + 0), + array("1" => 1), + array("one" => 1, 'two' => 2, "three" => 3, 4 => 4), + + // arrays with float values +/*5*/ array("float" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 33333333.3333), + + // arrays with string values + array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "pen\n"), +/*8*/ array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => 'pen\n'), + array(1 => "hello", "heredoc" => $heredoc), + + // array with object, unset variable and resource variable + array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp), + + // array with mixed values +/*11*/ array(1 => 'hello', 2 => new classA(), 222 => "fruit", + 'resource' => $fp, "int" => 133, "float" => 444.432, + "unset" => @$unset_var, "heredoc" => $heredoc) +); + +// loop through the various elements of $arrays to test array_map() +$iterator = 1; +foreach($arrays as $arr1) { + echo "-- Iteration $iterator --\n"; + var_dump( array_map('callback', $arr1) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : associative array with diff. values for 'arr1' argument *** +-- Iteration 1 -- +array(0) { +} +-- Iteration 2 -- +array(1) { + [0]=> + int(0) +} +-- Iteration 3 -- +array(1) { + [1]=> + int(1) +} +-- Iteration 4 -- +array(4) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [4]=> + int(4) +} +-- Iteration 5 -- +array(1) { + ["float"]=> + float(2.3333) +} +-- Iteration 6 -- +array(4) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.8999992284) + ["f4"]=> + float(33333333.3333) +} +-- Iteration 7 -- +array(4) { + [111]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) " world" + [3]=> + string(4) "pen +" +} +-- Iteration 8 -- +array(4) { + [111]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" + [3]=> + string(5) "pen\n" +} +-- Iteration 9 -- +array(2) { + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 10 -- +array(3) { + [11]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +-- Iteration 11 -- +array(8) { + [1]=> + string(5) "hello" + [2]=> + object(classA)#%d (0) { + } + [222]=> + string(5) "fruit" + ["resource"]=> + resource(%d) of type (stream) + ["int"]=> + int(133) + ["float"]=> + float(444.432) + ["unset"]=> + NULL + ["heredoc"]=> + string(11) "Hello world" +} +Done diff --git a/ext/standard/tests/array/array_map_variation6.phpt b/ext/standard/tests/array/array_map_variation6.phpt new file mode 100644 index 0000000000..2409a5763c --- /dev/null +++ b/ext/standard/tests/array/array_map_variation6.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test array_map() function : usage variations - array having subarrays +--FILE-- + 'a', 'b' => 2) +); + +var_dump( array_map('callback', $arr1)); +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : array having subarrays *** +array(5) { + [0]=> + array(0) { + } + [1]=> + array(2) { + [0]=> + int(1) + [1]=> + int(2) + } + [2]=> + array(2) { + [0]=> + string(1) "a" + [1]=> + string(1) "b" + } + [3]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + string(1) "a" + [3]=> + string(1) "b" + } + [4]=> + array(2) { + [1]=> + string(1) "a" + ["b"]=> + int(2) + } +} +Done diff --git a/ext/standard/tests/array/array_map_variation7.phpt b/ext/standard/tests/array/array_map_variation7.phpt new file mode 100644 index 0000000000..8f88a0f88c --- /dev/null +++ b/ext/standard/tests/array/array_map_variation7.phpt @@ -0,0 +1,122 @@ +--TEST-- +Test array_map() function : usage variations - arrays of different size +--FILE-- + $b); +} + +// calling array_map with different arrays +var_dump( array_map('callback', array(1, 2, 3), array()) ); +var_dump( array_map('callback', array(), array('a', 'b', 'c')) ); +var_dump( array_map('callback', array(1, 2, 3), array('a', 'b')) ); +var_dump( array_map('callback', array(012, 0x2F, 0X1A), array(2.3, 12.4e2)) ); +var_dump( array_map('callback', array(), array(1, 2, 3), array('a', 'b')) ); // passing more no. of arrays than callback function argument + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : arrays with diff. size *** +array(3) { + [0]=> + array(1) { + [1]=> + NULL + } + [1]=> + array(1) { + [2]=> + NULL + } + [2]=> + array(1) { + [3]=> + NULL + } +} +array(3) { + [0]=> + array(1) { + [""]=> + string(1) "a" + } + [1]=> + array(1) { + [""]=> + string(1) "b" + } + [2]=> + array(1) { + [""]=> + string(1) "c" + } +} +array(3) { + [0]=> + array(1) { + [1]=> + string(1) "a" + } + [1]=> + array(1) { + [2]=> + string(1) "b" + } + [2]=> + array(1) { + [3]=> + NULL + } +} +array(3) { + [0]=> + array(1) { + [10]=> + float(2.3) + } + [1]=> + array(1) { + [47]=> + float(1240) + } + [2]=> + array(1) { + [26]=> + NULL + } +} +array(3) { + [0]=> + array(1) { + [""]=> + int(1) + } + [1]=> + array(1) { + [""]=> + int(2) + } + [2]=> + array(1) { + [""]=> + int(3) + } +} +Done diff --git a/ext/standard/tests/array/array_map_variation8.phpt b/ext/standard/tests/array/array_map_variation8.phpt new file mode 100644 index 0000000000..5672e6cd95 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation8.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test array_map() function : usage variations - array with references +--FILE-- + 0, + 1 => &$value4, + 2 => &$value2, + 3 => "hello", + 4 => &$value3, + $value4 => &$value2 +); +echo "-- with one array --\n"; +var_dump( array_map('callback1', $arr1) ); + +echo "-- with two arrays --\n"; +var_dump( array_map('callback_cat', $arr1, $arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : array with references for 'arr1' argument *** +-- with one array -- +array(6) { + [0]=> + int(0) + [1]=> + string(5) "hello" + [2]=> + string(5) "hello" + [3]=> + string(5) "hello" + [4]=> + int(0) + ["hello"]=> + string(5) "hello" +} +-- with two arrays -- +array(6) { + [0]=> + string(2) "00" + [1]=> + string(10) "hellohello" + [2]=> + string(10) "hellohello" + [3]=> + string(10) "hellohello" + [4]=> + string(2) "00" + [5]=> + string(10) "hellohello" +} +Done diff --git a/ext/standard/tests/array/array_map_variation9.phpt b/ext/standard/tests/array/array_map_variation9.phpt new file mode 100644 index 0000000000..f029beccd6 --- /dev/null +++ b/ext/standard/tests/array/array_map_variation9.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test array_map() function : usage variations - binary safe checking +--FILE-- + $b); +} + +// array with binary data +$arr1 = array(b"hello", b"world", "1", b"22.22"); + +echo "-- checking binary safe array with one parameter callback function --\n"; +var_dump( array_map('callback1', $arr1) ); + +echo "-- checking binary safe array with two parameter callback function --\n"; +var_dump( array_map(b"callback2", $arr1) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_map() : array with binary data for 'arr1' argument *** +-- checking binary safe array with one parameter callback function -- +array(4) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" + [2]=> + string(1) "1" + [3]=> + string(5) "22.22" +} +-- checking binary safe array with two parameter callback function -- + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: b in %s on line %d%d + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: b in %s on line %d%d + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: b in %s on line %d%d + +Warning: Missing argument 2 for callback2() in %s on line %d%d + +Notice: Undefined variable: b in %s on line %d%d +array(4) { + [0]=> + array(1) { + ["hello"]=> + NULL + } + [1]=> + array(1) { + ["world"]=> + NULL + } + [2]=> + array(1) { + [1]=> + NULL + } + [3]=> + array(1) { + ["22.22"]=> + NULL + } +} +Done