From 5878e38a039aeb1359fce95b01faacece954ed48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 20 Nov 2024 16:38:01 -0300 Subject: [PATCH] Prefer PHPUnit self calls instead of $this MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Done using PreferPHPUnitSelfCallRector. Signed-off-by: Maurício Meneghini Fauth --- phpstan-baseline.neon | 97 +---------------------- tests/Cache/ApcuCacheFactoryTest.php | 8 +- tests/Cache/ApcuCacheTest.php | 36 ++++----- tests/Cache/InMemoryCacheTest.php | 14 ++-- tests/FunctionsTest.php | 72 +++-------------- tests/LoaderTest.php | 56 ++++---------- tests/MoFilesTest.php | 112 ++++----------------------- tests/PluralFormulaTest.php | 15 +--- tests/PluralTest.php | 6 +- tests/StringReaderTest.php | 8 +- tests/TranslatorTest.php | 24 +++--- 11 files changed, 90 insertions(+), 358 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 56b0bf1..971c409 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -115,46 +115,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 @@ -166,33 +131,8 @@ parameters: 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\\(\\)\\.$#" + message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\) with array\\ and array\\ will always evaluate to false\\.$#" 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 - @@ -225,11 +165,6 @@ parameters: count: 1 path: tests/LoaderTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 16 - path: tests/MoFilesTest.php - - message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Tests\\\\MoFilesTest\\:\\:getFiles\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -250,11 +185,6 @@ parameters: count: 1 path: tests/MoFilesTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" - count: 3 - path: tests/PluralFormulaTest.php - - message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Tests\\\\PluralFormulaTest\\:\\:pluralCounts\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -270,11 +200,6 @@ parameters: count: 1 path: tests/PluralFormulaTest.php - - - message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" - count: 3 - path: tests/PluralTest.php - - message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Tests\\\\PluralTest\\:\\:dataProviderPluralForms\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -285,23 +210,3 @@ parameters: count: 1 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/tests/Cache/ApcuCacheFactoryTest.php b/tests/Cache/ApcuCacheFactoryTest.php index b6262b1..53b16a8 100644 --- a/tests/Cache/ApcuCacheFactoryTest.php +++ b/tests/Cache/ApcuCacheFactoryTest.php @@ -43,7 +43,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 @@ -59,7 +59,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 @@ -76,7 +76,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 @@ -93,6 +93,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 5fa06f4..cc3be25 100644 --- a/tests/Cache/ApcuCacheTest.php +++ b/tests/Cache/ApcuCacheTest.php @@ -53,7 +53,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 @@ -67,9 +67,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 @@ -91,7 +91,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 @@ -105,7 +105,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 @@ -117,7 +117,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 @@ -136,9 +136,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 @@ -149,7 +149,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 @@ -159,7 +159,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 @@ -172,7 +172,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 @@ -186,7 +186,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 @@ -209,7 +209,7 @@ public function testReloadOnMissHonorsLock(): void }); $actual = $method->invoke($cache, $msgid); - $this->assertSame($expected, $actual); + self::assertSame($expected, $actual); } public function testSetSetsMsgstr(): void @@ -221,21 +221,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 @@ -250,7 +250,7 @@ public function testSetAllSetsTranslations(): void foreach ($translations as $msgid => $expected) { $actual = $cache->get($msgid); - $this->assertEquals($expected, $actual); + self::assertSame($expected, $actual); } } @@ -265,6 +265,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 c81a56e..8047f92 100644 --- a/tests/Cache/InMemoryCacheTest.php +++ b/tests/Cache/InMemoryCacheTest.php @@ -19,7 +19,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 @@ -27,7 +27,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 @@ -37,21 +37,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 @@ -64,7 +64,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); } } @@ -77,6 +77,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 8551957..3a3621c 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -24,79 +24,25 @@ public function setUp(): void public function testGettext(): void { - $this->assertEquals( - 'Typ', - _gettext('Type') - ); + self::assertSame('Typ', _gettext('Type')); - $this->assertEquals( - 'Typ', - __('Type') - ); + 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( - 'Typ', - _dgettext('phpmyadmin', 'Type') - ); + 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 f8ff148..3eb16ec 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)); } /** @@ -153,10 +150,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')); } /** @@ -166,10 +163,7 @@ public function testGetTranslator(string $domain, string $locale, string $otherd { $loader = $this->getLoader($domain, $locale); $translator = $loader->getTranslator($otherdomain); - $this->assertEquals( - $expected, - $translator->gettext('Type') - ); + self::assertSame($expected, $translator->gettext('Type')); } /** @@ -225,38 +219,26 @@ public function testInstance(): void $loader->bindtextdomain('phpmyadmin', __DIR__ . '/data/locale/'); $translator = $loader->getTranslator(); - $this->assertEquals( - 'Typ', - $translator->gettext('Type') - ); + self::assertSame('Typ', $translator->gettext('Type')); /* Ensure the object survives */ $loader = Loader::getInstance(); $translator = $loader->getTranslator(); - $this->assertEquals( - 'Typ', - $translator->gettext('Type') - ); + self::assertSame('Typ', $translator->gettext('Type')); /* Ensure the object can support different locale files for the same domain */ $loader = Loader::getInstance(); $loader->setlocale('be_BY'); $loader->bindtextdomain('phpmyadmin', __DIR__ . '/data/locale/'); $translator = $loader->getTranslator(); - $this->assertEquals( - 'Тып', - $translator->gettext('Type') - ); + self::assertSame('Тып', $translator->gettext('Type')); } public function testDetect(): void { $GLOBALS['lang'] = 'foo'; $loader = Loader::getInstance(); - $this->assertEquals( - 'foo', - $loader->detectlocale() - ); + self::assertSame('foo', $loader->detectlocale()); unset($GLOBALS['lang']); } @@ -274,27 +256,15 @@ public function testDetectEnv(): void unset($GLOBALS['lang']); putenv('LC_ALL=baz'); - $this->assertEquals( - 'baz', - $loader->detectlocale() - ); + self::assertSame('baz', $loader->detectlocale()); putenv('LC_ALL'); putenv('LC_MESSAGES=bar'); - $this->assertEquals( - 'bar', - $loader->detectlocale() - ); + self::assertSame('bar', $loader->detectlocale()); putenv('LC_MESSAGES'); putenv('LANG=barr'); - $this->assertEquals( - 'barr', - $loader->detectlocale() - ); + self::assertSame('barr', $loader->detectlocale()); putenv('LANG'); - $this->assertEquals( - 'en', - $loader->detectlocale() - ); + self::assertSame('en', $loader->detectlocale()); } public function testSetCacheFactory(): void @@ -320,6 +290,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 a36f057..9cbcfc5 100644 --- a/tests/MoFilesTest.php +++ b/tests/MoFilesTest.php @@ -24,15 +24,9 @@ class MoFilesTest extends TestCase public function testMoFileTranslate(string $filename): void { $parser = $this->getTranslator($filename); - $this->assertEquals( - 'Pole', - $parser->gettext('Column') - ); + self::assertSame('Pole', $parser->gettext('Column')); // Non existing string - $this->assertEquals( - 'Column parser', - $parser->gettext('Column parser') - ); + self::assertSame('Column parser', $parser->gettext('Column parser')); } /** @@ -51,55 +45,13 @@ 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)); } /** @@ -108,13 +60,7 @@ public function testMoFilePlurals(string $filename): void 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')); } /** @@ -123,14 +69,7 @@ public function testMoFileContext(string $filename): void 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)); } /** @@ -165,26 +104,13 @@ 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)); } /** @@ -193,14 +119,8 @@ public function testEmptyMoFile(string $file): void 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 541caa4..06f1261 100644 --- a/tests/PluralFormulaTest.php +++ b/tests/PluralFormulaTest.php @@ -19,10 +19,7 @@ class PluralFormulaTest extends TestCase */ public function testExtractPluralsForms(string $header, string $expected): void { - $this->assertEquals( - $expected, - Translator::extractPluralsForms($header) - ); + self::assertSame($expected, Translator::extractPluralsForms($header)); } /** @@ -63,10 +60,7 @@ public static function pluralExtractionData(): array */ public function testPluralCounts(string $expr, int $expected): void { - $this->assertEquals( - $expected, - Translator::extractPluralCount($expr) - ); + self::assertSame($expected, Translator::extractPluralCount($expr)); } /** @@ -107,10 +101,7 @@ public static function pluralCounts(): array */ public function testPluralExpression(string $expr, string $expected): void { - $this->assertEquals( - $expected, - Translator::sanitizePluralExpression($expr) - ); + self::assertSame($expected, Translator::sanitizePluralExpression($expr)); } /** diff --git a/tests/PluralTest.php b/tests/PluralTest.php index fe4afb6..3651db4 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); } /** @@ -115,7 +115,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 dd135b5..d70bc20 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