1
0
mirror of https://github.com/php/php-src.git synced 2026-03-26 09:12:14 +01:00
Files
archived-php-src/ext/standard/tests/array/array_rand.phpt
George Peter Banyard 5fbd49f9ab Convert Errors to ValueErrors
Closes GH-4930
2019-12-05 14:22:54 +01:00

60 lines
1.0 KiB
PHP

--TEST--
array_rand() tests
--FILE--
<?php
try {
var_dump(array_rand(array()));
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(array_rand(array(), 0));
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(array_rand(array(1,2,3), 0));
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(array_rand(array(1,2,3), -1));
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
try {
var_dump(array_rand(array(1,2,3), 10));
} catch (\ValueError $e) {
echo $e->getMessage() . "\n";
}
var_dump(array_rand(array(1,2,3), 3));
var_dump(array_rand(array(1,2,3), 2));
?>
--EXPECTF--
Array is empty
Array is empty
Second argument has to be between 1 and the number of elements in the array
Second argument has to be between 1 and the number of elements in the array
Second argument has to be between 1 and the number of elements in the array
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
array(2) {
[0]=>
int(%d)
[1]=>
int(%d)
}