From: Josie Messa Date: Wed, 20 Feb 2008 14:19:44 +0000 (+0000) Subject: - New tests for current() function X-Git-Tag: php-5.2.6RC1~38 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=18dc5aaed6e2be39ec001107525a8e3c5a789bf2;p=php - New tests for current() function --- diff --git a/ext/standard/tests/array/current_basic.phpt b/ext/standard/tests/array/current_basic.phpt new file mode 100644 index 0000000000..cec6959778 --- /dev/null +++ b/ext/standard/tests/array/current_basic.phpt @@ -0,0 +1,32 @@ +--TEST-- +Test current() function : basic functionality +--FILE-- + 3); +var_dump(current($array)); +next($array); +var_dump(current($array)); +end($array); +var_dump(current($array)); +next($array); +var_dump(current($array)); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : basic functionality *** +string(4) "zero" +string(3) "one" +int(3) +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/current_error.phpt b/ext/standard/tests/array/current_error.phpt new file mode 100644 index 0000000000..40362e779e --- /dev/null +++ b/ext/standard/tests/array/current_error.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test current() function : error conditions - Pass incorrect number of args +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing current() : error conditions *** + +-- Testing current() function with Zero arguments -- + +Warning: Wrong parameter count for current() in %s on line %d +NULL + +-- Testing current() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for current() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/current_variation1.phpt b/ext/standard/tests/array/current_variation1.phpt new file mode 100644 index 0000000000..cb21df27a2 --- /dev/null +++ b/ext/standard/tests/array/current_variation1.phpt @@ -0,0 +1,217 @@ +--TEST-- +Test current() function : usage variations - Pass different data types as $array_arg arg +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Iteration 1 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 2 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 3 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 4 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 5 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 6 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 7 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 8 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 9 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 10 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 11 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 12 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 13 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 14 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 15 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 16 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 17 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 18 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 19 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 20 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 21 -- +NULL + +-- Iteration 22 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 23 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) + +-- Iteration 24 -- + +Warning: current(): Passed variable is not an array or object in %s on line %d +bool(false) +===DONE=== diff --git a/ext/standard/tests/array/current_variation2.phpt b/ext/standard/tests/array/current_variation2.phpt new file mode 100644 index 0000000000..49769cea3f --- /dev/null +++ b/ext/standard/tests/array/current_variation2.phpt @@ -0,0 +1,155 @@ +--TEST-- +Test current() function : usage variations - arrays containing different data types +--FILE-- + array( + 0, + 1, + 12345, + -2345, + ), + + // float data +/*2*/ 'float' => array( + 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + ), + + // null data +/*3*/ 'null' => array( + NULL, + null, + ), + + // boolean data +/*4*/ 'bool' => array( + true, + false, + TRUE, + FALSE, + ), + + // empty data +/*5*/ 'empty string' => array( + "", + '', + ), + +/*6*/ 'empty array' => array( + ), + + // string data +/*7*/ 'string' => array( + "string", + 'string', + $heredoc, + ), + + // object data +/*8*/ 'object' => array( + new classA(), + ), + + // undefined data +/*9*/ 'undefined' => array( + @$undefined_var, + ), + + // unset data +/*10*/ 'unset' => array( + @$unset_var, + ), + + // resource variable +/*11*/ 'resource' => array( + $fp + ), +); + +// loop through each element of $inputs to check the behavior of current() +$iterator = 1; +foreach($inputs as $key => $input) { + echo "\n-- Iteration $iterator : $key data --\n"; + var_dump( current($input) ); + $iterator++; +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Iteration 1 : int data -- +int(0) + +-- Iteration 2 : float data -- +float(10.5) + +-- Iteration 3 : null data -- +NULL + +-- Iteration 4 : bool data -- +bool(true) + +-- Iteration 5 : empty string data -- +string(0) "" + +-- Iteration 6 : empty array data -- +bool(false) + +-- Iteration 7 : string data -- +string(6) "string" + +-- Iteration 8 : object data -- +object(classA)#%d (0) { +} + +-- Iteration 9 : undefined data -- +NULL + +-- Iteration 10 : unset data -- +NULL + +-- Iteration 11 : resource data -- +resource(%d) of type (stream) +===DONE=== diff --git a/ext/standard/tests/array/current_variation3.phpt b/ext/standard/tests/array/current_variation3.phpt new file mode 100644 index 0000000000..bab5e6e0c5 --- /dev/null +++ b/ext/standard/tests/array/current_variation3.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test current() function : usage variations - referenced variables +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Initial position of internal pointer -- +string(4) "zero" + +-- Position after calling next() -- +$array1: string(3) "one" +$array2: string(3) "one" +===DONE=== diff --git a/ext/standard/tests/array/current_variation4.phpt b/ext/standard/tests/array/current_variation4.phpt new file mode 100644 index 0000000000..741fced2e7 --- /dev/null +++ b/ext/standard/tests/array/current_variation4.phpt @@ -0,0 +1,71 @@ +--TEST-- +Test current() function : usage variations - multi-dimensional arrays +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing current() : usage variations *** + +-- Two Dimensional Array -- +Initial Position: string(4) "zero" +Next Position: array(3) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) +} +End Position: string(3) "two" + +-- Access an Array Within an Array -- +Initial Position: int(1) + +-- Recursive, Multidimensional Array -- +Current Position: string(3) "two" +string(3) "two" +int(1) +===DONE===