diff options
author | Sanjay Mantoor <smantoor@php.net> | 2008-09-11 10:48:12 +0000 |
---|---|---|
committer | Sanjay Mantoor <smantoor@php.net> | 2008-09-11 10:48:12 +0000 |
commit | 313728200de7ef6176cd1946074f9687236a05e3 (patch) | |
tree | 7ba23aba2c53ec10a157c6dc921e252a21e5f319 | |
parent | d19e466d969375bb6f9cb1c2df5db95ad15147a2 (diff) | |
download | php-git-313728200de7ef6176cd1946074f9687236a05e3.tar.gz |
New testcases for array_intersect_key() function
9 files changed, 1165 insertions, 0 deletions
diff --git a/ext/standard/tests/array/array_intersect_key_error.phpt b/ext/standard/tests/array/array_intersect_key_error.phpt new file mode 100644 index 0000000000..78f074fe4e --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_error.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_intersect_key() function : error conditions +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : error conditions ***\n"; + +//Initialise function arguments +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); + +// Testing array_intersect_key with one less than the expected number of arguments +echo "\n-- Testing array_intersect_key() function with less than expected no. of arguments --\n"; +var_dump( array_intersect_key($array1) ); + +// Testing array_intersect_key with one less than the expected number of arguments +echo "\n-- Testing array_intersect_key() function with no arguments --\n"; +var_dump( array_intersect_key() ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : error conditions *** + +-- Testing array_intersect_key() function with less than expected no. of arguments -- + +Warning: Wrong parameter count for array_intersect_key() in %s on line %d +NULL + +-- Testing array_intersect_key() function with no arguments -- + +Warning: Wrong parameter count for array_intersect_key() in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation1.phpt b/ext/standard/tests/array/array_intersect_key_variation1.phpt new file mode 100644 index 0000000000..c28394ba81 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation1.phpt @@ -0,0 +1,315 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing unexpected values to first argument +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array2 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array3 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource var' => $fp, +); + +// loop through each element of the array for arr1 + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($value, $array2) ); + var_dump( array_intersect_key($value, $array2, $array3) ); +} + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +--int 0-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +--resource var-- + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #1 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation2.phpt b/ext/standard/tests/array/array_intersect_key_variation2.phpt new file mode 100644 index 0000000000..59b769be66 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation2.phpt @@ -0,0 +1,314 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing unexpected values to second argument +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array3 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource var' => $fp, +); + +// loop through each element of the array for arr2 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($array1, $value) ); + var_dump( array_intersect_key($array1, $value, $array3) ); +} + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +--int 0-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +--resource var-- + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_key(): Argument #2 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation3.phpt b/ext/standard/tests/array/array_intersect_key_variation3.phpt new file mode 100644 index 0000000000..8fd3d3c77f --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation3.phpt @@ -0,0 +1,235 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing unexpected values to optional argument +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4); +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//resource variable +$fp = fopen(__FILE__, "r"); + +// define some classes +class classWithToString +{ + public function __toString() { + return "Class A object"; + } +} + +class classWithoutToString +{ +} + +// heredoc string +$heredoc = <<<EOT +hello world +EOT; + +// add arrays +$index_array = array (1, 2, 3); +$assoc_array = array ('one' => 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -12345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, + + // resource data + 'resource var' => $fp, +); + +// loop through each element of the array for arr2 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($array1, $array2, $value) ); +} + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +--int 0-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL + +--resource var-- + +Warning: array_intersect_key(): Argument #3 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation4.phpt b/ext/standard/tests/array/array_intersect_key_variation4.phpt new file mode 100644 index 0000000000..1223d2153e --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation4.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing integer indexed array +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', -1 => '-1' , 02 => 'two', -07 => '-07', 0xA => '0xA', -0xC => '-0xc'); + +$input_arrays = array( + 'decimal indexed' => array(10 => '10', '-17' => '-17'), + 'octal indexed' => array(-011 => '-011', 012 => '012'), + 'hexa indexed' => array(0x12 => '0x12', -0x7 => '-0x7', ), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($input_array, $value) ); + var_dump( array_intersect_key($value, $input_array ) ); +} +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +--decimal indexed-- +array(1) { + [10]=> + string(3) "0xA" +} +array(1) { + [10]=> + string(2) "10" +} + +--octal indexed-- +array(1) { + [10]=> + string(3) "0xA" +} +array(1) { + [10]=> + string(3) "012" +} + +--hexa indexed-- +array(1) { + [-7]=> + string(3) "-07" +} +array(1) { + [-7]=> + string(4) "-0x7" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation5.phpt b/ext/standard/tests/array/array_intersect_key_variation5.phpt new file mode 100644 index 0000000000..c286de6e3f --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation5.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing float indexed array +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 10 => '10' , -10 => '-10'); +$float_indx_array = array(0.0 => '0.0', 10.5 => '10.5' , -10.5 => '-10.5', 0.5 => '0.5'); + +echo "\n-- Testing array_intersect_key() function with float indexed array --\n"; +var_dump( array_intersect_key($input_array, $float_indx_array) ); +var_dump( array_intersect_key($float_indx_array,$input_array ) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +-- Testing array_intersect_key() function with float indexed array -- +array(3) { + [0]=> + string(1) "0" + [10]=> + string(2) "10" + [-10]=> + string(3) "-10" +} +array(3) { + [0]=> + string(3) "0.5" + [10]=> + string(4) "10.5" + [-10]=> + string(5) "-10.5" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation6.phpt b/ext/standard/tests/array/array_intersect_key_variation6.phpt new file mode 100644 index 0000000000..823b0707d9 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation6.phpt @@ -0,0 +1,37 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing boolean indexed array +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 1 => '1' , -10 => '-10'); +$boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF'); + +echo "\n-- Testing array_intersect_key() function with boolean indexed array --\n"; +var_dump( array_intersect_key($input_array, $boolean_indx_array) ); +var_dump( array_intersect_key($boolean_indx_array,$input_array ) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +-- Testing array_intersect_key() function with boolean indexed array -- +array(2) { + [0]=> + string(1) "0" + [1]=> + string(1) "1" +} +array(2) { + [1]=> + string(5) "boolT" + [0]=> + string(5) "boolF" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation7.phpt b/ext/standard/tests/array/array_intersect_key_variation7.phpt new file mode 100644 index 0000000000..fe4446a243 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation7.phpt @@ -0,0 +1,63 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing null,unset and undefeined variable indexed array +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$input_array = array(0 => '0', 1 => '1' , -10 => '-10' , null => 'null'); +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +$input_arrays = array( + 'null indexed' => array(NULL => 'null 1', null => 'null 2'), + 'undefined indexed' => array(@$undefined_var => 'undefined'), + 'unset indexed' => array(@$unset_var => 'unset'), +); + +foreach($input_arrays as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_key($input_array, $value) ); + var_dump( array_intersect_key($value,$input_array ) ); +} +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** + +--null indexed-- +array(1) { + [""]=> + string(4) "null" +} +array(1) { + [""]=> + string(6) "null 2" +} + +--undefined indexed-- +array(1) { + [""]=> + string(4) "null" +} +array(1) { + [""]=> + string(9) "undefined" +} + +--unset indexed-- +array(1) { + [""]=> + string(4) "null" +} +array(1) { + [""]=> + string(5) "unset" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_key_variation8.phpt b/ext/standard/tests/array/array_intersect_key_variation8.phpt new file mode 100644 index 0000000000..2b889b5965 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_key_variation8.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_intersect_key() function : usage variation - Passing Multi dimensional array +--FILE-- +<?php +/* Prototype : array array_intersect_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are present in all the other arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_key() : usage variation ***\n"; + +/// Initialise function arguments not being substituted (if any) +$array1 = array( + + 'first' => array('blue' => 1, 'red' => 2), + + 'second' => array('yellow' => 7), + + 'third' => array(0 =>'zero'), +); + +$array2 = array ( + + 'first' => array('blue' => 1, 'red' => 2,), + + 'second' => array('cyan' => 8), + + 'fourth' => array(2 => 'two'), +); +var_dump( array_intersect_key($array1, $array2) ); +var_dump( array_intersect_key($array2,$array1 ) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_key() : usage variation *** +array(2) { + ["first"]=> + array(2) { + ["blue"]=> + int(1) + ["red"]=> + int(2) + } + ["second"]=> + array(1) { + ["yellow"]=> + int(7) + } +} +array(2) { + ["first"]=> + array(2) { + ["blue"]=> + int(1) + ["red"]=> + int(2) + } + ["second"]=> + array(1) { + ["cyan"]=> + int(8) + } +} +===DONE=== |