diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 93a9635..bb0cbe0 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
- uses: actions/checkout@v3
+ uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
@@ -24,4 +24,4 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
- php-version: ['8.1', '8.2', '8.3']
\ No newline at end of file
+ php-version: ['8.1', '8.2', '8.3']
diff --git a/composer.json b/composer.json
index 974fde1..93590b4 100644
--- a/composer.json
+++ b/composer.json
@@ -26,7 +26,7 @@
"phpseclib/phpseclib": "dev-master"
},
"require-dev": {
- "phpunit/phpunit": "^4.8.35|^5.7|^6.0|^9.4",
+ "phpunit/phpunit": "^10.5|^11.1",
"squizlabs/php_codesniffer": "^3.0"
},
"suggest": {
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 84b893a..861a130 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,20 +1,20 @@
-
-
- tests/
-
-
-
-
-
- lib/
-
-
-
\ No newline at end of file
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd"
+ backupGlobals="false"
+ colors="true"
+ bootstrap="vendor/autoload.php"
+ cacheDirectory=".phpunit.cache"
+ >
+
+
+ tests/
+
+
+
+
diff --git a/src/BCMath.php b/src/BCMath.php
index f793c6e..10a317f 100644
--- a/src/BCMath.php
+++ b/src/BCMath.php
@@ -363,12 +363,13 @@ public static function __callStatic($name, $arguments)
'sqrt' => 2,
'sub' => 3
];
- if (count($arguments) < $params[$name] - 1) {
+ $cnt = count($arguments);
+ if ($cnt < $params[$name] - 1) {
$min = $params[$name] - 1;
- throw new \ArgumentCountError("bc$name() expects at least $min parameters, " . func_num_args() . " given");
+ throw new \ArgumentCountError("bc$name() expects at least $min parameters, " . $cnt . " given");
}
- if (count($arguments) > $params[$name]) {
- $str = "bc$name() expects at most {$params[$name]} parameters, " . func_num_args() . " given";
+ if ($cnt > $params[$name]) {
+ $str = "bc$name() expects at most {$params[$name]} parameters, " . $cnt . " given";
throw new \ArgumentCountError($str);
}
$numbers = array_slice($arguments, 0, $params[$name] - 1);
diff --git a/tests/BCMathTest.php b/tests/BCMathTest.php
index ff8e884..75ed104 100644
--- a/tests/BCMathTest.php
+++ b/tests/BCMathTest.php
@@ -1,18 +1,26 @@
-assertSame($a, $b);
}
- /**
- * @dataProvider generateTwoParams
- */
+ #[DataProvider('generateTwoParams')]
public function testSub(...$params)
{
$a = bcsub(...$params);
@@ -76,9 +80,11 @@ public function testSub(...$params)
}
/**
- * @dataProvider generateTwoParams
- * @requires PHP 7.3
+ * requires PHP 7.3
*/
+
+ #[RequiresPhp('>7.3')]
+ #[DataProvider('generateTwoParams')]
public function testMul(...$params)
{
$a = bcmul(...$params);
@@ -91,9 +97,7 @@ public function testMul(...$params)
$this->assertSame($a, $b);
}
- /**
- * @dataProvider generateTwoParams
- */
+ #[DataProvider('generateTwoParams')]
public function testDiv(...$params)
{
if ($params[1] === '0' || $params[1] === '-0') {
@@ -110,9 +114,12 @@ public function testDiv(...$params)
}
/**
- * @dataProvider generateTwoParams
- * @requires PHP 7.2
+ * dataProvider generateTwoParams
+ * requires PHP 7.2
*/
+
+ #[DataProvider('generateTwoParams')]
+ #[RequiresPhp('>7.2')]
public function testMod(...$params)
{
if ($params[1] === '0' || $params[1] === '-0') {
@@ -133,7 +140,7 @@ public function testMod(...$params)
*
* @return array
*/
- public function generatePowParams()
+ public static function generatePowParams()
{
return [
['9', '9'],
@@ -154,8 +161,10 @@ public function generatePowParams()
/**
* @dataProvider generatePowParams
- * @requires PHP 7.3
+ * requires PHP 7.3
*/
+ #[DataProvider('generatePowParams')]
+ #[RequiresPhp('>7.3')]
public function testPow(...$params)
{
$a = bcpow(...$params);
@@ -168,7 +177,7 @@ public function testPow(...$params)
*
* @return array
*/
- public function generatePowModParams()
+ public static function generatePowModParams()
{
return [
['9', '9', '17'],
@@ -188,10 +197,13 @@ public function generatePowModParams()
}
/**
- * @dataProvider generatePowModParams
- * @requires PHP 7.3
+ * dataProvider generatePowModParams
+ * requires PHP 7.3
*/
- public function testPowMod(...$params)
+ #[DataProvider('generatePowModParams')]
+ #[RequiresPhp('>7.3')]
+
+ public function testPowMod(...$params)
{
$a = bcpowmod(...$params);
$b = BCMath::powmod(...$params);
@@ -215,9 +227,19 @@ public function testSqrt()
public function testBoolScale()
{
- $a = bcadd('5', '2', false);
- $b = BCMath::add('5', '2', false);
- $this->assertSame($a, $b);
+ if(false) {
+ $exception_thrown = false;
+ try {
+ $a = bcadd('5', '2', false);
+ } catch (TypeError $e) {
+ $exception_thrown = true;
+ }
+ $this->assertSame(true, $exception_thrown);
+ } else {
+ $a = bcadd('5','2', false);
+ $b = BCMath::add('5', '2', false);
+ $this->assertSame($a, $b);
+ }
}
public function testIntParam()
@@ -246,4 +268,75 @@ public function setExpectedException($name, $message = null, $code = null)
$this->expectExceptionCode($code);
}
}
+
+ public static function generateScaleCallstaticParams()
+ {
+ return [
+ [4],
+ [4,2],
+ [4,2,3],
+ [4,2,3,5],
+ ];
+ }
+
+ #[DataProvider('generateScaleCallstaticParams')]
+ public function test_argumentsScaleCallstatic(...$params)
+ {
+ //scale with 1, 2, 3 parameters
+ if (func_num_args() == 1) {
+ bcscale(...$params);
+ BCMath::scale(...$params);
+ $scale = bcscale();
+ $orig = $params[0];
+ $this->assertSame($orig,$scale);
+ $scale = BCMath::scale();
+ $this->assertSame($orig,$scale);
+ } else {
+ $exception_thrown = false;
+ try{
+ BCMath::scale(...$params);
+ } catch (ArgumentCountError $e) {
+ $exception_thrown = true;
+ }
+ $this->assertSame(true, $exception_thrown);
+ if (true) {
+ // start the unit test with: (showing the wrong given values)
+ // phpunit --testdox-test testdox.txt --display-skipped
+ $this->markTestSkipped('ArgumentCountError in ' . $e->getFile() . ':' . $e->getLine() . ' : ' . $e->getMessage());
+ }
+ }
+ }
+ public static function generatePowModCallstaticParams()
+ {
+ return [
+ ['9'],
+ ['9', '17'],
+ ['9', '17', '-111'],
+ ['9', '17', '-111', 5],
+ ['9', '17', '-111', 5, 8],
+ ];
+ }
+ #[DataProvider('generatePowModCallstaticParams')]
+ public function test_argumentsPowModCallstatic(...$params)
+ {
+ //scale with 1, 2, 3 parameters
+ if (func_num_args() > 2 && func_num_args() < 5) {
+ $a = bcpowmod(...$params);
+ $b = BCMath::powmod(...$params);
+ $this->assertSame($a,$b);
+ } else {
+ $exception_thrown = false;
+ try{
+ BCMath::powmod(...$params);
+ } catch (ArgumentCountError $e) {
+ $exception_thrown = true;
+ }
+ $this->assertSame(true, $exception_thrown);
+ if (true) {
+ // start the unit test with: (showing the wrong given values)
+ // phpunit --testdox-test testdox.txt --display-skipped
+ $this->markTestSkipped('ArgumentCountError in ' . $e->getFile() . ':' . $e->getLine() . ' : ' . $e->getMessage());
+ }
+ }
+ }
}
\ No newline at end of file