summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex McLean <alex.mclean95@gmail.com>2021-02-21 22:55:43 +1000
committerGeorge Peter Banyard <girgias@php.net>2021-03-03 18:35:15 +0000
commitec5e811dbddbcb53db1d6ffa6f69eb9a1a36478e (patch)
tree1968ac471f655ae15fd39445d4d9c45bf244dcfd
parentc3165467f528af468b553db9efeefc6ad55a3b9c (diff)
downloadphp-git-ec5e811dbddbcb53db1d6ffa6f69eb9a1a36478e.tar.gz
Add test cases for bcmath ValueErrors
Closes GH-6714 Signed-off-by: George Peter Banyard <girgias@php.net>
-rw-r--r--ext/bcmath/tests/bcadd_error.phpt25
-rw-r--r--ext/bcmath/tests/bccomp_error.phpt25
-rw-r--r--ext/bcmath/tests/bcdiv_error2.phpt25
-rw-r--r--ext/bcmath/tests/bcmod_error3.phpt25
-rw-r--r--ext/bcmath/tests/bcmul_error.phpt25
-rw-r--r--ext/bcmath/tests/bcpow_error3.phpt25
-rw-r--r--ext/bcmath/tests/bcpowmod_error.phpt32
-rw-r--r--ext/bcmath/tests/bcsqrt_error2.phpt18
-rw-r--r--ext/bcmath/tests/bcsub_error.phpt25
-rw-r--r--ext/bcmath/tests/str2num_formatting.phpt7
10 files changed, 232 insertions, 0 deletions
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--
+<?php
+if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
+?>
+--FILE--
+<?php
+
+try {
+ bcadd('a', '1');
+} catch (\ValueError $e) {
+ echo $e->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--
+<?php
+if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
+?>
+--FILE--
+<?php
+
+try {
+ bccomp('a', '1');
+} catch (\ValueError $e) {
+ echo $e->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--
+<?php
+if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
+?>
+--FILE--
+<?php
+
+try {
+ bcdiv('a', '1');
+} catch (\ValueError $e) {
+ echo $e->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--
+<?php
+if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
+?>
+--FILE--
+<?php
+
+try {
+ bcmod('a', '1');
+} catch (\ValueError $e) {
+ echo $e->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--
+<?php
+if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
+?>
+--FILE--
+<?php
+
+try {
+ bcmul('a', '1');
+} catch (\ValueError $e) {
+ echo $e->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--
+<?php
+if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
+?>
+--FILE--
+<?php
+
+try {
+ bcpow('a', '1');
+} catch (\ValueError $e) {
+ echo $e->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--
+<?php
+if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
+?>
+--FILE--
+<?php
+
+try {
+ bcpowmod('a', '1', '1');
+} catch (\ValueError $e) {
+ echo $e->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--
+<?php
+if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
+?>
+--FILE--
+<?php
+
+try {
+ bcsqrt('a');
+} catch (\ValueError $e) {
+ echo $e->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--
+<?php
+if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
+?>
+--FILE--
+<?php
+
+try {
+ bcsub('a', '1');
+} catch (\ValueError $e) {
+ echo $e->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