Skip to content

Commit

Permalink
Add native union types to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Mar 27, 2024
1 parent 71d27c1 commit 6dff644
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 54 deletions.
63 changes: 30 additions & 33 deletions tests/BigDecimalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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());
}
Expand Down
28 changes: 11 additions & 17 deletions tests/BigIntegerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand All @@ -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());
}
Expand Down
8 changes: 4 additions & 4 deletions tests/BigRationalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 6dff644

Please sign in to comment.