jmessa Tue Aug 12 11:02:00 2008 UTC Added files: (Branch: PHP_5_3) /php-src/ext/standard/tests/array array_diff_key_variation3.phpt array_diff_key_variation2.phpt array_diff_key_variation5.phpt array_diff_key_error.phpt array_diff_key_variation4.phpt array_diff_key_variation8.phpt array_diff_key_variation6.phpt array_diff_key_variation7.phpt
Modified files: /php-src/ext/standard/tests/array array_diff_key_variation1.phpt Log: - Committing new array_diff_key tests for Sanjay Mantoor
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_diff_key_variation1.phpt?r1=1.1.2.1&r2=1.1.2.2&diff_format=u Index: php-src/ext/standard/tests/array/array_diff_key_variation1.phpt diff -u php-src/ext/standard/tests/array/array_diff_key_variation1.phpt:1.1.2.1 php-src/ext/standard/tests/array/array_diff_key_variation1.phpt:1.1.2.2 --- php-src/ext/standard/tests/array/array_diff_key_variation1.phpt:1.1.2.1 Fri Jan 25 00:13:48 2008 +++ php-src/ext/standard/tests/array/array_diff_key_variation1.phpt Tue Aug 12 11:01:59 2008 @@ -1,89 +1,310 @@ --TEST-- -array_diff_key() : type variations +Test array_diff_key() function : usage variation - Passing unexpected values to first argument --FILE-- <?php -/* -* proto array array_diff_key(array arr1, array arr2 [, array ...]) -* Function is implemented in ext/standard/array.c -*/ -/* -* Testing how array_diff_key treats keys that are numbers, floating point numbers or strings. -*/ -$arr1 = array(1 => 'a', 2 => 'b', 3 => 'c', 'key1' => 'value'); -$arr2 = array(1.00 => 'a', 2.00 => 'b', 3.00 => 'c', 'key2' => 'value'); -$arr3 = array('1' => 'a', '2' => 'b', '3' => 'c', 'key3' => 'value'); -$arr4 = array('1.00' => 'a', '2.00' => 'b', '3.00' => 'c', 'key4' => 'value'); //$arr4 looks different to the other three arrays. -print "Result of comparing integers and floating point value:\n"; //1 and 1.00 are treated as the same thing -print_r(array_diff_key($arr1, $arr2)); -print_r(array_diff_key($arr2, $arr1)); -print "Result of comparing integers and strings containing an integers:\n"; //1 and the string 1 are treated as the same thing -print_r(array_diff_key($arr1, $arr3)); -print_r(array_diff_key($arr3, $arr1)); -print "Result of comparing integers and strings containing floating points:\n"; //1 and the string 1.00 are not treated as the same thing -print_r(array_diff_key($arr1, $arr4)); -print_r(array_diff_key($arr4, $arr1)); -print "Result of comparing floating points and strings containing integers:\n"; -print_r(array_diff_key($arr2, $arr3)); //1.00 and the string 1 are treated as the same thing -print_r(array_diff_key($arr3, $arr2)); -print "Result of comparing strings containing integers and strings containing floating points:\n"; //the strings 1 and 1.00 are not treated as the same thing. -print_r(array_diff_key($arr3, $arr4)); -print_r(array_diff_key($arr4, $arr3)); +/* Prototype : array array_diff_key(array arr1, array arr2 [, array ...]) + * Description: Returns the entries of arr1 that have keys which are not present in any of the others arguments. + * Source code: ext/standard/array.c + */ + +echo "*** Testing array_diff_key() : usage variation ***\n"; + +// Initialise function arguments not being substituted (if any) +$array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8); +$array3 = array(1, 2, 3, 4, 5); + +//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; + +//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_diff_key($value, $array2) ); + var_dump( array_diff_key($value, $array2, $array3) ); +}; + +fclose($fp); ?> +===DONE=== --EXPECTF-- -Result of comparing integers and floating point value: -Array -( - [key1] => value -) -Array -( - [key2] => value -) -Result of comparing integers and strings containing an integers: -Array -( - [key1] => value -) -Array -( - [key3] => value -) -Result of comparing integers and strings containing floating points: -Array -( - [1] => a - [2] => b - [3] => c - [key1] => value -) -Array -( - [1.00] => a - [2.00] => b - [3.00] => c - [key4] => value -) -Result of comparing floating points and strings containing integers: -Array -( - [key2] => value -) -Array -( - [key3] => value -) -Result of comparing strings containing integers and strings containing floating points: -Array -( - [1] => a - [2] => b - [3] => c - [key3] => value -) -Array -( - [1.00] => a - [2.00] => b - [3.00] => c - [key4] => value -) +*** Testing array_diff_key() : usage variation *** + +--int 0-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--int 1-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--int 12345-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--int -12345-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--float 10.5-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--float -10.5-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--float .5-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase NULL-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase null-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase true-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--lowercase false-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase TRUE-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--uppercase FALSE-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--empty string DQ-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--empty string SQ-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--string DQ-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--string SQ-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--mixed case string-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--heredoc-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithToString-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--undefined var-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--unset var-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +--resource-- + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL + +Warning: array_diff_key(): Argument #1 is not an array in %s on line %d +NULL +===DONE=== \ No newline at end of file http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_diff_key_variation3.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/array_diff_key_variation3.phpt +++ php-src/ext/standard/tests/array/array_diff_key_variation3.phpt http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_diff_key_variation2.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/array_diff_key_variation2.phpt +++ php-src/ext/standard/tests/array/array_diff_key_variation2.phpt http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_diff_key_variation5.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/array_diff_key_variation5.phpt +++ php-src/ext/standard/tests/array/array_diff_key_variation5.phpt http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_diff_key_error.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/array_diff_key_error.phpt +++ php-src/ext/standard/tests/array/array_diff_key_error.phpt http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_diff_key_variation4.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/array_diff_key_variation4.phpt +++ php-src/ext/standard/tests/array/array_diff_key_variation4.phpt http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_diff_key_variation8.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/array_diff_key_variation8.phpt +++ php-src/ext/standard/tests/array/array_diff_key_variation8.phpt http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_diff_key_variation6.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/array_diff_key_variation6.phpt +++ php-src/ext/standard/tests/array/array_diff_key_variation6.phpt http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_diff_key_variation7.phpt?view=markup&rev=1.1 Index: php-src/ext/standard/tests/array/array_diff_key_variation7.phpt +++ php-src/ext/standard/tests/array/array_diff_key_variation7.phpt
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php