From 92fc589ffd76d5042cf696b1beb4408c163a7bab Mon Sep 17 00:00:00 2001 From: Aman Mohamed Ali <69119173+spidervirus@users.noreply.github.com> Date: Sat, 24 Oct 2026 16:22:12 +0400 Subject: [PATCH 1/2] ext/bcmath: Add missing error test cases for bcdivmod() Add test for ValueError on malformed string inputs to bcdivmod(), and add bcdivmod() negative scale check to negative_scale.phpt. --- ext/bcmath/tests/bcdivmod_error.phpt | 23 +++++++++++++++++++++++ ext/bcmath/tests/negative_scale.phpt | 7 +++++++ 2 files changed, 30 insertions(+) create mode 100644 ext/bcmath/tests/bcdivmod_error.phpt diff --git a/ext/bcmath/tests/bcdivmod_error.phpt b/ext/bcmath/tests/bcdivmod_error.phpt new file mode 100644 index 000000000000..8ab96d74034e --- /dev/null +++ b/ext/bcmath/tests/bcdivmod_error.phpt @@ -0,0 +1,23 @@ +--TEST-- +bcdivmod() requires well-formed values +--EXTENSIONS-- +bcmath +--FILE-- +getMessage() . PHP_EOL; +} + +try { + bcdivmod('1', 'a'); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +bcdivmod(): Argument #1 ($num1) is not well-formed +bcdivmod(): Argument #2 ($num2) is not well-formed diff --git a/ext/bcmath/tests/negative_scale.phpt b/ext/bcmath/tests/negative_scale.phpt index 3b9377559098..1fdda3af39a6 100644 --- a/ext/bcmath/tests/negative_scale.phpt +++ b/ext/bcmath/tests/negative_scale.phpt @@ -31,6 +31,11 @@ try { } catch (\ValueError $e) { echo $e->getMessage() . \PHP_EOL; } +try { + bcdivmod('1','2',-1); +} catch (\ValueError $e) { + echo $e->getMessage() . \PHP_EOL; +} try { bcpowmod('1', '2', '3', -9); } catch (\ValueError $e) { @@ -63,8 +68,10 @@ 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 +bcdivmod(): 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 + From 375ac8ef08c49bfb4be404a3866de4883b41cca1 Mon Sep 17 00:00:00 2001 From: Aman Mohamed Ali <69119173+spidervirus@users.noreply.github.com> Date: Sun, 25 Oct 2026 02:56:04 +0400 Subject: [PATCH 2/2] ext/bcmath: Apply review suggestions for error formatting Update tests to catch \Throwable and prefix output with $e::class per review feedback. --- ext/bcmath/tests/bcdivmod_error.phpt | 12 ++--- ext/bcmath/tests/negative_scale.phpt | 67 ++++++++++++++-------------- 2 files changed, 39 insertions(+), 40 deletions(-) diff --git a/ext/bcmath/tests/bcdivmod_error.phpt b/ext/bcmath/tests/bcdivmod_error.phpt index 8ab96d74034e..8690796f7f57 100644 --- a/ext/bcmath/tests/bcdivmod_error.phpt +++ b/ext/bcmath/tests/bcdivmod_error.phpt @@ -7,17 +7,17 @@ bcmath try { bcdivmod('a', '1'); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } try { bcdivmod('1', 'a'); -} catch (\ValueError $e) { - echo $e->getMessage() . PHP_EOL; +} catch (\Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; } ?> --EXPECT-- -bcdivmod(): Argument #1 ($num1) is not well-formed -bcdivmod(): Argument #2 ($num2) is not well-formed +ValueError: bcdivmod(): Argument #1 ($num1) is not well-formed +ValueError: bcdivmod(): Argument #2 ($num2) is not well-formed diff --git a/ext/bcmath/tests/negative_scale.phpt b/ext/bcmath/tests/negative_scale.phpt index 1fdda3af39a6..d911f01e279f 100644 --- a/ext/bcmath/tests/negative_scale.phpt +++ b/ext/bcmath/tests/negative_scale.phpt @@ -8,70 +8,69 @@ bcmath.scale=0 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); -} catch (\ValueError $e) { - echo $e->getMessage() . \PHP_EOL; +} 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 -bcdivmod(): 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