diff --git a/ext/standard/tests/array/array_filter_basic.phpt b/ext/standard/tests/array/array_filter_basic.phpt new file mode 100644 index 00000000000..daec07bacdf --- /dev/null +++ b/ext/standard/tests/array/array_filter_basic.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_filter() function : basic functionality +--FILE-- + +--EXPECTF-- +*** Testing array_filter() : basic functionality *** +array(2) { + [1]=> + int(2) + [3]=> + int(0) +} +array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [4]=> + int(-1) +} +Done diff --git a/ext/standard/tests/array/array_filter_error.phpt b/ext/standard/tests/array/array_filter_error.phpt new file mode 100644 index 00000000000..03165b6f438 --- /dev/null +++ b/ext/standard/tests/array/array_filter_error.phpt @@ -0,0 +1,50 @@ +--TEST-- +Test array_filter() function : error conditions +--FILE-- + +--EXPECTF-- +*** Testing array_filter() : error conditions *** +-- Testing array_filter() function with Zero arguments -- +Warning: Wrong parameter count for array_filter() in %s on line %d +NULL +-- Testing array_filter() function with more than expected no. of arguments -- +Warning: Wrong parameter count for array_filter() in %s on line %d +NULL +-- Testing array_filter() function with incorrect callback -- +Warning: array_filter(): The second argument, 'even', should be a valid callback in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_filter_variation1.phpt b/ext/standard/tests/array/array_filter_variation1.phpt new file mode 100644 index 00000000000..f8a3ca2731f --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation1.phpt @@ -0,0 +1,195 @@ +--TEST-- +Test array_filter() function : usage variations - Unexpected values for 'input' argument +--FILE-- + +--EXPECTF-- +*** Testing array_filter() : usage variations - unexpected values for 'input'*** +-- Iteration 1 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_filter(): The first argument should be an array in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_filter_variation2.phpt b/ext/standard/tests/array/array_filter_variation2.phpt new file mode 100644 index 00000000000..323cc93648a --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation2.phpt @@ -0,0 +1,184 @@ +--TEST-- +Test array_filter() function : usage variations - Unexpected values for 'callback' function argument +--FILE-- + 'red', 'item' => 'pen'), + + // null data +/*15*/ NULL, + null, + + // boolean data +/*17*/ true, + false, + TRUE, + FALSE, + + // empty data +/*21*/ "", + '', + + // string data +/*23*/ "string", + 'string', + + // object data +/*25*/ new MyClass(), + + // resource data + $fp, + + // undefined data + @$undefined_var, + + // unset data +/*28*/ @$unset_var, +); + +// loop through each element of the 'values' for callback +for($count = 0; $count < count($values); $count++) { + echo "-- Iteration ".($count + 1)." --"; + var_dump( array_filter($input, $values[$count]) ); +}; + +// closing resource +fclose($fp); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - unexpected values for 'callback' function*** +-- Iteration 1 -- +Warning: array_filter(): The second argument, '0', should be a valid callback in %s on line %d +NULL +-- Iteration 2 -- +Warning: array_filter(): The second argument, '1', should be a valid callback in %s on line %d +NULL +-- Iteration 3 -- +Warning: array_filter(): The second argument, '12345', should be a valid callback in %s on line %d +NULL +-- Iteration 4 -- +Warning: array_filter(): The second argument, '-2345', should be a valid callback in %s on line %d +NULL +-- Iteration 5 -- +Warning: array_filter(): The second argument, '10.5', should be a valid callback in %s on line %d +NULL +-- Iteration 6 -- +Warning: array_filter(): The second argument, '-10.5', should be a valid callback in %s on line %d +NULL +-- Iteration 7 -- +Warning: array_filter(): The second argument, '123456789000', should be a valid callback in %s on line %d +NULL +-- Iteration 8 -- +Warning: array_filter(): The second argument, '1.23456789E-9', should be a valid callback in %s on line %d +NULL +-- Iteration 9 -- +Warning: array_filter(): The second argument, '0.5', should be a valid callback in %s on line %d +NULL +-- Iteration 10 -- +Warning: array_filter(): The second argument, 'Array', should be a valid callback in %s on line %d +NULL +-- Iteration 11 -- +Warning: array_filter(): The second argument, 'Array', should be a valid callback in %s on line %d +NULL +-- Iteration 12 -- +Warning: array_filter(): The second argument, 'Array', should be a valid callback in %s on line %d +NULL +-- Iteration 13 -- +Warning: array_filter(): The second argument, 'Array', should be a valid callback in %s on line %d +NULL +-- Iteration 14 -- +Warning: array_filter(): The second argument, 'Array', should be a valid callback in %s on line %d +NULL +-- Iteration 15 -- +Warning: array_filter(): The second argument, '', should be a valid callback in %s on line %d +NULL +-- Iteration 16 -- +Warning: array_filter(): The second argument, '', should be a valid callback in %s on line %d +NULL +-- Iteration 17 -- +Warning: array_filter(): The second argument, '1', should be a valid callback in %s on line %d +NULL +-- Iteration 18 -- +Warning: array_filter(): The second argument, '', should be a valid callback in %s on line %d +NULL +-- Iteration 19 -- +Warning: array_filter(): The second argument, '1', should be a valid callback in %s on line %d +NULL +-- Iteration 20 -- +Warning: array_filter(): The second argument, '', should be a valid callback in %s on line %d +NULL +-- Iteration 21 -- +Warning: array_filter(): The second argument, '', should be a valid callback in %s on line %d +NULL +-- Iteration 22 -- +Warning: array_filter(): The second argument, '', should be a valid callback in %s on line %d +NULL +-- Iteration 23 -- +Warning: array_filter(): The second argument, 'string', should be a valid callback in %s on line %d +NULL +-- Iteration 24 -- +Warning: array_filter(): The second argument, 'string', should be a valid callback in %s on line %d +NULL +-- Iteration 25 -- +Warning: array_filter(): The second argument, 'object', should be a valid callback in %s on line %d +NULL +-- Iteration 26 -- +Warning: array_filter(): The second argument, %s, should be a valid callback in %s on line %d +NULL +-- Iteration 27 -- +Warning: array_filter(): The second argument, '', should be a valid callback in %s on line %d +NULL +-- Iteration 28 -- +Warning: array_filter(): The second argument, '', should be a valid callback in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_filter_variation3.phpt b/ext/standard/tests/array/array_filter_variation3.phpt new file mode 100644 index 00000000000..e22697a978a --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation3.phpt @@ -0,0 +1,216 @@ +--TEST-- +Test array_filter() function : usage variations - Different types of array for 'input' argument +--FILE-- + 'one', 'zero' => 0, -2 => "value"), //associative array + array("one" => 1, null => 'null', 5.2 => "float", true => 1, "" => 'empty'), // associative array with different keys + array(1 => 'one', 2, "key" => 'value') // combinition of associative and non-associative array + +); + +// loop through each element of 'input' with default callback +for($count = 0; $count < count($input_values); $count++) +{ + echo "-- Iteration ".($count + 1). " --\n"; + var_dump( array_filter($input_values[$count]) ); + var_dump( array_filter($input_values[$count], 'always_true') ); + var_dump( array_filter($input_values[$count], 'always_false') ); +} + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - different types of array for 'input' argument*** +-- Iteration 1 -- +array(5) { + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(-1) + [4]=> + int(28) + [5]=> + int(74) +} +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(2) + [3]=> + int(-1) + [4]=> + int(28) + [5]=> + int(74) +} +array(0) { +} +-- Iteration 2 -- +array(3) { + [1]=> + float(1.2) + [2]=> + float(1200) + [3]=> + float(0.0012) +} +array(4) { + [0]=> + float(0) + [1]=> + float(1.2) + [2]=> + float(1200) + [3]=> + float(0.0012) +} +array(0) { +} +-- Iteration 3 -- +array(3) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + [3]=> + string(1) " " +} +array(5) { + [0]=> + string(6) "value1" + [1]=> + string(6) "value2" + [2]=> + string(0) "" + [3]=> + string(1) " " + [4]=> + string(0) "" +} +array(0) { +} +-- Iteration 4 -- +array(2) { + [0]=> + bool(true) + [2]=> + bool(true) +} +array(4) { + [0]=> + bool(true) + [1]=> + bool(false) + [2]=> + bool(true) + [3]=> + bool(false) +} +array(0) { +} +-- Iteration 5 -- +array(0) { +} +array(2) { + [0]=> + NULL + [1]=> + NULL +} +array(0) { +} +-- Iteration 6 -- +array(2) { + [1]=> + string(3) "one" + [-2]=> + string(5) "value" +} +array(3) { + [1]=> + string(3) "one" + ["zero"]=> + int(0) + [-2]=> + string(5) "value" +} +array(0) { +} +-- Iteration 7 -- +array(4) { + ["one"]=> + int(1) + [""]=> + string(5) "empty" + [5]=> + string(5) "float" + [1]=> + int(1) +} +array(4) { + ["one"]=> + int(1) + [""]=> + string(5) "empty" + [5]=> + string(5) "float" + [1]=> + int(1) +} +array(0) { +} +-- Iteration 8 -- +array(3) { + [1]=> + string(3) "one" + [2]=> + int(2) + ["key"]=> + string(5) "value" +} +array(3) { + [1]=> + string(3) "one" + [2]=> + int(2) + ["key"]=> + string(5) "value" +} +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_filter_variation4.phpt b/ext/standard/tests/array/array_filter_variation4.phpt new file mode 100644 index 00000000000..61f40b6e853 --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation4.phpt @@ -0,0 +1,97 @@ +--TEST-- +Test array_filter() function : usage variations - Different types of 'callback' function +--FILE-- + 4, 'null' => NULL); + +// callback function without parameters and with return value +function callback1() +{ + return 1; +} +echo "-- Callback function without parameter and with return --\n"; +var_dump( array_filter($input, "callback1") ); + +// callback function with parameter and without return value +function callback2($input) +{ +} +echo "-- Callback funciton with parameter and without return --\n"; +var_dump( array_filter($input, "callback2") ); + + +// callback function without parameter and without return value +function callback3() +{ +} +echo "-- Callback function without parameter and return --\n"; +var_dump( array_filter($input, "callback3") ); + +// callback function with parameter and with return value +function callback4($input) +{ + if($input > 0 ) { + return true; + } + else { + return false; + } +} +echo "-- Callback function with parameter and return --\n"; +var_dump( array_filter($input, "callback4") ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variation - different 'callback' functions*** +-- Callback function without parameter and with return -- +array(8) { + [0]=> + int(0) + [1]=> + int(-1) + [2]=> + int(2) + [3]=> + float(0.0034) + [4]=> + string(5) "hello" + [5]=> + string(5) "value" + ["key"]=> + int(4) + ["null"]=> + NULL +} +-- Callback funciton with parameter and without return -- +array(0) { +} +-- Callback function without parameter and return -- +array(0) { +} +-- Callback function with parameter and return -- +array(3) { + [2]=> + int(2) + [3]=> + float(0.0034) + ["key"]=> + int(4) +} +Done diff --git a/ext/standard/tests/array/array_filter_variation5.phpt b/ext/standard/tests/array/array_filter_variation5.phpt new file mode 100644 index 00000000000..66b140a2240 --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation5.phpt @@ -0,0 +1,109 @@ +--TEST-- +Test array_filter() function : usage variations - 'input' argument with different false entries +--FILE-- + +--EXPECTF-- +*** Testing array_filter() : usage variations - different false elements in 'input' *** +array(0) { +} +array(16) { + [0]=> + bool(false) + [1]=> + bool(false) + [2]=> + string(0) "" + [3]=> + string(0) "" + [4]=> + int(0) + [5]=> + float(0) + [6]=> + NULL + [7]=> + NULL + [8]=> + string(1) "0" + [9]=> + string(1) "0" + [10]=> + array(0) { + } + [11]=> + bool(false) + [12]=> + bool(false) + [13]=> + string(0) "" + [14]=> + NULL + [15]=> + NULL +} +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_filter_variation6.phpt b/ext/standard/tests/array/array_filter_variation6.phpt new file mode 100644 index 00000000000..1020c28aad4 --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation6.phpt @@ -0,0 +1,94 @@ +--TEST-- +Test array_filter() function : usage variations - 'input' array containing references +--FILE-- + 5 then + * returns true else returns false + */ +function callback($input) +{ + if($input > 5) { + return true; + } + else { + return false; + } +} + +// initializing variables +$value1 = array(1, 2, 8); +$value2 = array(5, 6, 4); +$input = array(&$value1, 10, &$value2, 'value'); + +// with 'callback' argument +var_dump( array_filter($input, 'callback') ); + +// with default 'callback' argument +var_dump( array_filter($input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - 'input' containing references *** +array(3) { + [0]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(8) + } + [1]=> + int(10) + [2]=> + &array(3) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(4) + } +} +array(4) { + [0]=> + &array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(8) + } + [1]=> + int(10) + [2]=> + &array(3) { + [0]=> + int(5) + [1]=> + int(6) + [2]=> + int(4) + } + [3]=> + string(5) "value" +} +Done diff --git a/ext/standard/tests/array/array_filter_variation7.phpt b/ext/standard/tests/array/array_filter_variation7.phpt new file mode 100644 index 00000000000..e34d9133e31 --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation7.phpt @@ -0,0 +1,80 @@ +--TEST-- +Test array_filter() function : usage variations - anonymous callback functions +--FILE-- + 1);') ) ); + +// anonymous callback function with reference +echo "Anonymous callback function with reference parameter\n"; +var_dump( array_filter($input, create_function('&$input', 'return ($input < 1);') ) ); + +// anonymous callback function with null argument +echo "Anonymous callback funciton with null argument\n"; +var_dump( array_filter($input, create_function(null, 'return true;') ) ); + +// anonymous callback function with argument and null statement +echo "Anonymous callback function with regular argument and null statement\n"; +var_dump( array_filter($input, create_function('$input', null) ) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_filter() : usage variations - Anonymous callback functions *** +Anonymous callback function with regular parameter and statement +array(3) { + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) +} +Anonymous callback function with reference parameter +array(4) { + [0]=> + int(0) + [2]=> + int(-1) + [6]=> + string(5) "Hello" + [7]=> + NULL +} +Anonymous callback funciton with null argument +array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL +} +Anonymous callback function with regular argument and null statement +array(0) { +} +Done diff --git a/ext/standard/tests/array/array_filter_variation8.phpt b/ext/standard/tests/array/array_filter_variation8.phpt new file mode 100644 index 00000000000..4440b3324ec --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation8.phpt @@ -0,0 +1,151 @@ +--TEST-- +Test array_filter() function : usage variations - Callback function with different return values +--FILE-- + +--EXPECTF-- +*** Testing array_filter() : usage variations - callback function with different return values*** +callback function with int return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +callback function with float return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +callback function with string return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +callback function with null return value +array(0) { +} +callback function with array as return value +array(9) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL + [8]=> + bool(true) +} +Done diff --git a/ext/standard/tests/array/array_filter_variation9.phpt b/ext/standard/tests/array/array_filter_variation9.phpt new file mode 100644 index 00000000000..c6db57c36dd --- /dev/null +++ b/ext/standard/tests/array/array_filter_variation9.phpt @@ -0,0 +1,72 @@ +--TEST-- +Test array_filter() function : usage variations - built-in functions as 'callback' argument +--FILE-- + +--EXPECTF-- +*** Testing array_filter() : usage variations - built-in functions as 'callback' argument *** +array(6) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) +} +array(8) { + [0]=> + int(0) + [1]=> + int(1) + [2]=> + int(-1) + [3]=> + int(10) + [4]=> + int(100) + [5]=> + int(1000) + [6]=> + string(5) "Hello" + [7]=> + NULL +} + +Warning: array_filter(): The second argument, 'echo', should be a valid callback in %s on line %d +NULL + +Warning: array_filter(): The second argument, 'exit', should be a valid callback in %s on line %d +NULL +Done