diff options
author | Sanjay Mantoor <smantoor@php.net> | 2008-10-28 10:21:12 +0000 |
---|---|---|
committer | Sanjay Mantoor <smantoor@php.net> | 2008-10-28 10:21:12 +0000 |
commit | 2b1b26bf6d9f22b564b40e6857655a05deb884db (patch) | |
tree | 306357729e32d992c06131b9028729f44f5e1c28 | |
parent | 5d5215c49c9ba1f73d9d3c130585f7f6bdfab4a4 (diff) | |
download | php-git-2b1b26bf6d9f22b564b40e6857655a05deb884db.tar.gz |
New testcases for array_intersect_uassoc function
11 files changed, 1510 insertions, 0 deletions
diff --git a/ext/standard/tests/array/array_intersect_uassoc_error.phpt b/ext/standard/tests/array/array_intersect_uassoc_error.phpt new file mode 100644 index 0000000000..ae7acb133b --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_error.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_intersect_uassoc() function : error conditions +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : error conditions ***\n"; + +// Initialise function arguments +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$array3 = array("a"=>"green", "brown"); +$extra_arg = 10; + +//Callback function +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} + +//Test array_intersect_uassoc with one more than the expected number of arguments +echo "\n-- Testing array_intersect_uassoc() function with more than expected no. of arguments --\n"; +var_dump( array_intersect_uassoc($array1, $array2, 'key_compare_func',$extra_arg) ); + +// Testing array_intersect_uassoc with one less than the expected number of arguments +echo "\n-- Testing array_intersect_uassoc() function with less than expected no. of arguments --\n"; +var_dump( array_intersect_uassoc($array1, $array2) ); +var_dump( array_intersect_uassoc($array1, $array2, $array3) ); + +// Testing array_intersect_uassoc with no arguments +echo "\n-- Testing array_intersect_uassoc() function with no arguments --\n"; +var_dump( array_intersect_uassoc() ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : error conditions *** + +-- Testing array_intersect_uassoc() function with more than expected no. of arguments -- + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +-- Testing array_intersect_uassoc() function with less than expected no. of arguments -- + +Warning: array_intersect_uassoc(): at least 3 parameters are required, 2 given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, second array member is not a valid method in %s on line %d +NULL + +-- Testing array_intersect_uassoc() function with no arguments -- + +Warning: array_intersect_uassoc(): at least 3 parameters are required, 0 given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation1.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation1.phpt new file mode 100644 index 0000000000..86dec03d2d --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation1.phpt @@ -0,0 +1,323 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing unexpected values to first argument +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments +$array2 = array("a" => "green", "yellow", "red"); +$array3 = array("a"=>"green", "brown"); + +//Callback function +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} + +//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' => $fp, +); + +// loop through each element of the array for arr1 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_uassoc($value, $array2, 'key_compare_func') ); + var_dump( array_intersect_uassoc($value, $array2, $array3, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- + +*** Testing array_intersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #1 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation10.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation10.phpt new file mode 100644 index 0000000000..7089e63475 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation10.phpt @@ -0,0 +1,55 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing class/object methods to callback +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$array1 = array("a" => "green", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +// define some class with method +class MyClass +{ + static function static_compare_func($a, $b) { + return strcasecmp($a, $b); + } + + public function class_compare_func($a, $b) { + return strcasecmp($a, $b); + } + +} + +echo "\n-- Testing array_intersect_uassoc() function using class with static method as callback --\n"; +var_dump( array_intersect_uassoc($array1, $array2, array('MyClass','static_compare_func')) ); +var_dump( array_intersect_uassoc($array1, $array2, 'MyClass::static_compare_func')); + +echo "\n-- Testing array_intersect_uassoc() function using class with regular method as callback --\n"; +$obj = new MyClass(); +var_dump( array_intersect_uassoc($array1, $array2, array($obj,'class_compare_func')) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Testing array_intersect_uassoc() function using class with static method as callback -- +array(1) { + [u"a"]=> + unicode(5) "green" +} +array(1) { + [u"a"]=> + unicode(5) "green" +} + +-- Testing array_intersect_uassoc() function using class with regular method as callback -- +array(1) { + [u"a"]=> + unicode(5) "green" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation2.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation2.phpt new file mode 100644 index 0000000000..51341bb45e --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation2.phpt @@ -0,0 +1,323 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing unexpected values to second argument +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array3 = array("a"=>"green", "brown"); + +//Callback function +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} + +//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' => $fp, +); + +// loop through each element of the array for arr1 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_uassoc($array1, $value, 'key_compare_func') ); + var_dump( array_intersect_uassoc($array1, $value, $array3, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- + +*** Testing array_intersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL + +Warning: array_intersect_uassoc(): Argument #2 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation3.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation3.phpt new file mode 100644 index 0000000000..f596e9c32b --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation3.phpt @@ -0,0 +1,244 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing unexpected values to optional third argument +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); + +//Callback function +function key_compare_func($a, $b) { + if ($a === $b) { + return 0; + } + return ($a > $b) ? 1 : -1; +} + +//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' => $fp, +); + +// loop through each element of the array for arr1 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_uassoc($array1, $array2, $value, 'key_compare_func') ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- + +*** Testing array_intersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_intersect_uassoc(): Argument #3 is not an array in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation4.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation4.phpt new file mode 100644 index 0000000000..e5d0f56568 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation4.phpt @@ -0,0 +1,257 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing unexpected values to mandatory third argument +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +// Initialise function arguments +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); +$array3 = array("a"=>"green", "brown"); + +//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, + + // 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' => $fp, +); + +// loop through each element of the array for arr1 +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_intersect_uassoc($array1, $array2, $value) ); + var_dump( array_intersect_uassoc($array1, $array2, $array3, $value) ); +}; + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +--int 0-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int 1-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int 12345-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--int -12345-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float 10.5-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float -10.5-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--float .5-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase null-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase true-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--lowercase false-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--undefined var-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--unset var-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL + +--resource-- + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, no array or string given in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 4 to be a valid callback, no array or string given in %s on line %d +NULL +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation5.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation5.phpt new file mode 100644 index 0000000000..ec7ee81969 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation5.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Intersection of integers with floats and strings. +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$arr_default_int = array(1, 2 ); +$arr_float = array(0 => 1.00, 1.00 => 2.00, 2.00 => 3.00); +$arr_string = array('1', '2', '3'); +$arr_string_float = array('1.00', '2.00'); + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +echo "\n-- Result of integers and floating point intersection --\n"; +var_dump( array_intersect_uassoc($arr_default_int, $arr_float, "key_compare_func") ); + +echo "\n-- Result of integers and strings containing integers intersection --\n"; +var_dump( array_intersect_uassoc($arr_default_int, $arr_string, "key_compare_func") ); + +echo "\n-- Result of integers and strings containing floating points intersection --\n"; +var_dump( array_intersect_uassoc($arr_default_int, $arr_string_float, "key_compare_func") ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Result of integers and floating point intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Result of integers and strings containing integers intersection -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +-- Result of integers and strings containing floating points intersection -- +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation6.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation6.phpt new file mode 100644 index 0000000000..55dd46d48e --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation6.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Intersection of floating points with strings. +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$arr_float = array(0 => 1.00, 1.00 => 2.00); +$arr_string = array('1', '2', '3'); +$arr_string_float = array('1.00', '2.00'); + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +echo "\n-- Result of floating points and strings containing integers intersection --\n"; +var_dump( array_intersect_uassoc($arr_float, $arr_string, "key_compare_func") ); + +echo "\n-- Result of floating points and strings containing floating point intersection --\n"; +var_dump( array_intersect_uassoc($arr_float, $arr_string_float, "key_compare_func") ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Result of floating points and strings containing integers intersection -- +array(2) { + [0]=> + float(1) + [1]=> + float(2) +} + +-- Result of floating points and strings containing floating point intersection -- +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation7.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation7.phpt new file mode 100644 index 0000000000..7f5198ed0a --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation7.phpt @@ -0,0 +1,54 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Intersection of strings containing integers, float +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$arr1_string_int = array('1', '2'); +$arr2_string_int = array('1', '3'); +$arr1_string_float = array('1.00', '2.00'); +$arr2_string_float = array('1.00', '3.00'); + +function key_compare_func($a, $b) +{ + if ($a === $b) { + return 0; + } + return ($a > $b)? 1:-1; +} + +echo "\n-- Result of strings containing integers intersection --\n"; +var_dump( array_intersect_uassoc($arr1_string_int, $arr2_string_int, "key_compare_func") ); + +echo "\n-- Result of strings containing floating points intersection --\n"; +var_dump( array_intersect_uassoc($arr1_string_float, $arr2_string_float, "key_compare_func") ); + +echo "\n-- Result of strings containing integers and strings containing floating points intersection --\n"; +var_dump( array_intersect_uassoc($arr1_string_int, $arr2_string_float, "key_compare_func") ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Result of strings containing integers intersection -- +array(1) { + [0]=> + unicode(1) "1" +} + +-- Result of strings containing floating points intersection -- +array(1) { + [0]=> + unicode(4) "1.00" +} + +-- Result of strings containing integers and strings containing floating points intersection -- +array(0) { +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation8.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation8.phpt new file mode 100644 index 0000000000..8e8a8d0bb4 --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation8.phpt @@ -0,0 +1,51 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - arrays containing referenced variables +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$ref_var = 'a'; +$array1 = array('a', $ref_var); +$array2 = array('a' => 1, &$ref_var); + +echo "\n-- Testing array_intersect_uassoc() function with referenced variable \$ref_var has value '$ref_var' --\n"; +var_dump( array_intersect_uassoc($array1, $array2, "strcasecmp") ); + +// re-assign reference variable to different value +$ref_var = 10; +echo "\n-- Testing array_intersect_uassoc() function with referenced variable \$ref_var value changed to $ref_var --\n"; +var_dump( array_intersect_uassoc($array1, $array2, "strcasecmp") ); + +//When array are referenced +$array2 = &$array1; +echo "\n-- Testing array_intersect_uassoc() function when \$array2 is referencd to \$array1 --\n"; +var_dump( array_intersect_uassoc($array1, $array2, "strcasecmp") ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +-- Testing array_intersect_uassoc() function with referenced variable $ref_var has value 'a' -- +array(1) { + [0]=> + unicode(1) "a" +} + +-- Testing array_intersect_uassoc() function with referenced variable $ref_var value changed to 10 -- +array(0) { +} + +-- Testing array_intersect_uassoc() function when $array2 is referencd to $array1 -- +array(2) { + [0]=> + unicode(1) "a" + [1]=> + unicode(1) "a" +} +===DONE=== diff --git a/ext/standard/tests/array/array_intersect_uassoc_variation9.phpt b/ext/standard/tests/array/array_intersect_uassoc_variation9.phpt new file mode 100644 index 0000000000..64f58a6d1e --- /dev/null +++ b/ext/standard/tests/array/array_intersect_uassoc_variation9.phpt @@ -0,0 +1,39 @@ +--TEST-- +Test array_intersect_uassoc() function : usage variation - Passing non-existing function name to callback +--FILE-- +<?php +/* Prototype : array array_intersect_uassoc(array arr1, array arr2 [, array ...], callback key_compare_func) + * Description: Computes the intersection of arrays with additional index check, compares indexes by a callback function + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_intersect_uassoc() : usage variation ***\n"; + +//Initialize variables +$array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red"); +$array2 = array("a" => "green", "yellow", "red"); + +//function name within double quotes +var_dump( array_intersect_uassoc($array1, $array2, "unknown_function") ); + +//function name within single quotes +var_dump( array_intersect_uassoc($array1, $array2, 'unknown_function') ); + +//function name without quotes +var_dump( array_intersect_uassoc($array1, $array2, unknown_function) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_intersect_uassoc() : usage variation *** + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL + +Notice: Use of undefined constant unknown_function - assumed 'unknown_function' in %s on line %d + +Warning: array_intersect_uassoc() expects parameter 3 to be a valid callback, function 'unknown_function' not found or invalid function name in %s on line %d +NULL +===DONE=== |