php-src/ext/gmp/tests/gmp_mod.phpt
Nikita Popov 65f14b0d6c Throw ValueError instead of TypeError for malformed GMP number
If the passed argument has correct type (string) but does not
have a well-formed value, throw ValueError instead of TypeError.

Closes GH-6572.
2021-01-04 14:30:08 +01:00

51 lines
901 B
PHP

--TEST--
gmp_mod tests()
--SKIPIF--
<?php if (!extension_loaded("gmp")) print "skip"; ?>
--FILE--
<?php
try {
var_dump(gmp_mod("",""));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
var_dump(gmp_mod(0,1));
var_dump(gmp_mod(0,-1));
try {
var_dump(gmp_mod(-1,0));
} catch (\DivisionByZeroError $e) {
echo $e->getMessage() . \PHP_EOL;
}
try {
var_dump(gmp_mod(array(), array()));
} catch (\TypeError $e) {
echo $e->getMessage() . \PHP_EOL;
}
$a = gmp_init("-100000000");
$b = gmp_init("353467");
var_dump(gmp_mod($a, $b));
echo "Done\n";
?>
--EXPECT--
gmp_mod(): Argument #1 ($num1) is not an integer string
object(GMP)#2 (1) {
["num"]=>
string(1) "0"
}
object(GMP)#2 (1) {
["num"]=>
string(1) "0"
}
Modulo by zero
gmp_mod(): Argument #1 ($num1) must be of type GMP|string|int, array given
object(GMP)#4 (1) {
["num"]=>
string(5) "31161"
}
Done