From a4ffedbcc2dc4ce6826373f5a92346c846412e9c Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Tue, 13 Aug 2024 10:46:52 +0200 Subject: [PATCH] Remove not needed int type from ReferenceListFormatter It's always a string anyway. Also improve the test coverage. The localization was pretty much untested before. Change-Id: Ie6f34c67ae7dd9559346eb45a2604e14c5633991 --- src/ReferenceListFormatter.php | 4 ++-- tests/phpunit/unit/ReferenceListFormatterTest.php | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/ReferenceListFormatter.php b/src/ReferenceListFormatter.php index e07cfba89..ac1f47113 100644 --- a/src/ReferenceListFormatter.php +++ b/src/ReferenceListFormatter.php @@ -241,14 +241,14 @@ class ReferenceListFormatter { * offset, e.g. $base = 1, $offset = 2; = 1.2 * Since bug #5525, it correctly does 1.9 -> 1.10 as well as 1.099 -> 1.100 * - * @param int|string $base + * @param string $base * @param int $offset * @param int $max Maximum value expected. * * @return string */ private function referencesFormatEntryNumericBacklinkLabel( - $base, + string $base, int $offset, int $max ): string { diff --git a/tests/phpunit/unit/ReferenceListFormatterTest.php b/tests/phpunit/unit/ReferenceListFormatterTest.php index 765d88fb2..abfdfe748 100644 --- a/tests/phpunit/unit/ReferenceListFormatterTest.php +++ b/tests/phpunit/unit/ReferenceListFormatterTest.php @@ -389,10 +389,10 @@ class ReferenceListFormatterTest extends \MediaWikiUnitTestCase { * @dataProvider provideReferencesFormatEntryNumericBacklinkLabel */ public function testReferencesFormatEntryNumericBacklinkLabel( - string $expectedLabel, int $base, int $offset, int $max + string $expectedLabel, string $base, int $offset, int $max ) { $mockMessageLocalizer = $this->createMock( ReferenceMessageLocalizer::class ); - $mockMessageLocalizer->method( 'localizeSeparators' )->willReturnArgument( 0 ); + $mockMessageLocalizer->method( 'localizeSeparators' )->willReturn( ',' ); $mockMessageLocalizer->method( 'localizeDigits' )->willReturnArgument( 0 ); /** @var ReferenceListFormatter $formatter */ @@ -407,11 +407,12 @@ class ReferenceListFormatterTest extends \MediaWikiUnitTestCase { } public static function provideReferencesFormatEntryNumericBacklinkLabel() { - yield [ '1.2', 1, 2, 9 ]; - yield [ '1.02', 1, 2, 99 ]; - yield [ '1.002', 1, 2, 100 ]; - yield [ '1.50005', 1, 50005, 50005 ]; - yield [ '2.1', 2, 1, 1 ]; + yield [ '1,2', '1', 2, 9 ]; + yield [ '1,02', '1', 2, 99 ]; + yield [ '1,002', '1', 2, 100 ]; + yield [ '1,50005', '1', 50005, 50005 ]; + yield [ '2,1', '2', 1, 1 ]; + yield [ '3.2,1', '3.2', 1, 1 ]; } /**