]> granicus.if.org Git - php/commitdiff
Add test cases for bcmath ValueErrors
authorAlex McLean <alex.mclean95@gmail.com>
Sun, 21 Feb 2021 12:55:43 +0000 (22:55 +1000)
committerGeorge Peter Banyard <girgias@php.net>
Wed, 3 Mar 2021 18:35:15 +0000 (18:35 +0000)
Closes GH-6714

Signed-off-by: George Peter Banyard <girgias@php.net>
ext/bcmath/tests/bcadd_error.phpt [new file with mode: 0644]
ext/bcmath/tests/bccomp_error.phpt [new file with mode: 0644]
ext/bcmath/tests/bcdiv_error2.phpt [new file with mode: 0644]
ext/bcmath/tests/bcmod_error3.phpt [new file with mode: 0644]
ext/bcmath/tests/bcmul_error.phpt [new file with mode: 0644]
ext/bcmath/tests/bcpow_error3.phpt [new file with mode: 0644]
ext/bcmath/tests/bcpowmod_error.phpt [new file with mode: 0644]
ext/bcmath/tests/bcsqrt_error2.phpt [new file with mode: 0644]
ext/bcmath/tests/bcsub_error.phpt [new file with mode: 0644]
ext/bcmath/tests/str2num_formatting.phpt

diff --git a/ext/bcmath/tests/bcadd_error.phpt b/ext/bcmath/tests/bcadd_error.phpt
new file mode 100644 (file)
index 0000000..adb6c3c
--- /dev/null
@@ -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 (file)
index 0000000..364658d
--- /dev/null
@@ -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 (file)
index 0000000..d7ed546
--- /dev/null
@@ -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 (file)
index 0000000..71718d3
--- /dev/null
@@ -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 (file)
index 0000000..301ef11
--- /dev/null
@@ -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 (file)
index 0000000..fb71e63
--- /dev/null
@@ -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 (file)
index 0000000..9056f9e
--- /dev/null
@@ -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 (file)
index 0000000..85cefa0
--- /dev/null
@@ -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 (file)
index 0000000..0a890ef
--- /dev/null
@@ -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
index 83e633bdaf1b4db287a8a9179523b2ba8939338f..dd3499804e93efe5325de9b3ba5368b9af67ca7d 100644 (file)
@@ -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