Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions ext/bcmath/tests/bcdivmod_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
--TEST--
bcdivmod() requires well-formed values
--EXTENSIONS--
bcmath
--FILE--
<?php

try {
bcdivmod('a', '1');
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

try {
bcdivmod('1', 'a');
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
ValueError: bcdivmod(): Argument #1 ($num1) is not well-formed
ValueError: bcdivmod(): Argument #2 ($num2) is not well-formed
66 changes: 36 additions & 30 deletions ext/bcmath/tests/negative_scale.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,69 @@ bcmath.scale=0
<?php
try {
bcadd('1','2',-1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
bcsub('1','2',-1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
bcmul('1','2',-1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
bcdiv('1','2',-1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
bcmod('1','2',-1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
bcdivmod('1','2',-1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bcdivmod('1','2',-1);
bcdivmod('1', '2', -1);

} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
bcpowmod('1', '2', '3', -9);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
bcpow('1', '2', -1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
bcsqrt('9', -1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
bccomp('1', '2', -1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
try {
bcscale(-1);
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
} catch (\Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
?>
--EXPECT--
bcadd(): Argument #3 ($scale) must be between 0 and 2147483647
bcsub(): Argument #3 ($scale) must be between 0 and 2147483647
bcmul(): Argument #3 ($scale) must be between 0 and 2147483647
bcdiv(): Argument #3 ($scale) must be between 0 and 2147483647
bcmod(): Argument #3 ($scale) must be between 0 and 2147483647
bcpowmod(): Argument #4 ($scale) must be between 0 and 2147483647
bcpow(): Argument #3 ($scale) must be between 0 and 2147483647
bcsqrt(): Argument #2 ($scale) must be between 0 and 2147483647
bccomp(): Argument #3 ($scale) must be between 0 and 2147483647
bcscale(): Argument #1 ($scale) must be between 0 and 2147483647
ValueError: bcadd(): Argument #3 ($scale) must be between 0 and 2147483647
ValueError: bcsub(): Argument #3 ($scale) must be between 0 and 2147483647
ValueError: bcmul(): Argument #3 ($scale) must be between 0 and 2147483647
ValueError: bcdiv(): Argument #3 ($scale) must be between 0 and 2147483647
ValueError: bcmod(): Argument #3 ($scale) must be between 0 and 2147483647
ValueError: bcdivmod(): Argument #3 ($scale) must be between 0 and 2147483647
ValueError: bcpowmod(): Argument #4 ($scale) must be between 0 and 2147483647
ValueError: bcpow(): Argument #3 ($scale) must be between 0 and 2147483647
ValueError: bcsqrt(): Argument #2 ($scale) must be between 0 and 2147483647
ValueError: bccomp(): Argument #3 ($scale) must be between 0 and 2147483647
ValueError: bcscale(): Argument #1 ($scale) must be between 0 and 2147483647
Loading