From 7947862d6d311f6f91b1477f915d2b27cbc2266c Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Fri, 11 Aug 2023 12:20:01 +0200 Subject: [PATCH] Upgrade to PHPUnit 10 --- .gitignore | 2 +- composer.json | 2 +- phpunit.xml | 9 +-- tests/Context/AutoContextTest.php | 2 +- tests/Context/CashContextTest.php | 2 +- tests/Context/CustomContextTest.php | 2 +- tests/Context/DefaultContextTest.php | 2 +- tests/CurrencyConverterTest.php | 8 +-- tests/CurrencyTest.php | 8 +-- .../BaseCurrencyProviderTest.php | 4 +- .../ConfigurableProviderTest.php | 2 +- .../ExchangeRateProvider/PDOProviderTest.php | 10 ++-- tests/ISOCurrencyProviderTest.php | 4 +- tests/MoneyComparatorTest.php | 6 +- tests/MoneyTest.php | 56 +++++++++---------- tests/RationalMoneyTest.php | 14 ++--- 16 files changed, 67 insertions(+), 66 deletions(-) diff --git a/.gitignore b/.gitignore index 4901aab..8ae88e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ /vendor /composer.lock -/.phpunit.result.cache +/.phpunit.cache diff --git a/composer.json b/composer.json index c1a24f9..9558fad 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "ext-pdo": "*", "brick/varexporter": "~0.3.0", "php-coveralls/php-coveralls": "^2.2", - "phpunit/phpunit": "^9.4.3", + "phpunit/phpunit": "^10.1", "vimeo/psalm": "5.14.1" }, "suggest": { diff --git a/phpunit.xml b/phpunit.xml index bd04f0e..8a51903 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,14 @@ - - + + tests - + + src - + diff --git a/tests/Context/AutoContextTest.php b/tests/Context/AutoContextTest.php index 15a6561..b9d8b47 100644 --- a/tests/Context/AutoContextTest.php +++ b/tests/Context/AutoContextTest.php @@ -39,7 +39,7 @@ public function testApplyTo(string $amount, string $currency, RoundingMode $roun } } - public function providerApplyTo() : array + public static function providerApplyTo() : array { return [ ['1', 'USD', RoundingMode::UNNECESSARY, '1'], diff --git a/tests/Context/CashContextTest.php b/tests/Context/CashContextTest.php index c6f0b2b..09d661c 100644 --- a/tests/Context/CashContextTest.php +++ b/tests/Context/CashContextTest.php @@ -38,7 +38,7 @@ public function testApplyTo(int $step, string $amount, string $currency, Roundin } } - public function providerApplyTo() : array + public static function providerApplyTo() : array { return [ [1, '1', 'USD', RoundingMode::UNNECESSARY, '1.00'], diff --git a/tests/Context/CustomContextTest.php b/tests/Context/CustomContextTest.php index a84d092..4227252 100644 --- a/tests/Context/CustomContextTest.php +++ b/tests/Context/CustomContextTest.php @@ -38,7 +38,7 @@ public function testApplyTo(int $scale, int $step, string $amount, string $curre } } - public function providerApplyTo() : array + public static function providerApplyTo() : array { return [ [2, 1, '1', 'USD', RoundingMode::UNNECESSARY, '1.00'], diff --git a/tests/Context/DefaultContextTest.php b/tests/Context/DefaultContextTest.php index 785aafc..9a0c2fe 100644 --- a/tests/Context/DefaultContextTest.php +++ b/tests/Context/DefaultContextTest.php @@ -38,7 +38,7 @@ public function testApplyTo(string $amount, string $currency, RoundingMode $roun } } - public function providerApplyTo() : array + public static function providerApplyTo() : array { return [ ['1', 'USD', RoundingMode::UNNECESSARY, '1.00'], diff --git a/tests/CurrencyConverterTest.php b/tests/CurrencyConverterTest.php index b7a9ea0..060f5b6 100644 --- a/tests/CurrencyConverterTest.php +++ b/tests/CurrencyConverterTest.php @@ -57,7 +57,7 @@ public function testConvertMoney(array $money, string $toCurrency, RoundingMode } } - public function providerConvertMoney() : array + public static function providerConvertMoney() : array { return [ [['1.23', 'EUR'], 'USD', RoundingMode::DOWN, 'USD 1.35'], @@ -101,7 +101,7 @@ public function testConvertMoneyBag(array $monies, string $currency, Context $co $this->assertMoneyIs($total, $currencyConverter->convert($moneyBag, $currency, $context, $roundingMode)); } - public function providerConvertMoneyBag() : array + public static function providerConvertMoneyBag() : array { return [ [[['354.40005', 'EUR'], ['3.1234', 'JPY']], 'USD', new DefaultContext(), RoundingMode::DOWN, 'USD 437.56'], @@ -138,7 +138,7 @@ public function testConvertMoneyBagToRational(array $monies, string $currency, s $this->assertRationalMoneyEquals($expectedTotal, $actualTotal); } - public function providerConvertMoneyBagToRational() : array + public static function providerConvertMoneyBagToRational() : array { return [ [[['354.40005', 'EUR'], ['3.1234', 'JPY']], 'USD', 'USD 19909199529475444524673813/50000000000000000000000'], @@ -171,7 +171,7 @@ public function testConvertRationalMoney(array $money, string $toCurrency, Round } } - public function providerConvertRationalMoney() : array + public static function providerConvertRationalMoney() : array { return [ [['7/9', 'USD'], 'EUR', RoundingMode::DOWN, 'EUR 0.70'], diff --git a/tests/CurrencyTest.php b/tests/CurrencyTest.php index a6fef98..f223139 100644 --- a/tests/CurrencyTest.php +++ b/tests/CurrencyTest.php @@ -29,7 +29,7 @@ public function testOf(string $currencyCode, int $numericCode, int $fractionDigi $this->assertCurrencyEquals($currencyCode, $numericCode, $name, $fractionDigits, $currency); } - public function providerOf() : array + public static function providerOf() : array { return [ ['USD', 840, 2, 'US Dollar'], @@ -49,7 +49,7 @@ public function testOfUnknownCurrencyCode(string|int $currencyCode) : void Currency::of($currencyCode); } - public function providerOfUnknownCurrencyCode() : array + public static function providerOfUnknownCurrencyCode() : array { return [ ['XXX'], @@ -85,7 +85,7 @@ public function testOfCountry(string $countryCode, string $expected) : void } } - public function providerOfCountry() : array + public static function providerOfCountry() : array { return [ ['CA', 'CAD'], @@ -133,7 +133,7 @@ public function testJsonSerialize(Currency $currency, string $expected): void self::assertSame(json_encode($expected), json_encode($currency)); } - public function providerJsonSerialize(): array + public static function providerJsonSerialize(): array { return [ [Currency::of('USD'), 'USD'] diff --git a/tests/ExchangeRateProvider/BaseCurrencyProviderTest.php b/tests/ExchangeRateProvider/BaseCurrencyProviderTest.php index 0fa3fb6..c4eca94 100644 --- a/tests/ExchangeRateProvider/BaseCurrencyProviderTest.php +++ b/tests/ExchangeRateProvider/BaseCurrencyProviderTest.php @@ -42,7 +42,7 @@ public function testGetExchangeRate(string $sourceCurrencyCode, string $targetCu self::assertSame($exchangeRate, (string) $rate->toScale(6, RoundingMode::DOWN)); } - public function providerGetExchangeRate() : array + public static function providerGetExchangeRate() : array { return [ ['USD', 'EUR', '0.900000'], @@ -76,7 +76,7 @@ public function testReturnBigNumber(BigNumber|float|int|string $rate) : void $this->assertInstanceOf(BigNumber::class, $rate); } - public function providerReturnBigNumber() : array + public static function providerReturnBigNumber() : array { return [[1], [1.1], ['1.0'], [BigNumber::of('1')]]; } diff --git a/tests/ExchangeRateProvider/ConfigurableProviderTest.php b/tests/ExchangeRateProvider/ConfigurableProviderTest.php index ca905fe..2a6fef5 100644 --- a/tests/ExchangeRateProvider/ConfigurableProviderTest.php +++ b/tests/ExchangeRateProvider/ConfigurableProviderTest.php @@ -41,7 +41,7 @@ public function testGetExchangeRate(string $sourceCurrencyCode, string $targetCu self::assertSame($exchangeRate, (string) BigRational::of($rate)->toScale(3, RoundingMode::DOWN)); } - public function providerGetExchangeRate() : array + public static function providerGetExchangeRate() : array { return [ ['USD', 'EUR', '0.800'], diff --git a/tests/ExchangeRateProvider/PDOProviderTest.php b/tests/ExchangeRateProvider/PDOProviderTest.php index 3888fc9..d5e8aca 100644 --- a/tests/ExchangeRateProvider/PDOProviderTest.php +++ b/tests/ExchangeRateProvider/PDOProviderTest.php @@ -30,7 +30,7 @@ public function testConfigurationConstructorThrows(Closure $getConfiguration, st $getConfiguration(); } - public function providerConstructorWithInvalidConfiguration() : array + public static function providerConstructorWithInvalidConfiguration() : array { return [ [fn () => new PDOProviderConfiguration( @@ -111,7 +111,7 @@ public function testGetExchangeRate(string $sourceCurrencyCode, string $targetCu } } - public function providerGetExchangeRate() : array + public static function providerGetExchangeRate() : array { return [ ['USD', 'EUR', 0.9], @@ -165,7 +165,7 @@ public function testWithFixedSourceCurrency(string $sourceCurrencyCode, string $ } } - public function providerWithFixedSourceCurrency() : array + public static function providerWithFixedSourceCurrency() : array { return [ ['EUR', 'USD', 1.1], @@ -219,7 +219,7 @@ public function testWithFixedTargetCurrency(string $sourceCurrencyCode, string $ } } - public function providerWithFixedTargetCurrency() : array + public static function providerWithFixedTargetCurrency() : array { return [ ['USD', 'EUR', 0.9], @@ -281,7 +281,7 @@ public function testWithParameters(string $sourceCurrencyCode, string $targetCur } } - public function providerWithParameters() : array + public static function providerWithParameters() : array { return [ ['EUR', 'USD', [2017, 8], 1.1], diff --git a/tests/ISOCurrencyProviderTest.php b/tests/ISOCurrencyProviderTest.php index 22a194d..09700c9 100644 --- a/tests/ISOCurrencyProviderTest.php +++ b/tests/ISOCurrencyProviderTest.php @@ -41,7 +41,7 @@ public function testGetCurrency(string $currencyCode, int $numericCode, string $ $this->assertCurrencyEquals($currencyCode, $numericCode, $name, $defaultFractionDigits, $currency); } - public function providerGetCurrency() : array + public static function providerGetCurrency() : array { return [ ['EUR', 978, 'Euro', 2], @@ -66,7 +66,7 @@ public function testGetUnknownCurrency(string|int $currencyCode) : void ISOCurrencyProvider::getInstance()->getCurrency($currencyCode); } - public function providerUnknownCurrency() : array + public static function providerUnknownCurrency() : array { return [ ['XXX'], diff --git a/tests/MoneyComparatorTest.php b/tests/MoneyComparatorTest.php index eca6506..fd909d7 100644 --- a/tests/MoneyComparatorTest.php +++ b/tests/MoneyComparatorTest.php @@ -57,7 +57,7 @@ public function testCompare(array $a, array $b, int|string $cmp) : void self::assertSame($cmp === 0, $comparator->isEqual($a, $b)); } - public function providerCompare() : array + public static function providerCompare() : array { return [ [['1.00', 'EUR'], ['1', 'EUR'], 0], @@ -111,7 +111,7 @@ public function testMin(array $monies, string $expectedMin) : void } } - public function providerMin() : array + public static function providerMin() : array { return [ [[['1.00', 'EUR'], ['1.09', 'USD']], 'USD 1.09'], @@ -149,7 +149,7 @@ public function testMax(array $monies, string $expectedMin) : void } } - public function providerMax() : array + public static function providerMax() : array { return [ [[['1.00', 'EUR'], ['1.09', 'USD']], 'EUR 1.00'], diff --git a/tests/MoneyTest.php b/tests/MoneyTest.php index 9836bd6..7563c39 100644 --- a/tests/MoneyTest.php +++ b/tests/MoneyTest.php @@ -45,7 +45,7 @@ public function testOf(string $expectedResult, mixed ...$args) : void } } - public function providerOf() : array + public static function providerOf() : array { return [ ['USD 1.00', 1, 'USD'], @@ -81,7 +81,7 @@ public function testOfMinor(string $expectedResult, mixed ...$args) : void } } - public function providerOfMinor() : array + public static function providerOfMinor() : array { return [ ['EUR 0.01', 1, 'EUR'], @@ -102,7 +102,7 @@ public function testZero(string $currency, ?Context $context, string $expected) $this->assertMoneyIs($expected, $actual, $context === null ? new DefaultContext() : $context); } - public function providerZero() : array + public static function providerZero() : array { return [ ['USD', null, 'USD 0.00'], @@ -131,7 +131,7 @@ public function testTo(array $money, Context $context, RoundingMode $roundingMod } } - public function providerTo() : array + public static function providerTo() : array { return [ [['1.234', 'USD', new AutoContext()], new DefaultContext(), RoundingMode::DOWN, 'USD 1.23'], @@ -174,7 +174,7 @@ public function testPlus(array $money, mixed $plus, RoundingMode $roundingMode, } } - public function providerPlus() : array + public static function providerPlus() : array { return [ [['12.34', 'USD'], 1, RoundingMode::UNNECESSARY, 'USD 13.34'], @@ -232,7 +232,7 @@ public function testMinus(array $money, mixed $minus, RoundingMode $roundingMode } } - public function providerMinus() : array + public static function providerMinus() : array { return [ [['12.34', 'USD'], 1, RoundingMode::UNNECESSARY, 'USD 11.34'], @@ -272,7 +272,7 @@ public function testMultipliedBy(array $money, Money|int|float|string $multiplie } } - public function providerMultipliedBy() : array + public static function providerMultipliedBy() : array { return [ [['12.34', 'USD'], 2, RoundingMode::UNNECESSARY, 'USD 24.68'], @@ -311,7 +311,7 @@ public function testDividedBy(array $money, int|float|string $divisor, RoundingM } } - public function providerDividedBy() : array + public static function providerDividedBy() : array { return [ [['12.34', 'USD'], 0, RoundingMode::DOWN, DivisionByZeroException::class], @@ -341,7 +341,7 @@ public function testQuotientAndRemainder(array $money, int $divisor, string $exp $this->assertMoneyIs($expectedRemainder, $remainder); } - public function providerQuotientAndRemainder() : array + public static function providerQuotientAndRemainder() : array { return [ [['10', 'USD'], 3, 'USD 3.33', 'USD 0.01'], @@ -369,7 +369,7 @@ public function testAllocate(array $money, array $ratios, array $expected) : voi $this->assertMoniesAre($expected, $monies); } - public function providerAllocate() : array + public static function providerAllocate() : array { return [ [['99.99', 'USD'], [100], ['USD 99.99']], @@ -426,7 +426,7 @@ public function testAllocateWithRemainder(array $money, array $ratios, array $ex $this->assertMoniesAre($expected, $monies); } - public function providerAllocateWithRemainder() : array + public static function providerAllocateWithRemainder() : array { return [ [['99.99', 'USD'], [100], ['USD 99.99', 'USD 0.00']], @@ -483,7 +483,7 @@ public function testSplit(array $money, int $targets, array $expected) : void $this->assertMoniesAre($expected, $monies); } - public function providerSplit() : array + public static function providerSplit() : array { return [ [['99.99', 'USD'], 1, ['USD 99.99']], @@ -507,7 +507,7 @@ public function testSplitWithRemainder(array $money, int $targets, array $expect $this->assertMoniesAre($expected, $monies); } - public function providerSplitWithRemainder() : array + public static function providerSplitWithRemainder() : array { return [ [['99.99', 'USD'], 1, ['USD 99.99', 'USD 0.00']], @@ -534,7 +534,7 @@ public function testSplitIntoLessThanOnePart(int $parts) : void $money->split($parts); } - public function providerSplitIntoLessThanOnePart() : array + public static function providerSplitIntoLessThanOnePart() : array { return [ [-1], @@ -555,7 +555,7 @@ public function testSplitWithRemainderIntoLessThanOnePart(int $parts) : void $money->splitWithRemainder($parts); } - public function providerSplitWithRemainderIntoLessThanOnePart() : array + public static function providerSplitWithRemainderIntoLessThanOnePart() : array { return [ [-1], @@ -572,7 +572,7 @@ public function testAbs(array $money, string $abs) : void $this->assertMoneyIs($abs, Money::of(...$money)->abs()); } - public function providerAbs() : array + public static function providerAbs() : array { return [ [['-1', 'EUR'], 'EUR 1.00'], @@ -589,7 +589,7 @@ public function testNegated(array $money, string $negated) : void $this->assertMoneyIs($negated, Money::of(...$money)->negated()); } - public function providerNegated() : array + public static function providerNegated() : array { return [ [['1.234', 'EUR', new AutoContext()], 'EUR -1.234'], @@ -645,7 +645,7 @@ public function testIsNegativeOrZero(array $money, int $sign) : void self::assertSame($sign <= 0, Money::of(...$money)->isNegativeOrZero()); } - public function providerSign() : array + public static function providerSign() : array { return [ [['-0.001', 'USD', new AutoContext()], -1], @@ -783,16 +783,16 @@ public function testIsAmountAndCurrencyEqualTo(array $a, array $b, bool $c) : vo self::assertSame($c, Money::of(...$a)->isAmountAndCurrencyEqualTo(Money::of(...$b))); } - public function providerIsAmountAndCurrencyEqualTo() : \Generator + public static function providerIsAmountAndCurrencyEqualTo() : \Generator { - foreach ($this->providerCompare() as [$a, $b, $c]) { + foreach (self::providerCompare() as [$a, $b, $c]) { yield [$a, $b, $c === 0]; } yield [[1, 'EUR'], [1, 'USD'], false]; } - public function providerCompare() : array + public static function providerCompare() : array { return [ [['1', 'EUR', new AutoContext()], ['1.00', 'EUR'], 0], @@ -817,7 +817,7 @@ public function testGetMinorAmount(array $money, string $expected) : void self::assertSame($expected, (string) $actual); } - public function providerGetMinorAmount() : array + public static function providerGetMinorAmount() : array { return [ [[50, 'USD'], '5000'], @@ -845,7 +845,7 @@ public function testConvertedTo(array $money, array $parameters, string $expecte $this->assertMoneyIs($expected, $actual); } - public function providerConvertedTo() : array + public static function providerConvertedTo() : array { return [ [['1.23', 'USD'], ['JPY', '125', new CustomContext(2)], 'JPY 153.75'], @@ -872,7 +872,7 @@ public function testFormatWith(array $money, string $locale, string $symbol, str self::assertSame($expected, $actual); } - public function providerFormatWith() : array + public static function providerFormatWith() : array { return [ [['1.23', 'USD'], 'en_US', ';', '$1;23'], @@ -894,7 +894,7 @@ public function testFormatTo(array $money, string $locale, bool $allowWholeNumbe self::assertSame($expected, Money::of(...$money)->formatTo($locale, $allowWholeNumber)); } - public function providerFormatTo() : array + public static function providerFormatTo() : array { return [ [['1.23', 'USD'], 'en_US', false, '$1.23'], @@ -942,7 +942,7 @@ public function testMin(array $monies, string $expectedResult) : void } } - public function providerMin() : array + public static function providerMin() : array { return [ [[['1.0', 'USD', new AutoContext()], ['3.50', 'USD'], ['4.00', 'USD']], 'USD 1'], @@ -976,7 +976,7 @@ public function testMax(array $monies, string $expectedResult) : void } } - public function providerMax() : array + public static function providerMax() : array { return [ [[['5.50', 'USD'], ['3.50', 'USD'], ['4.90', 'USD']], 'USD 5.50'], @@ -1016,7 +1016,7 @@ public function testJsonSerialize(Money $money, array $expected): void self::assertSame(json_encode($expected), json_encode($money)); } - public function providerJsonSerialize(): array + public static function providerJsonSerialize(): array { return [ [Money::of('3.5', 'EUR'), ['amount' => '3.50', 'currency' => 'EUR']], diff --git a/tests/RationalMoneyTest.php b/tests/RationalMoneyTest.php index e8008cb..e5452c7 100644 --- a/tests/RationalMoneyTest.php +++ b/tests/RationalMoneyTest.php @@ -52,7 +52,7 @@ public function testPlus(array $rationalMoney, mixed $amount, string $expected) } } - public function providerPlus() : array + public static function providerPlus() : array { return [ [['1.1234', 'USD'], '987.65', 'USD 988773400/1000000'], @@ -83,7 +83,7 @@ public function testMinus(array $rationalMoney, mixed $amount, string $expected) } } - public function providerMinus() : array + public static function providerMinus() : array { return [ [['987.65', 'USD'], '1.1234', 'USD 986526600/1000000'], @@ -114,7 +114,7 @@ public function testMultipliedBy(array $rationalMoney, mixed $operand, string $e } } - public function providerMultipliedBy() : array + public static function providerMultipliedBy() : array { return [ [['987.65', 'USD'], '1.123456', 'USD 110958131840/100000000'], @@ -141,7 +141,7 @@ public function testDividedBy(array $rationalMoney, mixed $operand, string $expe } } - public function providerDividedBy() : array + public static function providerDividedBy() : array { return [ [['987.65', 'USD'], '1.123456', 'USD 98765000000/112345600'], @@ -162,7 +162,7 @@ public function testSimplified(array $rationalMoney, string $expected) : void $this->assertRationalMoneyEquals($expected, $actual); } - public function providerSimplified() : array + public static function providerSimplified() : array { return [ [['123456/10000', 'USD'], 'USD 7716/625'], @@ -190,7 +190,7 @@ public function testTo(array $rationalMoney, Context $context, RoundingMode $rou } } - public function providerTo() : array + public static function providerTo() : array { return [ [['987.65', 'USD'], new DefaultContext(), RoundingMode::UNNECESSARY, 'USD 987.65'], @@ -211,7 +211,7 @@ public function testJsonSerialize(RationalMoney $money, array $expected): void self::assertSame(json_encode($expected), json_encode($money)); } - public function providerJsonSerialize(): array + public static function providerJsonSerialize(): array { return [ [RationalMoney::of('3.5', 'EUR'), ['amount' => '35/10', 'currency' => 'EUR']],