diff options
author | Josie Messa <jmessa@php.net> | 2008-02-20 14:19:44 +0000 |
---|---|---|
committer | Josie Messa <jmessa@php.net> | 2008-02-20 14:19:44 +0000 |
commit | 18dc5aaed6e2be39ec001107525a8e3c5a789bf2 (patch) | |
tree | 9750ffc15e56705f508bf0641f4665beda8e5ad7 | |
parent | 39c4c3971d933c4fb7e8b0ab52c6dad4253a1cee (diff) | |
download | php-git-18dc5aaed6e2be39ec001107525a8e3c5a789bf2.tar.gz |
- New tests for current() function
-rw-r--r-- | ext/standard/tests/array/current_basic.phpt | 32 | ||||
-rw-r--r-- | ext/standard/tests/array/current_error.phpt | 40 | ||||
-rw-r--r-- | ext/standard/tests/array/current_variation1.phpt | 217 | ||||
-rw-r--r-- | ext/standard/tests/array/current_variation2.phpt | 155 | ||||
-rw-r--r-- | ext/standard/tests/array/current_variation3.phpt | 42 | ||||
-rw-r--r-- | ext/standard/tests/array/current_variation4.phpt | 71 |
6 files changed, 557 insertions, 0 deletions
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-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + */ + +/* + * Test basic functionality of current() + */ + +echo "*** Testing current() : basic functionality ***\n"; + +$array = array ('zero', 'one', 'two', 'three' => 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-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Pass incorrect number of arguments to current() to test behaviour + */ + +echo "*** Testing current() : error conditions ***\n"; + +// Zero arguments +echo "\n-- Testing current() function with Zero arguments --\n"; +var_dump( current() ); + +//Test current with one more than the expected number of arguments +echo "\n-- Testing current() function with more than expected no. of arguments --\n"; +$array_arg = array(1, 2); +$extra_arg = 10; +var_dump( current($array_arg, $extra_arg) ); +?> +===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-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Pass different data types as $array_arg argument to current() to test behaviour + */ + +echo "*** Testing current() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + var $var1; + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// unexpected values to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 0, + 1, + 12345, + -2345, + + // float data +/*5*/ 10.5, + -10.5, + 12.3456789000e10, + 12.3456789000E-10, + .5, + + // null data +/*10*/ NULL, + null, + + // boolean data +/*12*/ true, + false, + TRUE, + FALSE, + + // empty data +/*16*/ "", + '', + + // string data +/*18*/ "string", + 'string', + $heredoc, + + // object data +/*21*/ new classA(), + + // undefined data +/*22*/ @$undefined_var, + + // unset data +/*23*/ @$unset_var, + + // resource variable +/*24*/ $fp +); + +// loop through each element of $inputs to check the behavior of current() +$iterator = 1; +foreach($inputs as $input) { + echo "\n-- Iteration $iterator --\n"; + var_dump( current($input) ); + $iterator++; +}; + +fclose($fp); +?> +===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-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Pass arrays of different data types as $array_arg to current() to test behaviour + */ + +echo "*** Testing current() : usage variations ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +// get a class +class classA +{ + public function __toString() { + return "Class A object"; + } +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// get a resource variable +$fp = fopen(__FILE__, "r"); + +// arrays of different data types to be passed to $array_arg argument +$inputs = array( + + // int data +/*1*/ 'int' => 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-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Test how the internal pointer is affected when two variables are referenced to each other + */ + +echo "*** Testing current() : usage variations ***\n"; + +$array1 = array ('zero', 'one', 'two'); + +echo "\n-- Initial position of internal pointer --\n"; +var_dump(current($array1)); +next($array1); + +// Test that when two variables are referenced to one another +// the internal pointer is the same for both +$array2 = &$array1; +echo "\n-- Position after calling next() --\n"; +echo "\$array1: "; +var_dump(current($array1)); +echo "\$array2: "; +var_dump(current($array2)); +?> +===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-- +<?php +/* Prototype : mixed current(array $array_arg) + * Description: Return the element currently pointed to by the internal array pointer + * Source code: ext/standard/array.c + * Alias to functions: pos + */ + +/* + * Test how current() behaves with muti-dimensional and recursive arrays + */ + +echo "*** Testing current() : usage variations ***\n"; + +echo "\n-- Two Dimensional Array --\n"; +$multi_array = array ('zero', array (1, 2, 3), 'two'); +echo "Initial Position: "; +var_dump(current($multi_array)); + +echo "Next Position: "; +next($multi_array); +var_dump(current($multi_array)); + +echo "End Position: "; +end($multi_array); +var_dump(current($multi_array)); + +echo "\n-- Access an Array Within an Array --\n"; +//accessing an array within an array +echo "Initial Position: "; +var_dump(current($multi_array[1])); + +echo "\n-- Recursive, Multidimensional Array --\n"; +//create a recursive array +$multi_array[] = &$multi_array; + +//See where internal pointer is after adding more elements +echo "Current Position: "; +var_dump(current($multi_array)); + +//see if internal pointer is in same position as referenced array +var_dump(current($multi_array[3][3][3])); +// see if internal pointer is in the same position from when accessing this inner array +var_dump(current($multi_array[3][3][3][1])); +?> +===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=== |