From 6dff644c3184be568d2210c2439200e43a8c2ac2 Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Wed, 27 Mar 2024 18:46:44 +0100 Subject: [PATCH] Add native union types to tests --- tests/BigDecimalTest.php | 63 +++++++++++++++++++-------------------- tests/BigIntegerTest.php | 28 +++++++---------- tests/BigRationalTest.php | 8 ++--- 3 files changed, 45 insertions(+), 54 deletions(-) diff --git a/tests/BigDecimalTest.php b/tests/BigDecimalTest.php index 999de12..b7747ed 100644 --- a/tests/BigDecimalTest.php +++ b/tests/BigDecimalTest.php @@ -19,12 +19,12 @@ class BigDecimalTest extends AbstractTestCase { /** - * @param string|number $value The value to convert to a BigDecimal. - * @param string $unscaledValue The expected unscaled value. - * @param int $scale The expected scale. + * @param int|float|string $value The value to convert to a BigDecimal. + * @param string $unscaledValue The expected unscaled value. + * @param int $scale The expected scale. */ #[DataProvider('providerOf')] - public function testOf($value, string $unscaledValue, int $scale) : void + public function testOf(int|float|string $value, string $unscaledValue, int $scale) : void { self::assertBigDecimalInternalValues($unscaledValue, $scale, BigDecimal::of($value)); } @@ -221,7 +221,7 @@ public static function providerOfFloatInDifferentLocales() : array } #[DataProvider('providerOfInvalidValueThrowsException')] - public function testOfInvalidValueThrowsException($value) : void + public function testOfInvalidValueThrowsException(int|float|string $value) : void { $this->expectException(NumberFormatException::class); BigDecimal::of($value); @@ -266,12 +266,12 @@ public function testOfBigDecimalReturnsThis() : void } /** - * @param string|int $unscaledValue The unscaled value of the BigDecimal to create. + * @param int|string $unscaledValue The unscaled value of the BigDecimal to create. * @param int $scale The scale of the BigDecimal to create. * @param string $expectedUnscaledValue The expected result unscaled value. */ #[DataProvider('providerOfUnscaledValue')] - public function testOfUnscaledValue($unscaledValue, int $scale, string $expectedUnscaledValue) : void + public function testOfUnscaledValue(int|string $unscaledValue, int $scale, string $expectedUnscaledValue) : void { $number = BigDecimal::ofUnscaledValue($unscaledValue, $scale); self::assertBigDecimalInternalValues($expectedUnscaledValue, $scale, $number); @@ -751,11 +751,8 @@ public static function providerDividedBy() : array ]; } - /** - * @param string|number $zero - */ #[DataProvider('providerDividedByByZeroThrowsException')] - public function testDividedByByZeroThrowsException($zero) : void + public function testDividedByByZeroThrowsException(int|float|string $zero) : void { $this->expectException(DivisionByZeroException::class); BigDecimal::of(1)->dividedBy($zero, 0); @@ -773,12 +770,12 @@ public static function providerDividedByByZeroThrowsException() : array } /** - * @param string|number $number The number to divide. - * @param string|number $divisor The divisor. - * @param string $expected The expected result, or a class name if an exception is expected. + * @param int|float|string $number The number to divide. + * @param int|float|string $divisor The divisor. + * @param string $expected The expected result, or a class name if an exception is expected. */ #[DataProvider('providerExactlyDividedBy')] - public function testExactlyDividedBy($number, $divisor, string $expected) : void + public function testExactlyDividedBy(int|float|string $number, int|float|string $divisor, string $expected) : void { $number = BigDecimal::of($number); @@ -2158,61 +2155,61 @@ public static function providerCompareTo() : array } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testGetSign($number, int $sign) : void + public function testGetSign(int|float|string $number, int $sign) : void { self::assertSame($sign, BigDecimal::of($number)->getSign()); } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsZero($number, int $sign) : void + public function testIsZero(int|float|string $number, int $sign) : void { self::assertSame($sign === 0, BigDecimal::of($number)->isZero()); } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsNegative($number, int $sign) : void + public function testIsNegative(int|float|string $number, int $sign) : void { self::assertSame($sign < 0, BigDecimal::of($number)->isNegative()); } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsNegativeOrZero($number, int $sign) : void + public function testIsNegativeOrZero(int|float|string $number, int $sign) : void { self::assertSame($sign <= 0, BigDecimal::of($number)->isNegativeOrZero()); } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsPositive($number, int $sign) : void + public function testIsPositive(int|float|string $number, int $sign) : void { self::assertSame($sign > 0, BigDecimal::of($number)->isPositive()); } /** - * @param number|string $number The number to test. - * @param int $sign The sign of the number. + * @param int|float|string $number The number to test. + * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsPositiveOrZero($number, int $sign) : void + public function testIsPositiveOrZero(int|float|string $number, int $sign) : void { self::assertSame($sign >= 0, BigDecimal::of($number)->isPositiveOrZero()); } diff --git a/tests/BigIntegerTest.php b/tests/BigIntegerTest.php index aab7871..3f38dec 100644 --- a/tests/BigIntegerTest.php +++ b/tests/BigIntegerTest.php @@ -22,11 +22,11 @@ class BigIntegerTest extends AbstractTestCase { /** - * @param string|number $value The value to convert to a BigInteger. - * @param string $expected The expected string value of the result. + * @param int|float|string $value The value to convert to a BigInteger. + * @param string $expected The expected string value of the result. */ #[DataProvider('providerOf')] - public function testOf($value, string $expected) : void + public function testOf(int|float|string $value, string $expected) : void { self::assertBigIntegerEquals($expected, BigInteger::of($value)); } @@ -110,11 +110,8 @@ public function testOfBigIntegerReturnsThis() : void self::assertSame($decimal, BigInteger::of($decimal)); } - /** - * @param string|number $value - */ #[DataProvider('providerOfInvalidFormatThrowsException')] - public function testOfInvalidFormatThrowsException($value) : void + public function testOfInvalidFormatThrowsException(int|float|string $value) : void { $this->expectException(NumberFormatException::class); BigInteger::of($value); @@ -138,11 +135,8 @@ public static function providerOfInvalidFormatThrowsException() : array ]; } - /** - * @param float|string $value - */ #[DataProvider('providerOfNonConvertibleValueThrowsException')] - public function testOfNonConvertibleValueThrowsException($value) : void + public function testOfNonConvertibleValueThrowsException(float|string $value) : void { $this->expectException(RoundingNecessaryException::class); BigInteger::of($value); @@ -2847,7 +2841,7 @@ public static function providerCompareTo() : array * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testGetSign($number, int $sign) : void + public function testGetSign(int|string $number, int $sign) : void { self::assertSame($sign, BigInteger::of($number)->getSign()); } @@ -2857,7 +2851,7 @@ public function testGetSign($number, int $sign) : void * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsZero($number, int $sign) : void + public function testIsZero(int|string $number, int $sign) : void { self::assertSame($sign === 0, BigInteger::of($number)->isZero()); } @@ -2867,7 +2861,7 @@ public function testIsZero($number, int $sign) : void * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsNegative($number, int $sign) : void + public function testIsNegative(int|string $number, int $sign) : void { self::assertSame($sign < 0, BigInteger::of($number)->isNegative()); } @@ -2877,7 +2871,7 @@ public function testIsNegative($number, int $sign) : void * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsNegativeOrZero($number, int $sign) : void + public function testIsNegativeOrZero(int|string $number, int $sign) : void { self::assertSame($sign <= 0, BigInteger::of($number)->isNegativeOrZero()); } @@ -2887,7 +2881,7 @@ public function testIsNegativeOrZero($number, int $sign) : void * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsPositive($number, int $sign) : void + public function testIsPositive(int|string $number, int $sign) : void { self::assertSame($sign > 0, BigInteger::of($number)->isPositive()); } @@ -2897,7 +2891,7 @@ public function testIsPositive($number, int $sign) : void * @param int $sign The sign of the number. */ #[DataProvider('providerSign')] - public function testIsPositiveOrZero($number, int $sign) : void + public function testIsPositiveOrZero(int|string $number, int $sign) : void { self::assertSame($sign >= 0, BigInteger::of($number)->isPositiveOrZero()); } diff --git a/tests/BigRationalTest.php b/tests/BigRationalTest.php index 1686510..3f9b26f 100644 --- a/tests/BigRationalTest.php +++ b/tests/BigRationalTest.php @@ -217,12 +217,12 @@ public function testSumOfZeroValuesThrowsException() : void } /** - * @param string|int $rational The rational number to test. + * @param int|string $rational The rational number to test. * @param string $quotient The expected quotient. * @param string $remainder The expected remainder. */ #[DataProvider('providerQuotientAndRemainder')] - public function testQuotientAndRemainder($rational, string $quotient, string $remainder) : void + public function testQuotientAndRemainder(int|string $rational, string $quotient, string $remainder) : void { $rational = BigRational::of($rational); @@ -810,11 +810,11 @@ public static function providerToScale() : array } /** - * @param string|int $rational The rational number to test. + * @param int|string $rational The rational number to test. * @param int $integer The expected integer value. */ #[DataProvider('providerToInt')] - public function testToInt($rational, int $integer) : void + public function testToInt(int|string $rational, int $integer) : void { self::assertSame($integer, BigRational::of($rational)->toInt()); }