diff --git a/tests/Context/AutoContextTest.php b/tests/Context/AutoContextTest.php index b9d8b47..077f864 100644 --- a/tests/Context/AutoContextTest.php +++ b/tests/Context/AutoContextTest.php @@ -4,23 +4,21 @@ namespace Brick\Money\Tests\Context; +use Brick\Math\BigNumber; use Brick\Math\Exception\RoundingNecessaryException; use Brick\Math\RoundingMode; -use Brick\Money\Context\CashContext; use Brick\Money\Context\AutoContext; +use Brick\Money\Context\CashContext; use Brick\Money\Currency; use Brick\Money\Tests\AbstractTestCase; - -use Brick\Math\BigNumber; +use PHPUnit\Framework\Attributes\DataProvider; /** * Tests for class AutoContext. */ class AutoContextTest extends AbstractTestCase { - /** - * @dataProvider providerApplyTo - */ + #[DataProvider('providerApplyTo')] public function testApplyTo(string $amount, string $currency, RoundingMode $roundingMode, string $expected) : void { $amount = BigNumber::of($amount); diff --git a/tests/Context/CashContextTest.php b/tests/Context/CashContextTest.php index 09d661c..f6a36ea 100644 --- a/tests/Context/CashContextTest.php +++ b/tests/Context/CashContextTest.php @@ -4,22 +4,20 @@ namespace Brick\Money\Tests\Context; +use Brick\Math\BigNumber; use Brick\Math\Exception\RoundingNecessaryException; use Brick\Math\RoundingMode; use Brick\Money\Context\CashContext; use Brick\Money\Currency; use Brick\Money\Tests\AbstractTestCase; - -use Brick\Math\BigNumber; +use PHPUnit\Framework\Attributes\DataProvider; /** * Tests for class CashContext. */ class CashContextTest extends AbstractTestCase { - /** - * @dataProvider providerApplyTo - */ + #[DataProvider('providerApplyTo')] public function testApplyTo(int $step, string $amount, string $currency, RoundingMode $roundingMode, string $expected) : void { $amount = BigNumber::of($amount); diff --git a/tests/Context/CustomContextTest.php b/tests/Context/CustomContextTest.php index 4227252..da0b5e6 100644 --- a/tests/Context/CustomContextTest.php +++ b/tests/Context/CustomContextTest.php @@ -4,22 +4,20 @@ namespace Brick\Money\Tests\Context; +use Brick\Math\BigNumber; use Brick\Math\Exception\RoundingNecessaryException; use Brick\Math\RoundingMode; use Brick\Money\Context\CustomContext; use Brick\Money\Currency; use Brick\Money\Tests\AbstractTestCase; - -use Brick\Math\BigNumber; +use PHPUnit\Framework\Attributes\DataProvider; /** * Tests for class CustomContext. */ class CustomContextTest extends AbstractTestCase { - /** - * @dataProvider providerApplyTo - */ + #[DataProvider('providerApplyTo')] public function testApplyTo(int $scale, int $step, string $amount, string $currency, RoundingMode $roundingMode, string $expected) : void { $amount = BigNumber::of($amount); diff --git a/tests/Context/DefaultContextTest.php b/tests/Context/DefaultContextTest.php index 9a0c2fe..8a0f00e 100644 --- a/tests/Context/DefaultContextTest.php +++ b/tests/Context/DefaultContextTest.php @@ -4,22 +4,20 @@ namespace Brick\Money\Tests\Context; +use Brick\Math\BigNumber; use Brick\Math\Exception\RoundingNecessaryException; use Brick\Math\RoundingMode; use Brick\Money\Context\DefaultContext; use Brick\Money\Currency; use Brick\Money\Tests\AbstractTestCase; - -use Brick\Math\BigNumber; +use PHPUnit\Framework\Attributes\DataProvider; /** * Tests for class DefaultContext. */ class DefaultContextTest extends AbstractTestCase { - /** - * @dataProvider providerApplyTo - */ + #[DataProvider('providerApplyTo')] public function testApplyTo(string $amount, string $currency, RoundingMode $roundingMode, string $expected) : void { $amount = BigNumber::of($amount); diff --git a/tests/CurrencyConverterTest.php b/tests/CurrencyConverterTest.php index 060f5b6..00758d3 100644 --- a/tests/CurrencyConverterTest.php +++ b/tests/CurrencyConverterTest.php @@ -4,19 +4,19 @@ namespace Brick\Money\Tests; +use Brick\Math\Exception\RoundingNecessaryException; +use Brick\Math\RoundingMode; use Brick\Money\Context; -use Brick\Money\Context\DefaultContext; use Brick\Money\Context\AutoContext; use Brick\Money\Context\CustomContext; +use Brick\Money\Context\DefaultContext; use Brick\Money\CurrencyConverter; use Brick\Money\Exception\CurrencyConversionException; use Brick\Money\ExchangeRateProvider\ConfigurableProvider; use Brick\Money\Money; use Brick\Money\MoneyBag; - -use Brick\Math\Exception\RoundingNecessaryException; -use Brick\Math\RoundingMode; use Brick\Money\RationalMoney; +use PHPUnit\Framework\Attributes\DataProvider; /** * Tests for class CurrencyConverter. @@ -34,13 +34,12 @@ private function createCurrencyConverter() : CurrencyConverter } /** - * @dataProvider providerConvertMoney - * * @param array $money The base money. * @param string $toCurrency The currency code to convert to. * @param RoundingMode $roundingMode The rounding mode to use. * @param string $expectedResult The expected money's string representation, or an exception class name. */ + #[DataProvider('providerConvertMoney')] public function testConvertMoney(array $money, string $toCurrency, RoundingMode $roundingMode, string $expectedResult) : void { $money = Money::of(...$money); @@ -76,14 +75,13 @@ public static function providerConvertMoney() : array } /** - * @dataProvider providerConvertMoneyBag - * * @param array $monies The mixed currency monies to add. * @param string $currency The target currency code. * @param Context $context The target context. * @param RoundingMode $roundingMode The rounding mode to use. * @param string $total The expected total. */ + #[DataProvider('providerConvertMoneyBag')] public function testConvertMoneyBag(array $monies, string $currency, Context $context, RoundingMode $roundingMode, string $total) : void { $exchangeRateProvider = new ConfigurableProvider(); @@ -113,12 +111,11 @@ public static function providerConvertMoneyBag() : array } /** - * @dataProvider providerConvertMoneyBagToRational - * * @param array $monies The mixed monies to add. * @param string $currency The target currency code. * @param string $expectedTotal The expected total. */ + #[DataProvider('providerConvertMoneyBagToRational')] public function testConvertMoneyBagToRational(array $monies, string $currency, string $expectedTotal) : void { $exchangeRateProvider = new ConfigurableProvider(); @@ -147,13 +144,12 @@ public static function providerConvertMoneyBagToRational() : array } /** - * @dataProvider providerConvertRationalMoney - * * @param array $money The original amount and currency. * @param string $toCurrency The currency code to convert to. * @param RoundingMode $roundingMode The rounding mode to use. * @param string $expectedResult The expected money's string representation, or an exception class name. */ + #[DataProvider('providerConvertRationalMoney')] public function testConvertRationalMoney(array $money, string $toCurrency, RoundingMode $roundingMode, string $expectedResult) : void { $currencyConverter = $this->createCurrencyConverter(); diff --git a/tests/CurrencyTest.php b/tests/CurrencyTest.php index f223139..c040dff 100644 --- a/tests/CurrencyTest.php +++ b/tests/CurrencyTest.php @@ -6,6 +6,7 @@ use Brick\Money\Currency; use Brick\Money\Exception\UnknownCurrencyException; +use PHPUnit\Framework\Attributes\DataProvider; /** * Unit tests for class Currency. @@ -13,13 +14,12 @@ class CurrencyTest extends AbstractTestCase { /** - * @dataProvider providerOf - * * @param string $currencyCode The currency code. * @param int $numericCode The currency's numeric code. * @param int $fractionDigits The currency's default fraction digits. * @param string $name The currency's name. */ + #[DataProvider('providerOf')] public function testOf(string $currencyCode, int $numericCode, int $fractionDigits, string $name) : void { $currency = Currency::of($currencyCode); @@ -40,9 +40,7 @@ public static function providerOf() : array ]; } - /** - * @dataProvider providerOfUnknownCurrencyCode - */ + #[DataProvider('providerOfUnknownCurrencyCode')] public function testOfUnknownCurrencyCode(string|int $currencyCode) : void { $this->expectException(UnknownCurrencyException::class); @@ -68,9 +66,7 @@ public function testOfReturnsSameInstance() : void self::assertSame(Currency::of('EUR'), Currency::of('EUR')); } - /** - * @dataProvider providerOfCountry - */ + #[DataProvider('providerOfCountry')] public function testOfCountry(string $countryCode, string $expected) : void { if ($this->isExceptionClass($expected)) { @@ -124,9 +120,7 @@ public function testIs() : void self::assertTrue($clone->is($currency)); } - /** - * @dataProvider providerJsonSerialize - */ + #[DataProvider('providerJsonSerialize')] public function testJsonSerialize(Currency $currency, string $expected): void { self::assertSame($expected, $currency->jsonSerialize()); diff --git a/tests/ExchangeRateProvider/BaseCurrencyProviderTest.php b/tests/ExchangeRateProvider/BaseCurrencyProviderTest.php index c4eca94..ed188af 100644 --- a/tests/ExchangeRateProvider/BaseCurrencyProviderTest.php +++ b/tests/ExchangeRateProvider/BaseCurrencyProviderTest.php @@ -5,13 +5,12 @@ namespace Brick\Money\Tests\ExchangeRateProvider; use Brick\Math\BigNumber; +use Brick\Math\RoundingMode; use Brick\Money\ExchangeRateProvider; use Brick\Money\ExchangeRateProvider\BaseCurrencyProvider; use Brick\Money\ExchangeRateProvider\ConfigurableProvider; use Brick\Money\Tests\AbstractTestCase; - -use Brick\Math\BigRational; -use Brick\Math\RoundingMode; +use PHPUnit\Framework\Attributes\DataProvider; /** * Tests for class BaseCurrencyProvider. @@ -30,12 +29,11 @@ private function getExchangeRateProvider() : ExchangeRateProvider } /** - * @dataProvider providerGetExchangeRate - * * @param string $sourceCurrencyCode The code of the source currency. * @param string $targetCurrencyCode The code of the target currency. * @param string $exchangeRate The expected exchange rate, rounded DOWN to 6 decimals. */ + #[DataProvider('providerGetExchangeRate')] public function testGetExchangeRate(string $sourceCurrencyCode, string $targetCurrencyCode, string $exchangeRate) : void { $rate = $this->getExchangeRateProvider()->getExchangeRate($sourceCurrencyCode, $targetCurrencyCode); @@ -62,9 +60,7 @@ public static function providerGetExchangeRate() : array ]; } - /** - * @dataProvider providerReturnBigNumber - */ + #[DataProvider('providerReturnBigNumber')] public function testReturnBigNumber(BigNumber|float|int|string $rate) : void { $configurableProvider = new ConfigurableProvider(); diff --git a/tests/ExchangeRateProvider/ConfigurableProviderTest.php b/tests/ExchangeRateProvider/ConfigurableProviderTest.php index 2a6fef5..6fc1a9e 100644 --- a/tests/ExchangeRateProvider/ConfigurableProviderTest.php +++ b/tests/ExchangeRateProvider/ConfigurableProviderTest.php @@ -4,13 +4,13 @@ namespace Brick\Money\Tests\ExchangeRateProvider; +use Brick\Math\BigRational; +use Brick\Math\RoundingMode; use Brick\Money\Exception\CurrencyConversionException; use Brick\Money\ExchangeRateProvider; use Brick\Money\ExchangeRateProvider\ConfigurableProvider; use Brick\Money\Tests\AbstractTestCase; - -use Brick\Math\BigRational; -use Brick\Math\RoundingMode; +use PHPUnit\Framework\Attributes\DataProvider; /** * Tests for class ConfigurableProvider. @@ -29,12 +29,11 @@ private function getExchangeRateProvider() : ExchangeRateProvider } /** - * @dataProvider providerGetExchangeRate - * * @param string $sourceCurrencyCode The code of the source currency. * @param string $targetCurrencyCode The code of the target currency. * @param string $exchangeRate The expected exchange rate, rounded DOWN to 3 decimals. */ + #[DataProvider('providerGetExchangeRate')] public function testGetExchangeRate(string $sourceCurrencyCode, string $targetCurrencyCode, string $exchangeRate) : void { $rate = $this->getExchangeRateProvider()->getExchangeRate($sourceCurrencyCode, $targetCurrencyCode); diff --git a/tests/ExchangeRateProvider/PDOProviderTest.php b/tests/ExchangeRateProvider/PDOProviderTest.php index d5e8aca..c4faacf 100644 --- a/tests/ExchangeRateProvider/PDOProviderTest.php +++ b/tests/ExchangeRateProvider/PDOProviderTest.php @@ -9,19 +9,19 @@ use Brick\Money\ExchangeRateProvider\PDOProviderConfiguration; use Brick\Money\Tests\AbstractTestCase; use Closure; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** * Tests for class PDOProvider. - * - * @requires extension pdo_sqlite */ +#[RequiresPhpExtension('pdo_sqlite')] class PDOProviderTest extends AbstractTestCase { /** - * @dataProvider providerConstructorWithInvalidConfiguration - * * @param Closure(): PDOProviderConfiguration $getConfiguration */ + #[DataProvider('providerConstructorWithInvalidConfiguration')] public function testConfigurationConstructorThrows(Closure $getConfiguration, string $exceptionMessage) : void { $this->expectException(\InvalidArgumentException::class); @@ -67,12 +67,11 @@ public static function providerConstructorWithInvalidConfiguration() : array } /** - * @dataProvider providerGetExchangeRate - * * @param string $sourceCurrencyCode The code of the source currency. * @param string $targetCurrencyCode The code of the target currency. * @param float|string $expectedResult The expected exchange rate, or an exception class if expected. */ + #[DataProvider('providerGetExchangeRate')] public function testGetExchangeRate(string $sourceCurrencyCode, string $targetCurrencyCode, float|string $expectedResult) : void { $pdo = new \PDO('sqlite::memory:'); @@ -123,12 +122,11 @@ public static function providerGetExchangeRate() : array } /** - * @dataProvider providerWithFixedSourceCurrency - * * @param string $sourceCurrencyCode The code of the source currency. * @param string $targetCurrencyCode The code of the target currency. * @param float|string $expectedResult The expected exchange rate, or an exception class if expected. */ + #[DataProvider('providerWithFixedSourceCurrency')] public function testWithFixedSourceCurrency(string $sourceCurrencyCode, string $targetCurrencyCode, float|string $expectedResult) : void { $pdo = new \PDO('sqlite::memory:'); @@ -177,12 +175,11 @@ public static function providerWithFixedSourceCurrency() : array } /** - * @dataProvider providerWithFixedTargetCurrency - * * @param string $sourceCurrencyCode The code of the source currency. * @param string $targetCurrencyCode The code of the target currency. * @param float|string $expectedResult The expected exchange rate, or an exception class if expected. */ + #[DataProvider('providerWithFixedTargetCurrency')] public function testWithFixedTargetCurrency(string $sourceCurrencyCode, string $targetCurrencyCode, float|string $expectedResult) : void { $pdo = new \PDO('sqlite::memory:'); @@ -231,13 +228,12 @@ public static function providerWithFixedTargetCurrency() : array } /** - * @dataProvider providerWithParameters - * * @param string $sourceCurrencyCode The code of the source currency. * @param string $targetCurrencyCode The code of the target currency. * @param array $parameters The parameters to resolve the extra query placeholders. * @param float|string $expectedResult The expected exchange rate, or an exception class if expected. */ + #[DataProvider('providerWithParameters')] public function testWithParameters(string $sourceCurrencyCode, string $targetCurrencyCode, array $parameters, float|string $expectedResult) : void { $pdo = new \PDO('sqlite::memory:'); diff --git a/tests/ExchangeRateProvider/ProviderChainTest.php b/tests/ExchangeRateProvider/ProviderChainTest.php index 8cbcec5..7e21db2 100644 --- a/tests/ExchangeRateProvider/ProviderChainTest.php +++ b/tests/ExchangeRateProvider/ProviderChainTest.php @@ -9,6 +9,7 @@ use Brick\Money\ExchangeRateProvider\ConfigurableProvider; use Brick\Money\ExchangeRateProvider\ProviderChain; use Brick\Money\Tests\AbstractTestCase; +use PHPUnit\Framework\Attributes\Depends; /** * Tests for class ProviderChain. @@ -53,9 +54,7 @@ public function testAddFirstProvider() : ProviderChain return $provider; } - /** - * @depends testAddFirstProvider - */ + #[Depends('testAddFirstProvider')] public function testAddSecondProvider(ProviderChain $provider) : ProviderChain { $provider->addExchangeRateProvider(self::$provider2); @@ -67,9 +66,7 @@ public function testAddSecondProvider(ProviderChain $provider) : ProviderChain return $provider; } - /** - * @depends testAddSecondProvider - */ + #[Depends('testAddSecondProvider')] public function testRemoveProvider(ProviderChain $provider) : void { $provider->removeExchangeRateProvider(self::$provider1); diff --git a/tests/ISOCurrencyProviderTest.php b/tests/ISOCurrencyProviderTest.php index 09700c9..05890ef 100644 --- a/tests/ISOCurrencyProviderTest.php +++ b/tests/ISOCurrencyProviderTest.php @@ -7,6 +7,7 @@ use Brick\Money\Currency; use Brick\Money\Exception\UnknownCurrencyException; use Brick\Money\ISOCurrencyProvider; +use PHPUnit\Framework\Attributes\DataProvider; /** * Tests for class ISOCurrencyProvider. @@ -27,9 +28,7 @@ public static function setUpBeforeClass() : void $reflection->setValue(null); } - /** - * @dataProvider providerGetCurrency - */ + #[DataProvider('providerGetCurrency')] public function testGetCurrency(string $currencyCode, int $numericCode, string $name, int $defaultFractionDigits) : void { $provider = ISOCurrencyProvider::getInstance(); @@ -57,9 +56,7 @@ public static function providerGetCurrency() : array ]; } - /** - * @dataProvider providerUnknownCurrency - */ + #[DataProvider('providerUnknownCurrency')] public function testGetUnknownCurrency(string|int $currencyCode) : void { $this->expectException(UnknownCurrencyException::class); diff --git a/tests/MoneyBagTest.php b/tests/MoneyBagTest.php index b3a4425..815a7ae 100644 --- a/tests/MoneyBagTest.php +++ b/tests/MoneyBagTest.php @@ -9,6 +9,7 @@ use Brick\Money\Money; use Brick\Money\MoneyBag; use Brick\Money\RationalMoney; +use PHPUnit\Framework\Attributes\Depends; /** * Tests for class MoneyBag. @@ -51,9 +52,7 @@ public function testAddSubtractMoney() : MoneyBag return $moneyBag; } - /** - * @depends testAddSubtractMoney - */ + #[Depends('testAddSubtractMoney')] public function testAddCustomCurrency(MoneyBag $moneyBag) : void { $moneyBag->add(Money::of('0.1234', new Currency('BTC', 0, 'Bitcoin', 8))); diff --git a/tests/MoneyComparatorTest.php b/tests/MoneyComparatorTest.php index fd909d7..16c1642 100644 --- a/tests/MoneyComparatorTest.php +++ b/tests/MoneyComparatorTest.php @@ -9,6 +9,7 @@ use Brick\Money\ExchangeRateProvider\ConfigurableProvider; use Brick\Money\Money; use Brick\Money\MoneyComparator; +use PHPUnit\Framework\Attributes\DataProvider; /** * Tests for class MoneyComparator. @@ -32,12 +33,11 @@ private function getExchangeRateProvider() : ConfigurableProvider } /** - * @dataProvider providerCompare - * * @param array $a The money to compare. * @param array $b The money to compare to. * @param int|string $cmp The expected comparison value, or an exception class. */ + #[DataProvider('providerCompare')] public function testCompare(array $a, array $b, int|string $cmp) : void { $comparator = new MoneyComparator($this->getExchangeRateProvider()); @@ -86,11 +86,10 @@ public static function providerCompare() : array } /** - * @dataProvider providerMin - * * @param array $monies The monies to compare. * @param string $expectedMin The expected minimum money, or an exception class. */ + #[DataProvider('providerMin')] public function testMin(array $monies, string $expectedMin) : void { $comparator = new MoneyComparator($this->getExchangeRateProvider()); @@ -124,11 +123,10 @@ public static function providerMin() : array } /** - * @dataProvider providerMax - * * @param array $monies The monies to compare. * @param string $expectedMin The expected maximum money, or an exception class. */ + #[DataProvider('providerMax')] public function testMax(array $monies, string $expectedMin) : void { $comparator = new MoneyComparator($this->getExchangeRateProvider()); diff --git a/tests/MoneyTest.php b/tests/MoneyTest.php index 7563c39..fef317c 100644 --- a/tests/MoneyTest.php +++ b/tests/MoneyTest.php @@ -4,22 +4,23 @@ namespace Brick\Money\Tests; -use Brick\Money\Currency; -use Brick\Money\Exception\MoneyMismatchException; -use Brick\Money\Money; -use Brick\Money\Context; -use Brick\Money\Context\CashContext; -use Brick\Money\Context\DefaultContext; -use Brick\Money\Context\AutoContext; -use Brick\Money\Context\CustomContext; - use Brick\Math\BigDecimal; use Brick\Math\BigInteger; use Brick\Math\BigRational; -use Brick\Math\RoundingMode; use Brick\Math\Exception\DivisionByZeroException; use Brick\Math\Exception\NumberFormatException; use Brick\Math\Exception\RoundingNecessaryException; +use Brick\Math\RoundingMode; +use Brick\Money\Context; +use Brick\Money\Context\AutoContext; +use Brick\Money\Context\CashContext; +use Brick\Money\Context\CustomContext; +use Brick\Money\Context\DefaultContext; +use Brick\Money\Currency; +use Brick\Money\Exception\MoneyMismatchException; +use Brick\Money\Money; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; /** * Unit tests for class Money. @@ -27,11 +28,10 @@ class MoneyTest extends AbstractTestCase { /** - * @dataProvider providerOf - * * @param string $expectedResult The resulting money as a string, or an exception class. * @param mixed ...$args The arguments to the of() method. */ + #[DataProvider('providerOf')] public function testOf(string $expectedResult, mixed ...$args) : void { if ($this->isExceptionClass($expectedResult)) { @@ -63,11 +63,10 @@ public static function providerOf() : array } /** - * @dataProvider providerOfMinor - * * @param string $expectedResult The resulting money as a string, or an exception class. * @param mixed ...$args The arguments to the ofMinor() method. */ + #[DataProvider('providerOfMinor')] public function testOfMinor(string $expectedResult, mixed ...$args) : void { if ($this->isExceptionClass($expectedResult)) { @@ -93,9 +92,7 @@ public static function providerOfMinor() : array ]; } - /** - * @dataProvider providerZero - */ + #[DataProvider('providerZero')] public function testZero(string $currency, ?Context $context, string $expected) : void { $actual = Money::zero($currency, $context); @@ -113,9 +110,7 @@ public static function providerZero() : array ]; } - /** - * @dataProvider providerTo - */ + #[DataProvider('providerTo')] public function testTo(array $money, Context $context, RoundingMode $roundingMode, string $expected) : void { $money = Money::of(...$money); @@ -148,13 +143,12 @@ public static function providerTo() : array } /** - * @dataProvider providerPlus - * * @param array $money The base money. * @param mixed $plus The amount to add. * @param RoundingMode $roundingMode The rounding mode to use. * @param string $expected The expected money value, or an exception class name. */ + #[DataProvider('providerPlus')] public function testPlus(array $money, mixed $plus, RoundingMode $roundingMode, string $expected) : void { $money = Money::of(...$money); @@ -206,13 +200,12 @@ public function testPlusDifferentContextThrowsException() : void } /** - * @dataProvider providerMinus - * * @param array $money The base money. * @param mixed $minus The amount to subtract. * @param RoundingMode $roundingMode The rounding mode to use. * @param string $expected The expected money value, or an exception class name. */ + #[DataProvider('providerMinus')] public function testMinus(array $money, mixed $minus, RoundingMode $roundingMode, string $expected) : void { $money = Money::of(...$money); @@ -250,13 +243,12 @@ public static function providerMinus() : array } /** - * @dataProvider providerMultipliedBy - * * @param array $money The base money. * @param Money|int|float|string $multiplier The multiplier. * @param RoundingMode $roundingMode The rounding mode to use. * @param string $expected The expected money value, or an exception class name. */ + #[DataProvider('providerMultipliedBy')] public function testMultipliedBy(array $money, Money|int|float|string $multiplier, RoundingMode $roundingMode, string $expected) : void { $money = Money::of(...$money); @@ -289,13 +281,12 @@ public static function providerMultipliedBy() : array } /** - * @dataProvider providerDividedBy - * * @param array $money The base money. * @param int|float|string $divisor The divisor. * @param RoundingMode $roundingMode The rounding mode to use. * @param string $expected The expected money value, or an exception class name. */ + #[DataProvider('providerDividedBy')] public function testDividedBy(array $money, int|float|string $divisor, RoundingMode $roundingMode, string $expected) : void { $money = Money::of(...$money); @@ -329,9 +320,7 @@ public static function providerDividedBy() : array ]; } - /** - * @dataProvider providerQuotientAndRemainder - */ + #[DataProvider('providerQuotientAndRemainder')] public function testQuotientAndRemainder(array $money, int $divisor, string $expectedQuotient, string $expectedRemainder) : void { $money = Money::of(...$money); @@ -359,9 +348,7 @@ public function testQuotientAndRemainderThrowExceptionOnDecimal() : void $money->quotientAndRemainder('1.1'); } - /** - * @dataProvider providerAllocate - */ + #[DataProvider('providerAllocate')] public function testAllocate(array $money, array $ratios, array $expected) : void { $money = Money::of(...$money); @@ -416,9 +403,7 @@ public function testAllocateZeroRatios() : void $money->allocate(0, 0, 0, 0, 0); } - /** - * @dataProvider providerAllocateWithRemainder - */ + #[DataProvider('providerAllocateWithRemainder')] public function testAllocateWithRemainder(array $money, array $ratios, array $expected) : void { $money = Money::of(...$money); @@ -473,9 +458,7 @@ public function testAllocateWithRemainderZeroRatios() : void $money->allocateWithRemainder(0, 0, 0, 0, 0); } - /** - * @dataProvider providerSplit - */ + #[DataProvider('providerSplit')] public function testSplit(array $money, int $targets, array $expected) : void { $money = Money::of(...$money); @@ -497,9 +480,7 @@ public static function providerSplit() : array ]; } - /** - * @dataProvider providerSplitWithRemainder - */ + #[DataProvider('providerSplitWithRemainder')] public function testSplitWithRemainder(array $money, int $targets, array $expected) : void { $money = Money::of(...$money); @@ -521,9 +502,7 @@ public static function providerSplitWithRemainder() : array ]; } - /** - * @dataProvider providerSplitIntoLessThanOnePart - */ + #[DataProvider('providerSplitIntoLessThanOnePart')] public function testSplitIntoLessThanOnePart(int $parts) : void { $money = Money::of(50, 'USD'); @@ -542,9 +521,7 @@ public static function providerSplitIntoLessThanOnePart() : array ]; } - /** - * @dataProvider providerSplitWithRemainderIntoLessThanOnePart - */ + #[DataProvider('providerSplitWithRemainderIntoLessThanOnePart')] public function testSplitWithRemainderIntoLessThanOnePart(int $parts) : void { $money = Money::of(50, 'USD'); @@ -564,9 +541,7 @@ public static function providerSplitWithRemainderIntoLessThanOnePart() : array } - /** - * @dataProvider providerAbs - */ + #[DataProvider('providerAbs')] public function testAbs(array $money, string $abs) : void { $this->assertMoneyIs($abs, Money::of(...$money)->abs()); @@ -581,9 +556,7 @@ public static function providerAbs() : array ]; } - /** - * @dataProvider providerNegated - */ + #[DataProvider('providerNegated')] public function testNegated(array $money, string $negated) : void { $this->assertMoneyIs($negated, Money::of(...$money)->negated()); @@ -597,49 +570,37 @@ public static function providerNegated() : array ]; } - /** - * @dataProvider providerSign - */ + #[DataProvider('providerSign')] public function testGetSign(array $money, int $sign) : void { self::assertSame($sign, Money::of(...$money)->getSign()); } - /** - * @dataProvider providerSign - */ + #[DataProvider('providerSign')] public function testIsZero(array $money, int $sign) : void { self::assertSame($sign === 0, Money::of(...$money)->isZero()); } - /** - * @dataProvider providerSign - */ + #[DataProvider('providerSign')] public function testIsPositive(array $money, int $sign) : void { self::assertSame($sign > 0, Money::of(...$money)->isPositive()); } - /** - * @dataProvider providerSign - */ + #[DataProvider('providerSign')] public function testIsPositiveOrZero(array $money, int $sign) : void { self::assertSame($sign >= 0, Money::of(...$money)->isPositiveOrZero()); } - /** - * @dataProvider providerSign - */ + #[DataProvider('providerSign')] public function testIsNegative(array $money, int $sign) : void { self::assertSame($sign < 0, Money::of(...$money)->isNegative()); } - /** - * @dataProvider providerSign - */ + #[DataProvider('providerSign')] public function testIsNegativeOrZero(array $money, int $sign) : void { self::assertSame($sign <= 0, Money::of(...$money)->isNegativeOrZero()); @@ -668,12 +629,11 @@ public static function providerSign() : array } /** - * @dataProvider providerCompare - * * @param array $a The first money. * @param array $b The second money. * @param int $c The comparison value. */ + #[DataProvider('providerCompare')] public function testCompareTo(array $a, array $b, int $c) : void { self::assertSame($c, Money::of(...$a)->compareTo(Money::of(...$b))); @@ -686,12 +646,11 @@ public function testCompareToOtherCurrency() : void } /** - * @dataProvider providerCompare - * * @param array $a The first money. * @param array $b The second money. * @param int $c The comparison value. */ + #[DataProvider('providerCompare')] public function testIsEqualTo(array $a, array $b, int $c) : void { self::assertSame($c === 0, Money::of(...$a)->isEqualTo(Money::of(...$b))); @@ -704,12 +663,11 @@ public function testIsEqualToOtherCurrency() : void } /** - * @dataProvider providerCompare - * * @param array $a The first money. * @param array $b The second money. * @param int $c The comparison value. */ + #[DataProvider('providerCompare')] public function testIsLessThan(array $a, array $b, int $c) : void { self::assertSame($c < 0, Money::of(...$a)->isLessThan(Money::of(...$b))); @@ -722,12 +680,11 @@ public function testIsLessThanOtherCurrency() : void } /** - * @dataProvider providerCompare - * * @param array $a The first money. * @param array $b The second money. * @param int $c The comparison value. */ + #[DataProvider('providerCompare')] public function testIsLessThanOrEqualTo(array $a, array $b, int $c) : void { self::assertSame($c <= 0, Money::of(...$a)->isLessThanOrEqualTo(Money::of(...$b))); @@ -740,12 +697,11 @@ public function testIsLessThanOrEqualToOtherCurrency() : void } /** - * @dataProvider providerCompare - * * @param array $a The first money. * @param array $b The second money. * @param int $c The comparison value. */ + #[DataProvider('providerCompare')] public function testIsGreaterThan(array $a, array $b, int $c) : void { self::assertSame($c > 0, Money::of(...$a)->isGreaterThan(Money::of(...$b))); @@ -758,12 +714,11 @@ public function testIsGreaterThanOtherCurrency() : void } /** - * @dataProvider providerCompare - * * @param array $a The first money. * @param array $b The second money. * @param int $c The comparison value. */ + #[DataProvider('providerCompare')] public function testIsGreaterThanOrEqualTo(array $a, array $b, int $c) : void { self::assertSame($c >= 0, Money::of(...$a)->isGreaterThanOrEqualTo(Money::of(...$b))); @@ -775,9 +730,7 @@ public function testIsGreaterThanOrEqualToOtherCurrency() : void Money::of('1.00', 'EUR')->isGreaterThanOrEqualTo(Money::of('1.00', 'USD')); } - /** - * @dataProvider providerIsAmountAndCurrencyEqualTo - */ + #[DataProvider('providerIsAmountAndCurrencyEqualTo')] public function testIsAmountAndCurrencyEqualTo(array $a, array $b, bool $c) : void { self::assertSame($c, Money::of(...$a)->isAmountAndCurrencyEqualTo(Money::of(...$b))); @@ -806,9 +759,7 @@ public static function providerCompare() : array ]; } - /** - * @dataProvider providerGetMinorAmount - */ + #[DataProvider('providerGetMinorAmount')] public function testGetMinorAmount(array $money, string $expected) : void { $actual = Money::of(...$money)->getMinorAmount(); @@ -836,9 +787,7 @@ public function testGetUnscaledAmount() : void self::assertSame('12345', (string) $actual); } - /** - * @dataProvider providerConvertedTo - */ + #[DataProvider('providerConvertedTo')] public function testConvertedTo(array $money, array $parameters, string $expected) : void { $actual = Money::of(...$money)->convertedTo(...$parameters); @@ -855,14 +804,13 @@ public static function providerConvertedTo() : array } /** - * @dataProvider providerFormatWith - * @requires extension intl - * * @param array $money The money to test. * @param string $locale The target locale. * @param string $symbol A decimal symbol to apply to the NumberFormatter. * @param string $expected The expected output. */ + #[RequiresPhpExtension('intl')] + #[DataProvider('providerFormatWith')] public function testFormatWith(array $money, string $locale, string $symbol, string $expected) : void { $formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY); @@ -881,14 +829,13 @@ public static function providerFormatWith() : array } /** - * @dataProvider providerFormatTo - * @requires extension intl - * * @param array $money The money to test. * @param string $locale The target locale. * @param bool $allowWholeNumber Whether to allow formatting as a whole number if the amount has no fraction. * @param string $expected The expected output. */ + #[RequiresPhpExtension('intl')] + #[DataProvider('providerFormatTo')] public function testFormatTo(array $money, string $locale, bool $allowWholeNumber, string $expected) : void { self::assertSame($expected, Money::of(...$money)->formatTo($locale, $allowWholeNumber)); @@ -919,11 +866,10 @@ public function testToRational() : void } /** - * @dataProvider providerMin - * * @param array $monies The monies to compare. * @param string $expectedResult The expected money result, or an exception class. */ + #[DataProvider('providerMin')] public function testMin(array $monies, string $expectedResult) : void { $monies = array_map( @@ -953,11 +899,10 @@ public static function providerMin() : array } /** - * @dataProvider providerMax - * * @param array $monies The monies to compare. * @param string $expectedResult The expected money result, or an exception class. */ + #[DataProvider('providerMax')] public function testMax(array $monies, string $expectedResult) : void { $monies = array_map( @@ -1007,9 +952,7 @@ public function testTotalOfDifferentCurrenciesThrowsException() : void ); } - /** - * @dataProvider providerJsonSerialize - */ + #[DataProvider('providerJsonSerialize')] public function testJsonSerialize(Money $money, array $expected): void { self::assertSame($expected, $money->jsonSerialize()); diff --git a/tests/RationalMoneyTest.php b/tests/RationalMoneyTest.php index e5452c7..ffb18fd 100644 --- a/tests/RationalMoneyTest.php +++ b/tests/RationalMoneyTest.php @@ -4,19 +4,19 @@ namespace Brick\Money\Tests; +use Brick\Math\BigRational; +use Brick\Math\Exception\RoundingNecessaryException; +use Brick\Math\RoundingMode; use Brick\Money\Context; -use Brick\Money\Context\CashContext; -use Brick\Money\Context\DefaultContext; use Brick\Money\Context\AutoContext; +use Brick\Money\Context\CashContext; use Brick\Money\Context\CustomContext; +use Brick\Money\Context\DefaultContext; use Brick\Money\Currency; use Brick\Money\Exception\MoneyMismatchException; use Brick\Money\Money; use Brick\Money\RationalMoney; - -use Brick\Math\BigRational; -use Brick\Math\Exception\RoundingNecessaryException; -use Brick\Math\RoundingMode; +use PHPUnit\Framework\Attributes\DataProvider; /** * Unit tests for class RationalMoney. @@ -34,9 +34,7 @@ public function testGetters() : void self::assertSame($currency, $money->getCurrency()); } - /** - * @dataProvider providerPlus - */ + #[DataProvider('providerPlus')] public function testPlus(array $rationalMoney, mixed $amount, string $expected) : void { $rationalMoney = RationalMoney::of(...$rationalMoney); @@ -65,9 +63,7 @@ public static function providerPlus() : array ]; } - /** - * @dataProvider providerMinus - */ + #[DataProvider('providerMinus')] public function testMinus(array $rationalMoney, mixed $amount, string $expected) : void { $rationalMoney = RationalMoney::of(...$rationalMoney); @@ -96,9 +92,7 @@ public static function providerMinus() : array ]; } - /** - * @dataProvider providerMultipliedBy - */ + #[DataProvider('providerMultipliedBy')] public function testMultipliedBy(array $rationalMoney, mixed $operand, string $expected) : void { $rationalMoney = RationalMoney::of(...$rationalMoney); @@ -123,9 +117,7 @@ public static function providerMultipliedBy() : array ]; } - /** - * @dataProvider providerDividedBy - */ + #[DataProvider('providerDividedBy')] public function testDividedBy(array $rationalMoney, mixed $operand, string $expected) : void { $rationalMoney = RationalMoney::of(...$rationalMoney); @@ -151,9 +143,7 @@ public static function providerDividedBy() : array ]; } - /** - * @dataProvider providerSimplified - */ + #[DataProvider('providerSimplified')] public function testSimplified(array $rationalMoney, string $expected) : void { $rationalMoney = RationalMoney::of(...$rationalMoney); @@ -172,9 +162,7 @@ public static function providerSimplified() : array ]; } - /** - * @dataProvider providerTo - */ + #[DataProvider('providerTo')] public function testTo(array $rationalMoney, Context $context, RoundingMode $roundingMode, string $expected) : void { $rationalMoney = RationalMoney::of(...$rationalMoney); @@ -202,9 +190,7 @@ public static function providerTo() : array ]; } - /** - * @dataProvider providerJsonSerialize - */ + #[DataProvider('providerJsonSerialize')] public function testJsonSerialize(RationalMoney $money, array $expected): void { self::assertSame($expected, $money->jsonSerialize());