mirror of
https://github.com/php/php-src.git
synced 2025-01-08 20:17:28 +08:00
- Committing new array_diff_key tests for Sanjay Mantoor
This commit is contained in:
parent
4344e2ec9e
commit
ce5c43a1ed
36
ext/standard/tests/array/array_diff_key_error.phpt
Normal file
36
ext/standard/tests/array/array_diff_key_error.phpt
Normal file
@ -0,0 +1,36 @@
|
||||
--TEST--
|
||||
Test array_diff_key() function : error conditions
|
||||
--FILE--
|
||||
<?php
|
||||
/* 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() : error conditions ***\n";
|
||||
|
||||
// Initialise the variables
|
||||
$array1 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
|
||||
|
||||
// Testing array_diff_key with one less than the expected number of arguments
|
||||
echo "\n-- Testing array_diff_key() function with less than expected no. of arguments --\n";
|
||||
var_dump( array_diff_key($array1) );
|
||||
|
||||
// Testing array_diff_key with no arguments
|
||||
echo "\n-- Testing array_diff_key() function with no arguments --\n";
|
||||
var_dump( array_diff_key() );
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_key() : error conditions ***
|
||||
|
||||
-- Testing array_diff_key() function with less than expected no. of arguments --
|
||||
|
||||
Warning: array_diff_key(): at least 2 parameters are required, 1 given in %s on line %d
|
||||
NULL
|
||||
|
||||
-- Testing array_diff_key() function with no arguments --
|
||||
|
||||
Warning: array_diff_key(): at least 2 parameters are required, 0 given in %s on line %d
|
||||
NULL
|
||||
===DONE===
|
@ -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===
|
311
ext/standard/tests/array/array_diff_key_variation2.phpt
Normal file
311
ext/standard/tests/array/array_diff_key_variation2.phpt
Normal file
@ -0,0 +1,311 @@
|
||||
--TEST--
|
||||
Test array_diff_key() function : usage variation - Passing unexpected values to second argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* 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)
|
||||
$array1 = 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($array1, $value) );
|
||||
var_dump( array_diff_key($array1, $value, $array3) );
|
||||
};
|
||||
|
||||
fclose($fp);
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_key() : usage variation ***
|
||||
|
||||
--int 0--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 1--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 12345--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int -12345--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 10.5--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -10.5--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 12.3456789000e10--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -12.3456789000e10--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float .5--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase NULL--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase null--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase true--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase false--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase TRUE--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase FALSE--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string DQ--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string SQ--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--string DQ--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--string SQ--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--mixed case string--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--heredoc--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithToString--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithoutToString--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--undefined var--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--unset var--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--resource--
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_diff_key(): Argument #2 is not an array in %s on line %d
|
||||
NULL
|
||||
===DONE===
|
232
ext/standard/tests/array/array_diff_key_variation3.phpt
Normal file
232
ext/standard/tests/array/array_diff_key_variation3.phpt
Normal file
@ -0,0 +1,232 @@
|
||||
--TEST--
|
||||
Test array_diff_key() function : usage variation - Passing unexpected values to third optional argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* 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)
|
||||
$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;
|
||||
|
||||
//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($array1, $array2, $value) );
|
||||
};
|
||||
|
||||
fclose($fp);
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_key() : usage variation ***
|
||||
|
||||
--int 0--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 1--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int 12345--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--int -12345--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 10.5--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -10.5--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float 12.3456789000e10--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float -12.3456789000e10--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--float .5--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase NULL--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase null--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase true--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--lowercase false--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase TRUE--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--uppercase FALSE--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string DQ--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--empty string SQ--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--string DQ--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--string SQ--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--mixed case string--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--heredoc--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithToString--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--instance of classWithoutToString--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--undefined var--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--unset var--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
|
||||
--resource--
|
||||
|
||||
Warning: array_diff_key(): Argument #3 is not an array in %s on line %d
|
||||
NULL
|
||||
===DONE===
|
61
ext/standard/tests/array/array_diff_key_variation4.phpt
Normal file
61
ext/standard/tests/array/array_diff_key_variation4.phpt
Normal file
@ -0,0 +1,61 @@
|
||||
--TEST--
|
||||
Test array_diff_key() function : usage variation - Passing integer indexed array
|
||||
--FILE--
|
||||
<?php
|
||||
/* 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)
|
||||
$input_array = array(-07 => '-07', 0xA => '0xA');
|
||||
|
||||
$input_arrays = array(
|
||||
'decimal indexed' => array(10 => '10', '-17' => '-17'),
|
||||
'octal indexed' => array(-011 => '-011', 012 => '012'),
|
||||
'hexa indexed' => array(0x12 => '0x12', -0x7 => '-0x7', ),
|
||||
);
|
||||
|
||||
// loop through each element of the array for arr1
|
||||
foreach($input_arrays as $key =>$value) {
|
||||
echo "\n--$key--\n";
|
||||
var_dump( array_diff_key($input_array, $value) );
|
||||
var_dump( array_diff_key($value, $input_array) );
|
||||
}
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_key() : usage variation ***
|
||||
|
||||
--decimal indexed--
|
||||
array(1) {
|
||||
[-7]=>
|
||||
string(3) "-07"
|
||||
}
|
||||
array(1) {
|
||||
[-17]=>
|
||||
string(3) "-17"
|
||||
}
|
||||
|
||||
--octal indexed--
|
||||
array(1) {
|
||||
[-7]=>
|
||||
string(3) "-07"
|
||||
}
|
||||
array(1) {
|
||||
[-9]=>
|
||||
string(4) "-011"
|
||||
}
|
||||
|
||||
--hexa indexed--
|
||||
array(1) {
|
||||
[10]=>
|
||||
string(3) "0xA"
|
||||
}
|
||||
array(1) {
|
||||
[18]=>
|
||||
string(4) "0x12"
|
||||
}
|
||||
===DONE===
|
34
ext/standard/tests/array/array_diff_key_variation5.phpt
Normal file
34
ext/standard/tests/array/array_diff_key_variation5.phpt
Normal file
@ -0,0 +1,34 @@
|
||||
--TEST--
|
||||
Test array_diff_key() function : usage variation - Passing float indexed array
|
||||
--FILE--
|
||||
<?php
|
||||
/* 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)
|
||||
$input_array = array(0 => '0', 10 => '10', -10 => '-10', 20 =>'20', -20 => '-20');
|
||||
$float_indx_array = array(0.0 => '0.0', 10.5 => '10.5', -10.5 => '-10.5', 0.5 => '0.5');
|
||||
|
||||
echo "\n-- Testing array_diff_key() function with float indexed array --\n";
|
||||
// loop through each element of the array for arr1
|
||||
var_dump( array_diff_key($input_array, $float_indx_array) );
|
||||
var_dump( array_diff_key($float_indx_array, $input_array) );
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_key() : usage variation ***
|
||||
|
||||
-- Testing array_diff_key() function with float indexed array --
|
||||
array(2) {
|
||||
[20]=>
|
||||
string(2) "20"
|
||||
[-20]=>
|
||||
string(3) "-20"
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
===DONE===
|
36
ext/standard/tests/array/array_diff_key_variation6.phpt
Normal file
36
ext/standard/tests/array/array_diff_key_variation6.phpt
Normal file
@ -0,0 +1,36 @@
|
||||
--TEST--
|
||||
Test array_diff_key() function : usage variation - Passing boolean indexed array
|
||||
--FILE--
|
||||
<?php
|
||||
/* 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)
|
||||
$input_array = array(0 => '0', 1 => '1', -10 => '-10', 'true' => 1, 'false' => 0);
|
||||
$boolean_indx_array = array(true => 'boolt', false => 'boolf', TRUE => 'boolT', FALSE => 'boolF');
|
||||
|
||||
echo "\n-- Testing array_diff_key() function with boolean indexed array --\n";
|
||||
// loop through each element of the array for arr1
|
||||
var_dump( array_diff_key($input_array, $boolean_indx_array) );
|
||||
var_dump( array_diff_key($boolean_indx_array, $input_array) );
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_key() : usage variation ***
|
||||
|
||||
-- Testing array_diff_key() function with boolean indexed array --
|
||||
array(3) {
|
||||
[-10]=>
|
||||
string(3) "-10"
|
||||
["true"]=>
|
||||
int(1)
|
||||
["false"]=>
|
||||
int(0)
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
===DONE===
|
59
ext/standard/tests/array/array_diff_key_variation7.phpt
Normal file
59
ext/standard/tests/array/array_diff_key_variation7.phpt
Normal file
@ -0,0 +1,59 @@
|
||||
--TEST--
|
||||
Test array_diff_key() function : usage variation - Passing null,unset and undefined variable indexed array
|
||||
--FILE--
|
||||
<?php
|
||||
/* 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)
|
||||
$input_array = array(10 => '10', "" => 'empty');
|
||||
|
||||
//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";
|
||||
// loop through each element of the array for arr1
|
||||
var_dump( array_diff_key($input_array, $value) );
|
||||
var_dump( array_diff_key($value, $input_array) );
|
||||
}
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_key() : usage variation ***
|
||||
|
||||
--null indexed--
|
||||
array(1) {
|
||||
[10]=>
|
||||
string(2) "10"
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
|
||||
--undefined indexed--
|
||||
array(1) {
|
||||
[10]=>
|
||||
string(2) "10"
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
|
||||
--unset indexed--
|
||||
array(1) {
|
||||
[10]=>
|
||||
string(2) "10"
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
===DONE===
|
54
ext/standard/tests/array/array_diff_key_variation8.phpt
Normal file
54
ext/standard/tests/array/array_diff_key_variation8.phpt
Normal file
@ -0,0 +1,54 @@
|
||||
--TEST--
|
||||
Test array_diff_key() function : usage variation - Passing multi-dimensional array
|
||||
--FILE--
|
||||
<?php
|
||||
/* 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)
|
||||
$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'),
|
||||
);
|
||||
|
||||
echo "\n-- Testing array_diff_key() function with multi dimensional array --\n";
|
||||
var_dump( array_diff_key($array1, $array2) );
|
||||
var_dump( array_diff_key($array2, $array1) );
|
||||
?>
|
||||
===DONE===
|
||||
--EXPECTF--
|
||||
*** Testing array_diff_key() : usage variation ***
|
||||
|
||||
-- Testing array_diff_key() function with multi dimensional array --
|
||||
array(1) {
|
||||
["third"]=>
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(4) "zero"
|
||||
}
|
||||
}
|
||||
array(1) {
|
||||
["fourth"]=>
|
||||
array(1) {
|
||||
[2]=>
|
||||
string(3) "two"
|
||||
}
|
||||
}
|
||||
===DONE===
|
Loading…
Reference in New Issue
Block a user