From 51bf0d19b25095d624397c1a3812fc2ccc2bf340 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Tue, 3 Oct 2023 11:03:07 +0200 Subject: [PATCH] Fix --- composer.json | 2 +- tests/Helper/NumberFormatterTest.php | 46 +++-- tests/SonataIntlBundleTest.php | 18 +- tests/Timezone/ChainTimezoneDetectorTest.php | 18 +- .../UserBasedTimezoneDetectorTest.php | 10 +- tests/Twig/Extension/NumberRuntimeTest.php | 178 +++++++++--------- 6 files changed, 126 insertions(+), 146 deletions(-) diff --git a/composer.json b/composer.json index d1c11d9d..72d1e0f8 100644 --- a/composer.json +++ b/composer.json @@ -43,7 +43,7 @@ "phpunit/phpunit": "^9.5", "psalm/plugin-phpunit": "^0.18", "psalm/plugin-symfony": "^5.0", - "rector/rector": "^0.17", + "rector/rector": "^0.18", "symfony/phpunit-bridge": "^6.2", "symfony/security-core": "^5.4 || ^6.2", "vimeo/psalm": "^5.0" diff --git a/tests/Helper/NumberFormatterTest.php b/tests/Helper/NumberFormatterTest.php index eb2bf384..5ac04c67 100644 --- a/tests/Helper/NumberFormatterTest.php +++ b/tests/Helper/NumberFormatterTest.php @@ -95,7 +95,7 @@ public function testExceptionOnInvalidParams(): void } /** - * @dataProvider provideConstantValues + * @dataProvider provideParseConstantValueCases */ public function testParseConstantValue(string $constantName, int $expectedConstant, bool $exceptionExpected): void { @@ -112,21 +112,19 @@ public function testParseConstantValue(string $constantName, int $expectedConsta } /** - * @return array + * @return iterable */ - public function provideConstantValues(): array + public function provideParseConstantValueCases(): iterable { - return [ - ['positive_prefix', \NumberFormatter::POSITIVE_PREFIX, false], - ['non_existent_constant', \NumberFormatter::NEGATIVE_PREFIX, true], - ]; + yield ['positive_prefix', \NumberFormatter::POSITIVE_PREFIX, false]; + yield ['non_existent_constant', \NumberFormatter::NEGATIVE_PREFIX, true]; } /** * @param array $attributes * @param array $expectedAttributes * - * @dataProvider provideAttributeValues + * @dataProvider provideParseAttributesCases */ public function testParseAttributes(array $attributes, array $expectedAttributes, bool $exceptionExpected): void { @@ -143,29 +141,27 @@ public function testParseAttributes(array $attributes, array $expectedAttributes } /** - * @return array, array, bool}> + * @return iterable, array, bool}> */ - public function provideAttributeValues(): array + public function provideParseAttributesCases(): iterable { - return [ + yield [ + [ + 'positive_prefix' => 'POSITIVE', + 'negative_prefix' => 'NEGATIVE', + ], [ - [ - 'positive_prefix' => 'POSITIVE', - 'negative_prefix' => 'NEGATIVE', - ], - [ - \NumberFormatter::POSITIVE_PREFIX => 'POSITIVE', - \NumberFormatter::NEGATIVE_PREFIX => 'NEGATIVE', - ], - false, + \NumberFormatter::POSITIVE_PREFIX => 'POSITIVE', + \NumberFormatter::NEGATIVE_PREFIX => 'NEGATIVE', ], + false, + ]; + yield [ [ - [ - 'non_existent_constant' => 'NON_EXISTENT_VALUE', - ], - [], - true, + 'non_existent_constant' => 'NON_EXISTENT_VALUE', ], + [], + true, ]; } diff --git a/tests/SonataIntlBundleTest.php b/tests/SonataIntlBundleTest.php index 3e855178..340523ba 100644 --- a/tests/SonataIntlBundleTest.php +++ b/tests/SonataIntlBundleTest.php @@ -19,21 +19,19 @@ class SonataIntlBundleTest extends TestCase { /** - * @return array + * @return iterable */ - public function getVersions(): array + public function provideSymfonyVersionCases(): iterable { - return [ - ['2.0.1', '2.0.1', true, true], - ['2.0.2', '2.0.1', true, true], - ['2.1.1-DEV', '2.1.1', false, true], - ['2.1.0-RC1', '2.1.0', false, true], - ['2.1.0-RC1', '2.1.1', false, false], - ]; + yield ['2.0.1', '2.0.1', true, true]; + yield ['2.0.2', '2.0.1', true, true]; + yield ['2.1.1-DEV', '2.1.1', false, true]; + yield ['2.1.0-RC1', '2.1.0', false, true]; + yield ['2.1.0-RC1', '2.1.1', false, false]; } /** - * @dataProvider getVersions + * @dataProvider provideSymfonyVersionCases */ public function testSymfonyVersion(string $currentVersion, string $minVersion, bool $versionExpected, bool $versionBundle): void { diff --git a/tests/Timezone/ChainTimezoneDetectorTest.php b/tests/Timezone/ChainTimezoneDetectorTest.php index ac643266..fd2afe75 100644 --- a/tests/Timezone/ChainTimezoneDetectorTest.php +++ b/tests/Timezone/ChainTimezoneDetectorTest.php @@ -23,23 +23,21 @@ final class ChainTimezoneDetectorTest extends TestCase { /** - * @return array, string}> + * @return iterable, string}> */ - public static function timezoneProvider(): array + public static function provideDetectsTimezoneForUserCases(): iterable { - return [ - [['Europe/Paris', 'Europe/London'], 'Europe/Paris'], - [['Europe/Paris', null], 'Europe/Paris'], - [[null, 'Europe/Paris'], 'Europe/Paris'], - [[null, null], 'America/Denver'], - [['Invalid/Timezone', null], 'America/Denver'], - ]; + yield [['Europe/Paris', 'Europe/London'], 'Europe/Paris']; + yield [['Europe/Paris', null], 'Europe/Paris']; + yield [[null, 'Europe/Paris'], 'Europe/Paris']; + yield [[null, null], 'America/Denver']; + yield [['Invalid/Timezone', null], 'America/Denver']; } /** * @param array $detectorsTimezones * - * @dataProvider timezoneProvider + * @dataProvider provideDetectsTimezoneForUserCases */ public function testDetectsTimezoneForUser(array $detectorsTimezones, string $expectedTimezone): void { diff --git a/tests/Timezone/UserBasedTimezoneDetectorTest.php b/tests/Timezone/UserBasedTimezoneDetectorTest.php index 05ca570d..e7eb1fcf 100644 --- a/tests/Timezone/UserBasedTimezoneDetectorTest.php +++ b/tests/Timezone/UserBasedTimezoneDetectorTest.php @@ -29,16 +29,14 @@ final class UserBasedTimezoneDetectorTest extends TestCase /** * @return iterable */ - public static function timezoneProvider(): iterable + public static function provideUserTimezoneDetectionCases(): iterable { - return [ - ['Europe/Paris'], - [null], - ]; + yield ['Europe/Paris']; + yield [null]; } /** - * @dataProvider timezoneProvider + * @dataProvider provideUserTimezoneDetectionCases */ public function testUserTimezoneDetection(?string $timezone): void { diff --git a/tests/Twig/Extension/NumberRuntimeTest.php b/tests/Twig/Extension/NumberRuntimeTest.php index 799712eb..055eeb17 100644 --- a/tests/Twig/Extension/NumberRuntimeTest.php +++ b/tests/Twig/Extension/NumberRuntimeTest.php @@ -27,7 +27,7 @@ class NumberRuntimeTest extends TestCase * @param array $textAttributes * @param array $symbols * - * @dataProvider provideFormatCurrencyArguments + * @dataProvider provideFormatCurrencyCases */ public function testFormatCurrency( string $expectedResult, @@ -45,34 +45,32 @@ public function testFormatCurrency( } /** - * @return array, 4?: array, 5?: array}> + * @return iterable, 4?: array, 5?: array}> */ - public function provideFormatCurrencyArguments(): array + public function provideFormatCurrencyCases(): iterable { - return [ - [ - '€10.49', - 10.49, - 'EUR', - ], - [ - '€10.50', - 10.499, - 'EUR', - ], - [ - '€10,000.50', - 10000.499, - 'EUR', - ], - [ - '€10DOT000.50', - 10000.499, - 'EUR', - [], - [], - ['MONETARY_GROUPING_SEPARATOR_SYMBOL' => 'DOT'], - ], + yield [ + '€10.49', + 10.49, + 'EUR', + ]; + yield [ + '€10.50', + 10.499, + 'EUR', + ]; + yield [ + '€10,000.50', + 10000.499, + 'EUR', + ]; + yield [ + '€10DOT000.50', + 10000.499, + 'EUR', + [], + [], + ['MONETARY_GROUPING_SEPARATOR_SYMBOL' => 'DOT'], ]; } @@ -81,7 +79,7 @@ public function provideFormatCurrencyArguments(): array * @param array $textAttributes * @param array $symbols * - * @dataProvider provideFormatDecimalArguments + * @dataProvider provideFormatDecimalCases */ public function testFormatDecimal( string $expectedResult, @@ -98,30 +96,28 @@ public function testFormatDecimal( } /** - * @return array, 3?: array, 4?: array}> + * @return iterable, 3?: array, 4?: array}> */ - public function provideFormatDecimalArguments(): array + public function provideFormatDecimalCases(): iterable { - return [ - [ - '10', - 10, - ], - [ - '10.155', - 10.15459, - ], - [ - '1,000,000.155', - 1_000_000.15459, - ], - [ - '1DOT000DOT000.155', - 1_000_000.15459, - [], - [], - ['GROUPING_SEPARATOR_SYMBOL' => 'DOT'], - ], + yield [ + '10', + 10, + ]; + yield [ + '10.155', + 10.15459, + ]; + yield [ + '1,000,000.155', + 1_000_000.15459, + ]; + yield [ + '1DOT000DOT000.155', + 1_000_000.15459, + [], + [], + ['GROUPING_SEPARATOR_SYMBOL' => 'DOT'], ]; } @@ -130,7 +126,7 @@ public function provideFormatDecimalArguments(): array * @param array $textAttributes * @param array $symbols * - * @dataProvider provideFormatScientificArguments + * @dataProvider provideFormatScientificCases */ public function testFormatScientific( string $expectedResult, @@ -147,27 +143,25 @@ public function testFormatScientific( } /** - * @return array, 3?: array, 4?: array}> + * @return iterable, 3?: array, 4?: array}> */ - public function provideFormatScientificArguments(): array + public function provideFormatScientificCases(): iterable { - return [ - [ - '1E1', - 10, - ], - [ - '1E3', - 1000, - ], - [ - '1.0001E3', - 1000.1, - ], - [ - '1.00000015459E6', - 1_000_000.15459, - ], + yield [ + '1E1', + 10, + ]; + yield [ + '1E3', + 1000, + ]; + yield [ + '1.0001E3', + 1000.1, + ]; + yield [ + '1.00000015459E6', + 1_000_000.15459, ]; } @@ -176,7 +170,7 @@ public function provideFormatScientificArguments(): array * @param array $textAttributes * @param array $symbols * - * @dataProvider provideFormatDurationArguments + * @dataProvider provideFormatDurationCases */ public function testFormatDuration( string $expectedResult, @@ -193,15 +187,13 @@ public function testFormatDuration( } /** - * @return array, 3?: array, 4?: array}> + * @return iterable, 3?: array, 4?: array}> */ - public function provideFormatDurationArguments(): array + public function provideFormatDurationCases(): iterable { - return [ - [ - '277:46:40', - 1_000_000, - ], + yield [ + '277:46:40', + 1_000_000, ]; } @@ -210,7 +202,7 @@ public function provideFormatDurationArguments(): array * @param array $textAttributes * @param array $symbols * - * @dataProvider provideFormatPercentArguments + * @dataProvider provideFormatPercentCases */ public function testFormatPercent( string $expectedResult, @@ -227,23 +219,21 @@ public function testFormatPercent( } /** - * @return array, 3?: array, 4?: array}> + * @return iterable, 3?: array, 4?: array}> */ - public function provideFormatPercentArguments(): array + public function provideFormatPercentCases(): iterable { - return [ - [ - '10%', - 0.1, - ], - [ - '200%', - 1.999, - ], - [ - '99%', - 0.99, - ], + yield [ + '10%', + 0.1, + ]; + yield [ + '200%', + 1.999, + ]; + yield [ + '99%', + 0.99, ]; }