Skip to content

Commit ec5e811

Browse files
Alex-McLeanGirgias
authored andcommitted
Add test cases for bcmath ValueErrors
Closes phpGH-6714 Signed-off-by: George Peter Banyard <[email protected]>
1 parent c316546 commit ec5e811

10 files changed

+232
-0
lines changed

ext/bcmath/tests/bcadd_error.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
bcadd() requires well-formed values
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
try {
11+
bcadd('a', '1');
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . PHP_EOL;
14+
}
15+
16+
try {
17+
bcadd('1', 'a');
18+
} catch (\ValueError $e) {
19+
echo $e->getMessage() . PHP_EOL;
20+
}
21+
22+
?>
23+
--EXPECT--
24+
bcadd(): Argument #1 ($num1) is not well-formed
25+
bcadd(): Argument #2 ($num2) is not well-formed

ext/bcmath/tests/bccomp_error.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
bccomp() requires well-formed values
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
try {
11+
bccomp('a', '1');
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . PHP_EOL;
14+
}
15+
16+
try {
17+
bccomp('1', 'a');
18+
} catch (\ValueError $e) {
19+
echo $e->getMessage() . PHP_EOL;
20+
}
21+
22+
?>
23+
--EXPECT--
24+
bccomp(): Argument #1 ($num1) is not well-formed
25+
bccomp(): Argument #2 ($num2) is not well-formed

ext/bcmath/tests/bcdiv_error2.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
bcdiv() requires well-formed values
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
try {
11+
bcdiv('a', '1');
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . PHP_EOL;
14+
}
15+
16+
try {
17+
bcdiv('1', 'a');
18+
} catch (\ValueError $e) {
19+
echo $e->getMessage() . PHP_EOL;
20+
}
21+
22+
?>
23+
--EXPECT--
24+
bcdiv(): Argument #1 ($num1) is not well-formed
25+
bcdiv(): Argument #2 ($num2) is not well-formed

ext/bcmath/tests/bcmod_error3.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
bcmod() requires well-formed values
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
try {
11+
bcmod('a', '1');
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . PHP_EOL;
14+
}
15+
16+
try {
17+
bcmod('1', 'a');
18+
} catch (\ValueError $e) {
19+
echo $e->getMessage() . PHP_EOL;
20+
}
21+
22+
?>
23+
--EXPECT--
24+
bcmod(): Argument #1 ($num1) is not well-formed
25+
bcmod(): Argument #2 ($num2) is not well-formed

ext/bcmath/tests/bcmul_error.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
bcmul() requires well-formed values
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
try {
11+
bcmul('a', '1');
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . PHP_EOL;
14+
}
15+
16+
try {
17+
bcmul('1', 'a');
18+
} catch (\ValueError $e) {
19+
echo $e->getMessage() . PHP_EOL;
20+
}
21+
22+
?>
23+
--EXPECT--
24+
bcmul(): Argument #1 ($num1) is not well-formed
25+
bcmul(): Argument #2 ($num2) is not well-formed

ext/bcmath/tests/bcpow_error3.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
bcpow() requires well-formed values
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
try {
11+
bcpow('a', '1');
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . PHP_EOL;
14+
}
15+
16+
try {
17+
bcpow('1', 'a');
18+
} catch (\ValueError $e) {
19+
echo $e->getMessage() . PHP_EOL;
20+
}
21+
22+
?>
23+
--EXPECT--
24+
bcpow(): Argument #1 ($num) is not well-formed
25+
bcpow(): Argument #2 ($exponent) is not well-formed

ext/bcmath/tests/bcpowmod_error.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
bcpowmod() requires well-formed values
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
try {
11+
bcpowmod('a', '1', '1');
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . PHP_EOL;
14+
}
15+
16+
try {
17+
bcpowmod('1', 'a', '1');
18+
} catch (\ValueError $e) {
19+
echo $e->getMessage() . PHP_EOL;
20+
}
21+
22+
try {
23+
bcpowmod('1', '1', 'a');
24+
} catch (\ValueError $e) {
25+
echo $e->getMessage() . PHP_EOL;
26+
}
27+
28+
?>
29+
--EXPECT--
30+
bcpowmod(): Argument #1 ($num) is not well-formed
31+
bcpowmod(): Argument #2 ($exponent) is not well-formed
32+
bcpowmod(): Argument #3 ($modulus) is not well-formed

ext/bcmath/tests/bcsqrt_error2.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
bcsqrt() requires a well-formed value
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
try {
11+
bcsqrt('a');
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . PHP_EOL;
14+
}
15+
16+
?>
17+
--EXPECT--
18+
bcsqrt(): Argument #1 ($num) is not well-formed

ext/bcmath/tests/bcsub_error.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
bcsub() requires well-formed values
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('bcmath')) die('skip bcmath extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
10+
try {
11+
bcsub('a', '1');
12+
} catch (\ValueError $e) {
13+
echo $e->getMessage() . PHP_EOL;
14+
}
15+
16+
try {
17+
bcsub('1', 'a');
18+
} catch (\ValueError $e) {
19+
echo $e->getMessage() . PHP_EOL;
20+
}
21+
22+
?>
23+
--EXPECT--
24+
bcsub(): Argument #1 ($num1) is not well-formed
25+
bcsub(): Argument #2 ($num2) is not well-formed

ext/bcmath/tests/str2num_formatting.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ try {
4646
echo $e->getMessage() . PHP_EOL;
4747
}
4848

49+
try {
50+
echo bcadd("1.a", "2");
51+
} catch (\ValueError $e) {
52+
echo $e->getMessage() . PHP_EOL;
53+
}
54+
4955
echo "\n";
5056

5157
echo bccomp("1", "2"),"\n";
@@ -99,6 +105,7 @@ bcadd(): Argument #1 ($num1) is not well-formed
99105
bcadd(): Argument #1 ($num1) is not well-formed
100106
bcadd(): Argument #1 ($num1) is not well-formed
101107
bcadd(): Argument #1 ($num1) is not well-formed
108+
bcadd(): Argument #1 ($num1) is not well-formed
102109

103110
-1
104111
-1

0 commit comments

Comments
 (0)