From ec5e811dbddbcb53db1d6ffa6f69eb9a1a36478e Mon Sep 17 00:00:00 2001 From: Alex McLean Date: Sun, 21 Feb 2021 22:55:43 +1000 Subject: [PATCH] Add test cases for bcmath ValueErrors Closes GH-6714 Signed-off-by: George Peter Banyard --- ext/bcmath/tests/bcadd_error.phpt | 25 ++++++++++++++++++ ext/bcmath/tests/bccomp_error.phpt | 25 ++++++++++++++++++ ext/bcmath/tests/bcdiv_error2.phpt | 25 ++++++++++++++++++ ext/bcmath/tests/bcmod_error3.phpt | 25 ++++++++++++++++++ ext/bcmath/tests/bcmul_error.phpt | 25 ++++++++++++++++++ ext/bcmath/tests/bcpow_error3.phpt | 25 ++++++++++++++++++ ext/bcmath/tests/bcpowmod_error.phpt | 32 ++++++++++++++++++++++++ ext/bcmath/tests/bcsqrt_error2.phpt | 18 +++++++++++++ ext/bcmath/tests/bcsub_error.phpt | 25 ++++++++++++++++++ ext/bcmath/tests/str2num_formatting.phpt | 7 ++++++ 10 files changed, 232 insertions(+) create mode 100644 ext/bcmath/tests/bcadd_error.phpt create mode 100644 ext/bcmath/tests/bccomp_error.phpt create mode 100644 ext/bcmath/tests/bcdiv_error2.phpt create mode 100644 ext/bcmath/tests/bcmod_error3.phpt create mode 100644 ext/bcmath/tests/bcmul_error.phpt create mode 100644 ext/bcmath/tests/bcpow_error3.phpt create mode 100644 ext/bcmath/tests/bcpowmod_error.phpt create mode 100644 ext/bcmath/tests/bcsqrt_error2.phpt create mode 100644 ext/bcmath/tests/bcsub_error.phpt diff --git a/ext/bcmath/tests/bcadd_error.phpt b/ext/bcmath/tests/bcadd_error.phpt new file mode 100644 index 0000000000..adb6c3cdc3 --- /dev/null +++ b/ext/bcmath/tests/bcadd_error.phpt @@ -0,0 +1,25 @@ +--TEST-- +bcadd() requires well-formed values +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +try { + bcadd('1', 'a'); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +bcadd(): Argument #1 ($num1) is not well-formed +bcadd(): Argument #2 ($num2) is not well-formed diff --git a/ext/bcmath/tests/bccomp_error.phpt b/ext/bcmath/tests/bccomp_error.phpt new file mode 100644 index 0000000000..364658dc7d --- /dev/null +++ b/ext/bcmath/tests/bccomp_error.phpt @@ -0,0 +1,25 @@ +--TEST-- +bccomp() requires well-formed values +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +try { + bccomp('1', 'a'); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +bccomp(): Argument #1 ($num1) is not well-formed +bccomp(): Argument #2 ($num2) is not well-formed diff --git a/ext/bcmath/tests/bcdiv_error2.phpt b/ext/bcmath/tests/bcdiv_error2.phpt new file mode 100644 index 0000000000..d7ed546772 --- /dev/null +++ b/ext/bcmath/tests/bcdiv_error2.phpt @@ -0,0 +1,25 @@ +--TEST-- +bcdiv() requires well-formed values +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +try { + bcdiv('1', 'a'); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +bcdiv(): Argument #1 ($num1) is not well-formed +bcdiv(): Argument #2 ($num2) is not well-formed diff --git a/ext/bcmath/tests/bcmod_error3.phpt b/ext/bcmath/tests/bcmod_error3.phpt new file mode 100644 index 0000000000..71718d3be8 --- /dev/null +++ b/ext/bcmath/tests/bcmod_error3.phpt @@ -0,0 +1,25 @@ +--TEST-- +bcmod() requires well-formed values +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +try { + bcmod('1', 'a'); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +bcmod(): Argument #1 ($num1) is not well-formed +bcmod(): Argument #2 ($num2) is not well-formed diff --git a/ext/bcmath/tests/bcmul_error.phpt b/ext/bcmath/tests/bcmul_error.phpt new file mode 100644 index 0000000000..301ef11812 --- /dev/null +++ b/ext/bcmath/tests/bcmul_error.phpt @@ -0,0 +1,25 @@ +--TEST-- +bcmul() requires well-formed values +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +try { + bcmul('1', 'a'); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +bcmul(): Argument #1 ($num1) is not well-formed +bcmul(): Argument #2 ($num2) is not well-formed diff --git a/ext/bcmath/tests/bcpow_error3.phpt b/ext/bcmath/tests/bcpow_error3.phpt new file mode 100644 index 0000000000..fb71e631e6 --- /dev/null +++ b/ext/bcmath/tests/bcpow_error3.phpt @@ -0,0 +1,25 @@ +--TEST-- +bcpow() requires well-formed values +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +try { + bcpow('1', 'a'); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +bcpow(): Argument #1 ($num) is not well-formed +bcpow(): Argument #2 ($exponent) is not well-formed diff --git a/ext/bcmath/tests/bcpowmod_error.phpt b/ext/bcmath/tests/bcpowmod_error.phpt new file mode 100644 index 0000000000..9056f9e755 --- /dev/null +++ b/ext/bcmath/tests/bcpowmod_error.phpt @@ -0,0 +1,32 @@ +--TEST-- +bcpowmod() requires well-formed values +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +try { + bcpowmod('1', 'a', '1'); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} + +try { + bcpowmod('1', '1', 'a'); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +bcpowmod(): Argument #1 ($num) is not well-formed +bcpowmod(): Argument #2 ($exponent) is not well-formed +bcpowmod(): Argument #3 ($modulus) is not well-formed diff --git a/ext/bcmath/tests/bcsqrt_error2.phpt b/ext/bcmath/tests/bcsqrt_error2.phpt new file mode 100644 index 0000000000..85cefa0762 --- /dev/null +++ b/ext/bcmath/tests/bcsqrt_error2.phpt @@ -0,0 +1,18 @@ +--TEST-- +bcsqrt() requires a well-formed value +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +bcsqrt(): Argument #1 ($num) is not well-formed diff --git a/ext/bcmath/tests/bcsub_error.phpt b/ext/bcmath/tests/bcsub_error.phpt new file mode 100644 index 0000000000..0a890eff03 --- /dev/null +++ b/ext/bcmath/tests/bcsub_error.phpt @@ -0,0 +1,25 @@ +--TEST-- +bcsub() requires well-formed values +--SKIPIF-- + +--FILE-- +getMessage() . PHP_EOL; +} + +try { + bcsub('1', 'a'); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} + +?> +--EXPECT-- +bcsub(): Argument #1 ($num1) is not well-formed +bcsub(): Argument #2 ($num2) is not well-formed diff --git a/ext/bcmath/tests/str2num_formatting.phpt b/ext/bcmath/tests/str2num_formatting.phpt index 83e633bdaf..dd3499804e 100644 --- a/ext/bcmath/tests/str2num_formatting.phpt +++ b/ext/bcmath/tests/str2num_formatting.phpt @@ -46,6 +46,12 @@ try { echo $e->getMessage() . PHP_EOL; } +try { + echo bcadd("1.a", "2"); +} catch (\ValueError $e) { + echo $e->getMessage() . PHP_EOL; +} + echo "\n"; echo bccomp("1", "2"),"\n"; @@ -99,6 +105,7 @@ bcadd(): Argument #1 ($num1) is not well-formed bcadd(): Argument #1 ($num1) is not well-formed bcadd(): Argument #1 ($num1) is not well-formed bcadd(): Argument #1 ($num1) is not well-formed +bcadd(): Argument #1 ($num1) is not well-formed -1 -1 -- 2.50.1