mirror of
https://github.com/php/php-src.git
synced 2025-01-23 20:23:31 +08:00
MFH: split the test
This commit is contained in:
parent
a7b240b337
commit
241e66a708
42
ext/standard/tests/array/array_keys_error.phpt
Normal file
42
ext/standard/tests/array/array_keys_error.phpt
Normal file
@ -0,0 +1,42 @@
|
||||
--TEST--
|
||||
Test array_keys() function (error conditions)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "\n*** Testing error conditions ***";
|
||||
var_dump(array_keys(100));
|
||||
var_dump(array_keys("string"));
|
||||
var_dump(array_keys(new stdclass)); // object
|
||||
var_dump(array_keys()); // Zero arguments
|
||||
var_dump(array_keys(array(), "", TRUE, 100)); // args > expected
|
||||
var_dump(array_keys(array(1,2,3, array() => array()))); // (W)illegal offset
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing error conditions ***
|
||||
Warning: array_keys(): The first argument should be an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_keys(): The first argument should be an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: array_keys(): The first argument should be an array in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: Wrong parameter count for array_keys() in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: Wrong parameter count for array_keys() in %s on line %d
|
||||
NULL
|
||||
|
||||
Warning: Illegal offset type in %s on line %d
|
||||
array(3) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(1)
|
||||
[2]=>
|
||||
int(2)
|
||||
}
|
||||
Done
|
147
ext/standard/tests/array/array_keys_variation_001.phpt
Normal file
147
ext/standard/tests/array/array_keys_variation_001.phpt
Normal file
@ -0,0 +1,147 @@
|
||||
--TEST--
|
||||
Test array_keys() function (variation - 1)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "\n*** Testing array_keys() on various arrays ***";
|
||||
$arrays = array(
|
||||
array(),
|
||||
array(0),
|
||||
array( array() ),
|
||||
array("Hello" => "World"),
|
||||
array("" => ""),
|
||||
array(1,2,3, "d" => array(4,6, "d")),
|
||||
array("a" => 1, "b" => 2, "c" =>3, "d" => array()),
|
||||
array(0 => 0, 1 => 1, 2 => 2, 3 => 3),
|
||||
array(0.001=>3.000, 1.002=>2, 1.999=>3, "a"=>3, 3=>5, "5"=>3.000),
|
||||
array(TRUE => TRUE, FALSE => FALSE, NULL => NULL, "\x000", "\000"),
|
||||
array("a" => "abcd", "a" => "", "ab" => -6, "cd" => -0.5 ),
|
||||
array(0 => array(), 1=> array(0), 2 => array(1), ""=> array(),""=>"" )
|
||||
);
|
||||
|
||||
$i = 0;
|
||||
/* loop through to test array_keys() with different arrays */
|
||||
foreach ($arrays as $array) {
|
||||
echo "\n-- Iteration $i --\n";
|
||||
var_dump(array_keys($array));
|
||||
$i++;
|
||||
}
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_keys() on various arrays ***
|
||||
-- Iteration 0 --
|
||||
array(0) {
|
||||
}
|
||||
|
||||
-- Iteration 1 --
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-- Iteration 2 --
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
-- Iteration 3 --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(5) "Hello"
|
||||
}
|
||||
|
||||
-- Iteration 4 --
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
}
|
||||
|
||||
-- Iteration 5 --
|
||||
array(4) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(1)
|
||||
[2]=>
|
||||
int(2)
|
||||
[3]=>
|
||||
string(1) "d"
|
||||
}
|
||||
|
||||
-- Iteration 6 --
|
||||
array(4) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
[3]=>
|
||||
string(1) "d"
|
||||
}
|
||||
|
||||
-- Iteration 7 --
|
||||
array(4) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(1)
|
||||
[2]=>
|
||||
int(2)
|
||||
[3]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-- Iteration 8 --
|
||||
array(5) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(1)
|
||||
[2]=>
|
||||
string(1) "a"
|
||||
[3]=>
|
||||
int(3)
|
||||
[4]=>
|
||||
int(5)
|
||||
}
|
||||
|
||||
-- Iteration 9 --
|
||||
array(5) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(0)
|
||||
[2]=>
|
||||
string(0) ""
|
||||
[3]=>
|
||||
int(2)
|
||||
[4]=>
|
||||
int(3)
|
||||
}
|
||||
|
||||
-- Iteration 10 --
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(2) "ab"
|
||||
[2]=>
|
||||
string(2) "cd"
|
||||
}
|
||||
|
||||
-- Iteration 11 --
|
||||
array(4) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(1)
|
||||
[2]=>
|
||||
int(2)
|
||||
[3]=>
|
||||
string(0) ""
|
||||
}
|
||||
Done
|
52
ext/standard/tests/array/array_keys_variation_002.phpt
Normal file
52
ext/standard/tests/array/array_keys_variation_002.phpt
Normal file
@ -0,0 +1,52 @@
|
||||
--TEST--
|
||||
Test array_keys() function (variation - 2)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "\n*** Testing array_keys() on range of values ***\n";
|
||||
$arr_range = array(
|
||||
2147483647 => 1,
|
||||
2147483648 => 2,
|
||||
-2147483647 => 3,
|
||||
-2147483648 => 4,
|
||||
-2147483649 => 5,
|
||||
-0 => 6,
|
||||
0 => 7
|
||||
);
|
||||
var_dump(array_keys($arr_range));
|
||||
|
||||
echo "\n*** Testing array_keys() on an array created on the fly ***\n";
|
||||
var_dump(array_keys(array("a" => 1, "b" => 2, "c" => 3)));
|
||||
var_dump(array_keys(array())); // null array
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_keys() on range of values ***
|
||||
array(4) {
|
||||
[0]=>
|
||||
int(2147483647)
|
||||
[1]=>
|
||||
int(-2147483648)
|
||||
[2]=>
|
||||
int(-2147483647)
|
||||
[3]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
*** Testing array_keys() on an array created on the fly ***
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
Done
|
56
ext/standard/tests/array/array_keys_variation_002_64bit.phpt
Normal file
56
ext/standard/tests/array/array_keys_variation_002_64bit.phpt
Normal file
@ -0,0 +1,56 @@
|
||||
--TEST--
|
||||
Test array_keys() function (variation - 2)
|
||||
--SKIPIF--
|
||||
<?php
|
||||
if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "\n*** Testing array_keys() on range of values ***\n";
|
||||
$arr_range = array(
|
||||
2147483647 => 1,
|
||||
2147483648 => 2,
|
||||
-2147483647 => 3,
|
||||
-2147483648 => 4,
|
||||
-2147483649 => 5,
|
||||
-0 => 6,
|
||||
0 => 7
|
||||
);
|
||||
var_dump(array_keys($arr_range));
|
||||
|
||||
echo "\n*** Testing array_keys() on an array created on the fly ***\n";
|
||||
var_dump(array_keys(array("a" => 1, "b" => 2, "c" => 3)));
|
||||
var_dump(array_keys(array())); // null array
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_keys() on range of values ***
|
||||
array(6) {
|
||||
[0]=>
|
||||
int(2147483647)
|
||||
[1]=>
|
||||
int(2147483648)
|
||||
[2]=>
|
||||
int(-2147483647)
|
||||
[3]=>
|
||||
int(-2147483648)
|
||||
[4]=>
|
||||
int(-2147483649)
|
||||
[5]=>
|
||||
int(0)
|
||||
}
|
||||
|
||||
*** Testing array_keys() on an array created on the fly ***
|
||||
array(3) {
|
||||
[0]=>
|
||||
string(1) "a"
|
||||
[1]=>
|
||||
string(1) "b"
|
||||
[2]=>
|
||||
string(1) "c"
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
Done
|
102
ext/standard/tests/array/array_keys_variation_003.phpt
Normal file
102
ext/standard/tests/array/array_keys_variation_003.phpt
Normal file
@ -0,0 +1,102 @@
|
||||
--TEST--
|
||||
Test array_keys() function (variation - 3)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "*** Testing array_keys() on all the types other than arrays ***\n";
|
||||
$types_arr = array(
|
||||
TRUE => TRUE,
|
||||
FALSE => FALSE,
|
||||
1 => 1,
|
||||
0 => 0,
|
||||
-1 => -1,
|
||||
"1" => "1",
|
||||
"0" => "0",
|
||||
"-1" => "-1",
|
||||
NULL,
|
||||
array(),
|
||||
"php" => "php",
|
||||
"" => ""
|
||||
);
|
||||
$values = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "php", "");
|
||||
foreach ($values as $value){
|
||||
var_dump(array_keys($types_arr, $value));
|
||||
}
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_keys() on all the types other than arrays ***
|
||||
array(3) {
|
||||
[0]=>
|
||||
int(1)
|
||||
[1]=>
|
||||
int(-1)
|
||||
[2]=>
|
||||
string(3) "php"
|
||||
}
|
||||
array(4) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(2)
|
||||
[2]=>
|
||||
int(3)
|
||||
[3]=>
|
||||
string(0) ""
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(1)
|
||||
}
|
||||
array(4) {
|
||||
[0]=>
|
||||
int(0)
|
||||
[1]=>
|
||||
int(2)
|
||||
[2]=>
|
||||
string(3) "php"
|
||||
[3]=>
|
||||
string(0) ""
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(-1)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(1)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(0)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(-1)
|
||||
}
|
||||
array(3) {
|
||||
[0]=>
|
||||
int(2)
|
||||
[1]=>
|
||||
int(3)
|
||||
[2]=>
|
||||
string(0) ""
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(2)
|
||||
[1]=>
|
||||
int(3)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(3) "php"
|
||||
}
|
||||
array(2) {
|
||||
[0]=>
|
||||
int(2)
|
||||
[1]=>
|
||||
string(0) ""
|
||||
}
|
||||
Done
|
68
ext/standard/tests/array/array_keys_variation_004.phpt
Normal file
68
ext/standard/tests/array/array_keys_variation_004.phpt
Normal file
@ -0,0 +1,68 @@
|
||||
--TEST--
|
||||
Test array_keys() function (variation - 4)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "*** Testing array_keys() on all the types other than arrays ***\n";
|
||||
$types_arr = array(
|
||||
TRUE => TRUE,
|
||||
FALSE => FALSE,
|
||||
1 => 1,
|
||||
0 => 0,
|
||||
-1 => -1,
|
||||
"1" => "1",
|
||||
"0" => "0",
|
||||
"-1" => "-1",
|
||||
NULL,
|
||||
array(),
|
||||
"php" => "php",
|
||||
"" => ""
|
||||
);
|
||||
$values = array(TRUE, FALSE, 1, 0, -1, "1", "0", "-1", NULL, array(), "php", "");
|
||||
foreach ($values as $value){
|
||||
var_dump(array_keys($types_arr, $value, TRUE));
|
||||
}
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_keys() on all the types other than arrays ***
|
||||
array(0) {
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
array(0) {
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(1)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(0)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(-1)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(2)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(3)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(3) "php"
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
string(0) ""
|
||||
}
|
||||
Done
|
40
ext/standard/tests/array/array_keys_variation_005.phpt
Normal file
40
ext/standard/tests/array/array_keys_variation_005.phpt
Normal file
@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
Test array_keys() function (variation - 5)
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
echo "\n*** Testing array_keys() with resource type ***\n";
|
||||
$resource1 = fopen( __FILE__, "r");
|
||||
$resource2 = opendir( "." );
|
||||
|
||||
/* creating an array with resource types as elements */
|
||||
$arr_resource = array($resource1, $resource2);
|
||||
|
||||
var_dump(array_keys($arr_resource, $resource1)); // loose type checking
|
||||
var_dump(array_keys($arr_resource, $resource1, TRUE)); // strict type checking
|
||||
var_dump(array_keys($arr_resource, $resource2)); // loose type checking
|
||||
var_dump(array_keys($arr_resource, $resource2, TRUE)); // strict type checking
|
||||
|
||||
/* Closing the resource handles */
|
||||
fclose( $resource1 );
|
||||
closedir( $resource2 );
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing array_keys() with resource type ***
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(0)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(0)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(1)
|
||||
}
|
||||
array(1) {
|
||||
[0]=>
|
||||
int(1)
|
||||
}
|
Loading…
Reference in New Issue
Block a user