diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6c804d7..afc547c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,14 +11,14 @@ jobs: continue-on-error: ${{ matrix.experimental }} strategy: matrix: - php-version: ['8.2', '8.3'] + php-version: ['8.2', '8.3', '8.4'] extensions: [':apcu, mbstring', 'apcu, mbstring'] os: [ubuntu-latest] experimental: [false] composer-options: [''] include: - - { php-version: '8.4', experimental: true, os: ubuntu-latest, composer-options: '--ignore-platform-req=php+', extensions: 'apcu, mbstring' } - - { php-version: '8.4', experimental: true, os: ubuntu-latest, composer-options: '--ignore-platform-req=php+', extensions: ':apcu, mbstring' } + - { php-version: '8.5', experimental: true, os: ubuntu-latest, composer-options: '--ignore-platform-req=php+', extensions: 'apcu, mbstring' } + - { php-version: '8.5', experimental: true, os: ubuntu-latest, composer-options: '--ignore-platform-req=php+', extensions: ':apcu, mbstring' } steps: - name: Checkout code uses: actions/checkout@v4 @@ -40,7 +40,7 @@ jobs: dependency-versions: highest composer-options: ${{ matrix.composer-options }} - - name: Run php tests + - name: Run PHP tests run: composer run phpunit -- --display-deprecations --display-notices --display-warnings --display-errors --display-skipped - name: Send coverage diff --git a/CHANGELOG.md b/CHANGELOG.md index f807ddc..6776e47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,12 @@ ## [Unreleased] -* Drop support for PHP 7.1, PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0 and PHP 8.1. +* Drop support for PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0 and PHP 8.1. + +## [Unreleased] + +* Bump PHP minimum version to 7.2 +* Add support for Symfony 7 ## [5.3.1] - 2023-08-23 diff --git a/composer.json b/composer.json index 8d74850..0926ef2 100644 --- a/composer.json +++ b/composer.json @@ -32,11 +32,12 @@ }, "require-dev": { "phpmyadmin/coding-standard": "^4.0", - "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.10", - "phpstan/phpstan-phpunit": "^1.3", - "phpstan/phpstan-strict-rules": "^1.5", - "phpunit/phpunit": "^10.3", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^1.12", + "phpstan/phpstan-deprecation-rules": "^1.2", + "phpstan/phpstan-phpunit": "^1.4", + "phpstan/phpstan-strict-rules": "^1.6", + "phpunit/phpunit": "^10.5", "psalm/plugin-phpunit": "^0.18.4", "vimeo/psalm": "^5.6" }, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4ed289e..d38ef7d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -25,6 +25,16 @@ parameters: count: 1 path: src/Loader.php + - + message: "#^Offset 'lang' on array\\{0\\: string, lang\\: non\\-falsy\\-string, 1\\: non\\-falsy\\-string, country\\?\\: string, 2\\?\\: string, charset\\?\\: string, 3\\?\\: string, modifier\\?\\: non\\-empty\\-string, \\.\\.\\.\\} on left side of \\?\\? always exists and is not nullable\\.$#" + count: 1 + path: src/Loader.php + + - + message: "#^Strict comparison using \\!\\=\\= between non\\-falsy\\-string and '' will always evaluate to true\\.$#" + count: 1 + path: src/Loader.php + - message: "#^Casting to int something that's already int\\.$#" count: 1 @@ -50,46 +60,11 @@ parameters: count: 1 path: src/Translator.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#" - count: 1 - path: tests/Cache/ApcuCacheFactoryTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\)\\.$#" - count: 1 - path: tests/Cache/ApcuCacheFactoryTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 2 - path: tests/Cache/ApcuCacheFactoryTest.php - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#" count: 1 path: tests/Cache/ApcuCacheFactoryTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 2 - path: tests/Cache/ApcuCacheTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#" - count: 4 - path: tests/Cache/ApcuCacheTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 11 - path: tests/Cache/ApcuCacheTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\)\\.$#" - count: 1 - path: tests/Cache/ApcuCacheTest.php - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#" count: 1 @@ -100,36 +75,6 @@ parameters: count: 1 path: tests/Cache/ApcuDisabledTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 1 - path: tests/Cache/InMemoryCacheTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#" - count: 1 - path: tests/Cache/InMemoryCacheTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 4 - path: tests/Cache/InMemoryCacheTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\)\\.$#" - count: 1 - path: tests/Cache/InMemoryCacheTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 9 - path: tests/FunctionsTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 13 - path: tests/LoaderTest.php - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:isInstanceOf\\(\\)\\.$#" count: 1 @@ -144,38 +89,3 @@ parameters: message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\TestCase\\:\\:once\\(\\)\\.$#" count: 1 path: tests/LoaderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 16 - path: tests/MoFilesTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 3 - path: tests/PluralFormulaTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 3 - path: tests/PluralTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileExists\\(\\)\\.$#" - count: 2 - path: tests/StringReaderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 2 - path: tests/StringReaderTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 6 - path: tests/TranslatorTest.php - - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 6 - path: tests/TranslatorTest.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 14356a3..16a94f4 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,7 +6,7 @@ parameters: - src - tests checkBenevolentUnionTypes: true + checkDynamicProperties: true checkImplicitMixed: true checkTooWideReturnTypesInProtectedAndPublicMethods: true checkUninitializedProperties: true - reportUnmatchedIgnoredErrors: true diff --git a/psalm-baseline.xml b/psalm-baseline.xml index c332561..7d9864f 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + diff --git a/tests/Cache/ApcuCacheFactoryTest.php b/tests/Cache/ApcuCacheFactoryTest.php index cc1ba52..858c105 100644 --- a/tests/Cache/ApcuCacheFactoryTest.php +++ b/tests/Cache/ApcuCacheFactoryTest.php @@ -41,7 +41,7 @@ public function testGetInstanceReturnApcuCache(): void { $factory = new ApcuCacheFactory(); $instance = $factory->getInstance(new MoParser(null), 'foo', 'bar'); - $this->assertInstanceOf(ApcuCache::class, $instance); + self::assertInstanceOf(ApcuCache::class, $instance); } public function testConstructorSetsTtl(): void @@ -57,7 +57,7 @@ public function testConstructorSetsTtl(): void sleep($ttl * 2); apcu_fetch('mo_' . $locale . '.' . $domain . '.' . $msgid, $success); - $this->assertFalse($success); + self::assertFalse($success); } public function testConstructorSetsReloadOnMiss(): void @@ -74,7 +74,7 @@ public function testConstructorSetsReloadOnMiss(): void apcu_delete('mo_' . $locale . '.' . $domain . '.' . $msgid); $actual = $instance->get($msgid); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testConstructorSetsPrefix(): void @@ -91,6 +91,6 @@ public function testConstructorSetsPrefix(): void $factory->getInstance($parser, $locale, $domain); $actual = apcu_fetch($prefix . $locale . '.' . $domain . '.' . $msgid); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } } diff --git a/tests/Cache/ApcuCacheTest.php b/tests/Cache/ApcuCacheTest.php index 06c8ff8..c7b22c2 100644 --- a/tests/Cache/ApcuCacheTest.php +++ b/tests/Cache/ApcuCacheTest.php @@ -51,7 +51,7 @@ public function testConstructorLoadsCache(): void new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), $locale, $domain); $actual = apcu_fetch('mo_' . $locale . '.' . $domain . '.' . $msgid); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testConstructorSetsTtl(): void @@ -65,9 +65,9 @@ public function testConstructorSetsTtl(): void sleep($ttl * 2); apcu_fetch('mo_' . $locale . '.' . $domain . '.' . $msgid, $success); - $this->assertFalse($success); + self::assertFalse($success); apcu_fetch('mo_' . $locale . '.' . $domain . '.' . ApcuCache::LOADED_KEY, $success); - $this->assertFalse($success); + self::assertFalse($success); } public function testConstructorSetsReloadOnMiss(): void @@ -89,7 +89,7 @@ public function testConstructorSetsReloadOnMiss(): void apcu_delete($prefix . $locale . '.' . $domain . '.' . $msgid); $actual = $cache->get($msgid); - $this->assertEquals($expected, $actual); + self::assertSame($expected, $actual); } public function testConstructorSetsPrefix(): void @@ -103,7 +103,7 @@ public function testConstructorSetsPrefix(): void new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), $locale, $domain, 0, true, $prefix); $actual = apcu_fetch($prefix . $locale . '.' . $domain . '.' . $msgid); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testEnsureTranslationsLoadedSetsLoadedKey(): void @@ -115,7 +115,7 @@ public function testEnsureTranslationsLoadedSetsLoadedKey(): void new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), $locale, $domain); $actual = apcu_fetch('mo_' . $locale . '.' . $domain . '.' . ApcuCache::LOADED_KEY); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testEnsureTranslationsLoadedHonorsLock(): void @@ -134,9 +134,9 @@ public function testEnsureTranslationsLoadedHonorsLock(): void new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), $locale, $domain); $actual = apcu_fetch($lock); - $this->assertSame(1, $actual); + self::assertSame(1, $actual); apcu_fetch('mo_' . $locale . '.' . $domain . '.' . $msgid, $success); - $this->assertFalse($success); + self::assertFalse($success); } public function testGetReturnsMsgstr(): void @@ -147,7 +147,7 @@ public function testGetReturnsMsgstr(): void $cache = new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), 'foo', 'bar'); $actual = $cache->get($msgid); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testGetReturnsMsgidForCacheMiss(): void @@ -157,7 +157,7 @@ public function testGetReturnsMsgidForCacheMiss(): void $cache = new ApcuCache(new MoParser(null), 'foo', 'bar'); $actual = $cache->get($expected); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testStoresMsgidOnCacheMiss(): void @@ -170,7 +170,7 @@ public function testStoresMsgidOnCacheMiss(): void $cache->get($expected); $actual = apcu_fetch('mo_' . $locale . '.' . $domain . '.' . $expected); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testGetReloadsOnCacheMiss(): void @@ -184,7 +184,7 @@ public function testGetReloadsOnCacheMiss(): void apcu_delete('mo_' . $locale . '.' . $domain . '.' . ApcuCache::LOADED_KEY); $actual = $cache->get($msgid); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testReloadOnMissHonorsLock(): void @@ -207,7 +207,7 @@ public function testReloadOnMissHonorsLock(): void }); $actual = $method->invoke($cache, $msgid); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testSetSetsMsgstr(): void @@ -219,21 +219,21 @@ public function testSetSetsMsgstr(): void $cache->set($msgid, $expected); $actual = $cache->get($msgid); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testHasReturnsFalse(): void { $cache = new ApcuCache(new MoParser(null), 'foo', 'bar'); $actual = $cache->has('Column'); - $this->assertFalse($actual); + self::assertFalse($actual); } public function testHasReturnsTrue(): void { $cache = new ApcuCache(new MoParser(__DIR__ . '/../data/little.mo'), 'foo', 'bar'); $actual = $cache->has('Column'); - $this->assertTrue($actual); + self::assertTrue($actual); } public function testSetAllSetsTranslations(): void @@ -248,7 +248,7 @@ public function testSetAllSetsTranslations(): void foreach ($translations as $msgid => $expected) { $actual = $cache->get($msgid); - $this->assertEquals($expected, $actual); + self::assertSame($expected, $actual); } } @@ -263,6 +263,6 @@ public function testCacheStoresPluralForms(): void $msgstr = $cache->get($msgid); $actual = explode(chr(0), $msgstr); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } } diff --git a/tests/Cache/InMemoryCacheTest.php b/tests/Cache/InMemoryCacheTest.php index 6b1a73d..b869218 100644 --- a/tests/Cache/InMemoryCacheTest.php +++ b/tests/Cache/InMemoryCacheTest.php @@ -17,7 +17,7 @@ public function testConstructorParsesCache(): void $parser = new MoParser(__DIR__ . '/../data/little.mo'); $cache = new InMemoryCache($parser); $actual = $cache->get('Column'); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testGetReturnsMsgidForCacheMiss(): void @@ -25,7 +25,7 @@ public function testGetReturnsMsgidForCacheMiss(): void $expected = 'Column'; $cache = new InMemoryCache(new MoParser(null)); $actual = $cache->get($expected); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testSetSetsMsgstr(): void @@ -35,21 +35,21 @@ public function testSetSetsMsgstr(): void $cache = new InMemoryCache(new MoParser(null)); $cache->set($msgid, $expected); $actual = $cache->get($msgid); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testHasReturnsFalse(): void { $cache = new InMemoryCache(new MoParser(null)); $actual = $cache->has('Column'); - $this->assertFalse($actual); + self::assertFalse($actual); } public function testHasReturnsTrue(): void { $cache = new InMemoryCache(new MoParser(__DIR__ . '/../data/little.mo')); $actual = $cache->has('Column'); - $this->assertTrue($actual); + self::assertTrue($actual); } public function testSetAllSetsTranslations(): void @@ -62,7 +62,7 @@ public function testSetAllSetsTranslations(): void $cache->setAll($translations); foreach ($translations as $msgid => $expected) { $actual = $cache->get($msgid); - $this->assertEquals($expected, $actual); + self::assertSame($expected, $actual); } } @@ -75,6 +75,6 @@ public function testGetAllReturnsTranslations(): void $cache = new InMemoryCache(new MoParser(null)); $cache->setAll($expected); $actual = $cache->getAll(); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } } diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 803dcb0..de04195 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -38,79 +38,34 @@ public function setUp(): void public function testGettext(): void { - $this->assertEquals( + self::assertSame( 'Typ', _gettext('Type'), ); - $this->assertEquals( + self::assertSame( 'Typ', __('Type'), ); - $this->assertEquals( - '%d sekundy', - _ngettext( - '%d second', - '%d seconds', - 2, - ), - ); + self::assertSame('%d sekundy', _ngettext('%d second', '%d seconds', 2)); - $this->assertEquals( - '%d seconds', - _npgettext( - 'context', - '%d second', - '%d seconds', - 2, - ), - ); + self::assertSame('%d seconds', _npgettext('context', '%d second', '%d seconds', 2)); - $this->assertEquals( - 'Tabulka', - _pgettext( - 'Display format', - 'Table', - ), - ); + self::assertSame('Tabulka', _pgettext('Display format', 'Table')); } public function testDomain(): void { - $this->assertEquals( + self::assertSame( 'Typ', _dgettext('phpmyadmin', 'Type'), ); - $this->assertEquals( - '%d sekundy', - _dngettext( - 'phpmyadmin', - '%d second', - '%d seconds', - 2, - ), - ); + self::assertSame('%d sekundy', _dngettext('phpmyadmin', '%d second', '%d seconds', 2)); - $this->assertEquals( - '%d seconds', - _dnpgettext( - 'phpmyadmin', - 'context', - '%d second', - '%d seconds', - 2, - ), - ); + self::assertSame('%d seconds', _dnpgettext('phpmyadmin', 'context', '%d second', '%d seconds', 2)); - $this->assertEquals( - 'Tabulka', - _dpgettext( - 'phpmyadmin', - 'Display format', - 'Table', - ), - ); + self::assertSame('Tabulka', _dpgettext('phpmyadmin', 'Display format', 'Table')); } } diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php index c00692f..36ab8c6 100644 --- a/tests/LoaderTest.php +++ b/tests/LoaderTest.php @@ -26,10 +26,7 @@ class LoaderTest extends TestCase */ public function testListLocales(string $locale, array $expected): void { - $this->assertEquals( - $expected, - Loader::listLocales($locale), - ); + self::assertSame($expected, Loader::listLocales($locale)); } /** @return list}> */ @@ -151,10 +148,10 @@ public function testLocaleChange(): void $loader->textdomain('phpmyadmin'); $loader->bindtextdomain('phpmyadmin', __DIR__ . '/data/locale/'); $translator = $loader->getTranslator('phpmyadmin'); - $this->assertEquals('Typ', $translator->gettext('Type')); + self::assertSame('Typ', $translator->gettext('Type')); $loader->setlocale('be_BY'); $translator = $loader->getTranslator('phpmyadmin'); - $this->assertEquals('Тып', $translator->gettext('Type')); + self::assertSame('Тып', $translator->gettext('Type')); } /** @dataProvider translatorData */ @@ -162,7 +159,7 @@ public function testGetTranslator(string $domain, string $locale, string $otherd { $loader = $this->getLoader($domain, $locale); $translator = $loader->getTranslator($otherdomain); - $this->assertEquals( + self::assertSame( $expected, $translator->gettext('Type'), ); @@ -219,7 +216,7 @@ public function testInstance(): void $loader->bindtextdomain('phpmyadmin', __DIR__ . '/data/locale/'); $translator = $loader->getTranslator(); - $this->assertEquals( + self::assertSame( 'Typ', $translator->gettext('Type'), ); @@ -227,7 +224,7 @@ public function testInstance(): void /* Ensure the object survives */ $loader = Loader::getInstance(); $translator = $loader->getTranslator(); - $this->assertEquals( + self::assertSame( 'Typ', $translator->gettext('Type'), ); @@ -237,7 +234,7 @@ public function testInstance(): void $loader->setlocale('be_BY'); $loader->bindtextdomain('phpmyadmin', __DIR__ . '/data/locale/'); $translator = $loader->getTranslator(); - $this->assertEquals( + self::assertSame( 'Тып', $translator->gettext('Type'), ); @@ -247,7 +244,7 @@ public function testDetect(): void { $GLOBALS['lang'] = 'foo'; $loader = Loader::getInstance(); - $this->assertEquals( + self::assertSame( 'foo', $loader->detectlocale(), ); @@ -268,24 +265,24 @@ public function testDetectEnv(): void unset($GLOBALS['lang']); putenv('LC_ALL=baz'); - $this->assertEquals( + self::assertSame( 'baz', $loader->detectlocale(), ); putenv('LC_ALL'); putenv('LC_MESSAGES=bar'); - $this->assertEquals( + self::assertSame( 'bar', $loader->detectlocale(), ); putenv('LC_MESSAGES'); putenv('LANG=barr'); - $this->assertEquals( + self::assertSame( 'barr', $loader->detectlocale(), ); putenv('LANG'); - $this->assertEquals( + self::assertSame( 'en', $loader->detectlocale(), ); @@ -314,6 +311,6 @@ public function testSetCacheFactory(): void $translator = $loader->getTranslator($domain); $actual = $translator->gettext('Type'); - $this->assertEquals($expected, $actual); + self::assertSame($expected, $actual); } } diff --git a/tests/MoFilesTest.php b/tests/MoFilesTest.php index 3706d2b..2452cfc 100644 --- a/tests/MoFilesTest.php +++ b/tests/MoFilesTest.php @@ -22,12 +22,12 @@ class MoFilesTest extends TestCase public function testMoFileTranslate(string $filename): void { $parser = $this->getTranslator($filename); - $this->assertEquals( + self::assertSame( 'Pole', $parser->gettext('Column'), ); // Non existing string - $this->assertEquals( + self::assertSame( 'Column parser', $parser->gettext('Column parser'), ); @@ -47,82 +47,27 @@ public function testMoFilePlurals(string $filename): void $expected0 = '%d sekund'; } - $this->assertEquals( - $expected0, - $parser->ngettext( - '%d second', - '%d seconds', - 0, - ), - ); - $this->assertEquals( - '%d sekunda', - $parser->ngettext( - '%d second', - '%d seconds', - 1, - ), - ); - $this->assertEquals( - $expected2, - $parser->ngettext( - '%d second', - '%d seconds', - 2, - ), - ); - $this->assertEquals( - $expected0, - $parser->ngettext( - '%d second', - '%d seconds', - 5, - ), - ); - $this->assertEquals( - $expected0, - $parser->ngettext( - '%d second', - '%d seconds', - 10, - ), - ); + self::assertSame($expected0, $parser->ngettext('%d second', '%d seconds', 0)); + self::assertSame('%d sekunda', $parser->ngettext('%d second', '%d seconds', 1)); + self::assertSame($expected2, $parser->ngettext('%d second', '%d seconds', 2)); + self::assertSame($expected0, $parser->ngettext('%d second', '%d seconds', 5)); + self::assertSame($expected0, $parser->ngettext('%d second', '%d seconds', 10)); // Non existing string - $this->assertEquals( - '"%d" seconds', - $parser->ngettext( - '"%d" second', - '"%d" seconds', - 10, - ), - ); + self::assertSame('"%d" seconds', $parser->ngettext('"%d" second', '"%d" seconds', 10)); } /** @dataProvider provideMoFiles */ public function testMoFileContext(string $filename): void { $parser = $this->getTranslator($filename); - $this->assertEquals( - 'Tabulka', - $parser->pgettext( - 'Display format', - 'Table', - ), - ); + self::assertSame('Tabulka', $parser->pgettext('Display format', 'Table')); } /** @dataProvider provideNotTranslatedFiles */ public function testMoFileNotTranslated(string $filename): void { $parser = $this->getTranslator($filename); - $this->assertEquals( - '%d second', - $parser->ngettext( - '%d second', - '%d seconds', - 1, - ), - ); + self::assertSame('%d second', $parser->ngettext('%d second', '%d seconds', 1)); } /** @return list */ @@ -149,40 +94,21 @@ public function testEmptyMoFile(string $file): void $parser = new MoParser($file); $translator = new Translator(new InMemoryCache($parser)); if (basename($file) === 'magic.mo') { - $this->assertEquals(Translator::ERROR_BAD_MAGIC, $parser->error); + self::assertSame(Translator::ERROR_BAD_MAGIC, $parser->error); } else { - $this->assertEquals(Translator::ERROR_READING, $parser->error); + self::assertSame(Translator::ERROR_READING, $parser->error); } - $this->assertEquals( - 'Table', - $translator->pgettext( - 'Display format', - 'Table', - ), - ); - $this->assertEquals( - '"%d" seconds', - $translator->ngettext( - '"%d" second', - '"%d" seconds', - 10, - ), - ); + self::assertSame('Table', $translator->pgettext('Display format', 'Table')); + self::assertSame('"%d" seconds', $translator->ngettext('"%d" second', '"%d" seconds', 10)); } /** @dataProvider provideMoFiles */ public function testExists(string $file): void { $parser = $this->getTranslator($file); - $this->assertEquals( - true, - $parser->exists('Column'), - ); - $this->assertEquals( - false, - $parser->exists('Column parser'), - ); + self::assertTrue($parser->exists('Column')); + self::assertFalse($parser->exists('Column parser')); } /** diff --git a/tests/PluralFormulaTest.php b/tests/PluralFormulaTest.php index 0390031..a14a5c2 100644 --- a/tests/PluralFormulaTest.php +++ b/tests/PluralFormulaTest.php @@ -19,7 +19,7 @@ class PluralFormulaTest extends TestCase */ public function testExtractPluralsForms(string $header, string $expected): void { - $this->assertEquals( + self::assertSame( $expected, Translator::extractPluralsForms($header), ); @@ -59,7 +59,7 @@ public static function pluralExtractionData(): array /** @dataProvider pluralCounts */ public function testPluralCounts(string $expr, int $expected): void { - $this->assertEquals( + self::assertSame( $expected, Translator::extractPluralCount($expr), ); @@ -99,7 +99,7 @@ public static function pluralCounts(): array /** @dataProvider pluralExpressions */ public function testPluralExpression(string $expr, string $expected): void { - $this->assertEquals( + self::assertSame( $expected, Translator::sanitizePluralExpression($expr), ); diff --git a/tests/PluralTest.php b/tests/PluralTest.php index 776258e..8a82e5f 100644 --- a/tests/PluralTest.php +++ b/tests/PluralTest.php @@ -29,7 +29,7 @@ public function testNpgettext(int $number, string $expected): void { $parser = $this->getTranslator(''); $result = $parser->npgettext('context', "%d pig went to the market\n", "%d pigs went to the market\n", $number); - $this->assertSame($expected, $result); + self::assertSame($expected, $result); } /** @@ -60,7 +60,7 @@ public function testNgettext(): void $translationKey = implode(chr(0), ["%d pig went to the market\n", "%d pigs went to the market\n"]); $parser->setTranslation($translationKey, ''); $result = $parser->ngettext("%d pig went to the market\n", "%d pigs went to the market\n", 1); - $this->assertSame('', $result); + self::assertSame('', $result); } /** @return list */ @@ -113,7 +113,7 @@ public function testNgettextSelectString(string $pluralForms): void $translationKey = implode(chr(0), ["%d pig went to the market\n", "%d pigs went to the market\n"]); $parser->setTranslation($translationKey, 'ok'); $result = $parser->ngettext("%d pig went to the market\n", "%d pigs went to the market\n", 1); - $this->assertSame('ok', $result); + self::assertSame('ok', $result); } private function getTranslator(string $filename): Translator diff --git a/tests/StringReaderTest.php b/tests/StringReaderTest.php index 17dc794..1af9fe2 100644 --- a/tests/StringReaderTest.php +++ b/tests/StringReaderTest.php @@ -17,22 +17,22 @@ class StringReaderTest extends TestCase public function testReadFails(): void { $tempFile = (string) tempnam(sys_get_temp_dir(), 'phpMyAdmin_StringReaderTest'); - $this->assertFileExists($tempFile); + self::assertFileExists($tempFile); $stringReader = new StringReader($tempFile); unlink($tempFile); $actual = $stringReader->read(-1, -1); - $this->assertSame('', $actual); + self::assertSame('', $actual); } public function testReadIntArray(): void { $tempFile = (string) tempnam(sys_get_temp_dir(), 'phpMyAdmin_StringReaderTest'); file_put_contents($tempFile, "\0\0\0\0\0\0\0\0\0\0\0\0"); - $this->assertFileExists($tempFile); + self::assertFileExists($tempFile); $stringReader = new StringReader($tempFile); unlink($tempFile); $actual = $stringReader->readintarray('V', 2, 2); - $this->assertSame([ + self::assertSame([ 1 => 0, 2 => 0, ], $actual); diff --git a/tests/TranslatorTest.php b/tests/TranslatorTest.php index 58a04b4..f890fcf 100644 --- a/tests/TranslatorTest.php +++ b/tests/TranslatorTest.php @@ -22,7 +22,7 @@ public function testConstructorWithFilenameParam(): void $expected = 'Pole'; $translator = new Translator(__DIR__ . '/data/little.mo'); $actual = $translator->gettext('Column'); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testConstructorWithNullParam(): void @@ -30,7 +30,7 @@ public function testConstructorWithNullParam(): void $expected = 'Column'; $translator = new Translator(null); $actual = $translator->gettext($expected); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } /** @@ -39,7 +39,7 @@ public function testConstructorWithNullParam(): void public function testGettext(): void { $translator = $this->getTranslator(''); - $this->assertEquals('Test', $translator->gettext('Test')); + self::assertSame('Test', $translator->gettext('Test')); } /** @@ -49,7 +49,7 @@ public function testSetTranslation(): void { $translator = $this->getTranslator(''); $translator->setTranslation('Test', 'Translation'); - $this->assertEquals('Translation', $translator->gettext('Test')); + self::assertSame('Translation', $translator->gettext('Test')); } /** @@ -60,12 +60,12 @@ public function testGetSetTranslations(): void $transTable = ['Test' => 'Translation']; $translator = $this->getTranslator(''); $translator->setTranslations($transTable); - $this->assertEquals('Translation', $translator->gettext('Test')); - $this->assertSame($transTable, $translator->getTranslations()); + self::assertSame('Translation', $translator->gettext('Test')); + self::assertSame($transTable, $translator->getTranslations()); $translator = $this->getTranslator(null); $translator->setTranslations($transTable); - $this->assertSame($transTable, $translator->getTranslations()); - $this->assertEquals('Translation', $translator->gettext('Test')); + self::assertSame($transTable, $translator->getTranslations()); + self::assertSame('Translation', $translator->gettext('Test')); $transTable = [ 'Test' => 'Translation', 'shouldIWriteTests' => 'as much as possible', @@ -73,12 +73,12 @@ public function testGetSetTranslations(): void ]; $translator = $this->getTranslator(''); $translator->setTranslations($transTable); - $this->assertSame($transTable, $translator->getTranslations()); - $this->assertEquals('as much as possible', $translator->gettext('shouldIWriteTests')); + self::assertSame($transTable, $translator->getTranslations()); + self::assertSame('as much as possible', $translator->gettext('shouldIWriteTests')); $translator = $this->getTranslator(null); $translator->setTranslations($transTable); - $this->assertSame($transTable, $translator->getTranslations()); - $this->assertEquals('it depends', $translator->gettext('is it hard')); + self::assertSame($transTable, $translator->getTranslations()); + self::assertSame('it depends', $translator->gettext('is it hard')); } public function testGetTranslationsThrowsException(): void