diff --git a/composer.json b/composer.json index 0f863bb6..036eebcb 100644 --- a/composer.json +++ b/composer.json @@ -34,9 +34,9 @@ ], "require": { "php": ">=8.1", - "spiral/core": "^3.14.9", - "spiral/logger": "^3.14.9", - "spiral/tokenizer": "^3.14.9", + "spiral/core": "^3.15", + "spiral/logger": "^3.15", + "spiral/tokenizer": "^3.15", "symfony/translation": "^5.1 || ^6.0 || ^7.0", "psr/event-dispatcher": "^1.0" }, diff --git a/tests/AutoRegisterTest.php b/tests/AutoRegisterTest.php index 2bc011e0..6a59a3d0 100644 --- a/tests/AutoRegisterTest.php +++ b/tests/AutoRegisterTest.php @@ -20,11 +20,11 @@ public function testRegister(): void { $tr = $this->translator(); - $this->assertTrue($tr->getCatalogueManager()->get('en')->has('messages', 'Welcome, {name}!')); - $this->assertFalse($tr->getCatalogueManager()->get('en')->has('messages', 'new')); + self::assertTrue($tr->getCatalogueManager()->get('en')->has('messages', 'Welcome, {name}!')); + self::assertFalse($tr->getCatalogueManager()->get('en')->has('messages', 'new')); $tr->trans('new'); - $this->assertTrue($tr->getCatalogueManager()->get('en')->has('messages', 'new')); + self::assertTrue($tr->getCatalogueManager()->get('en')->has('messages', 'new')); } protected function translator(): Translator diff --git a/tests/CatalogueTest.php b/tests/CatalogueTest.php index 64ea41ae..86e141fb 100644 --- a/tests/CatalogueTest.php +++ b/tests/CatalogueTest.php @@ -15,8 +15,8 @@ public function testGetLocale(): void { $catalogue = new Catalogue('ru', []); - $this->assertSame('ru', $catalogue->getLocale()); - $this->assertSame([], $catalogue->getData()); + self::assertSame('ru', $catalogue->getLocale()); + self::assertSame([], $catalogue->getData()); } public function testHas(): void @@ -30,12 +30,12 @@ public function testHas(): void ], ]); - $this->assertSame(['messages', 'views'], $catalogue->getDomains()); + self::assertSame(['messages', 'views'], $catalogue->getDomains()); - $this->assertTrue($catalogue->has('messages', 'message')); - $this->assertTrue($catalogue->has('views', 'view')); - $this->assertFalse($catalogue->has('messages', 'another-message')); - $this->assertFalse($catalogue->has('other-domain', 'message')); + self::assertTrue($catalogue->has('messages', 'message')); + self::assertTrue($catalogue->has('views', 'view')); + self::assertFalse($catalogue->has('messages', 'another-message')); + self::assertFalse($catalogue->has('other-domain', 'message')); } public function testUndefinedString(): void @@ -58,8 +58,8 @@ public function testLoadAndGet(): void ], ]); - $this->assertSame('Russian Translation', $catalogue->get('messages', 'message')); - $this->assertSame('Russian View', $catalogue->get('views', 'view')); + self::assertSame('Russian Translation', $catalogue->get('messages', 'message')); + self::assertSame('Russian View', $catalogue->get('views', 'view')); } public function testLoadGetAndSet(): void @@ -73,16 +73,16 @@ public function testLoadGetAndSet(): void ], ]); - $this->assertSame('Russian Translation', $catalogue->get('messages', 'message')); - $this->assertSame('Russian View', $catalogue->get('views', 'view')); + self::assertSame('Russian Translation', $catalogue->get('messages', 'message')); + self::assertSame('Russian View', $catalogue->get('views', 'view')); - $this->assertFalse($catalogue->has('views', 'message')); + self::assertFalse($catalogue->has('views', 'message')); $catalogue->set('views', 'message', 'View Message'); - $this->assertTrue($catalogue->has('views', 'message')); + self::assertTrue($catalogue->has('views', 'message')); - $this->assertSame('View Message', $catalogue->get('views', 'message')); + self::assertSame('View Message', $catalogue->get('views', 'message')); - $this->assertSame([ + self::assertSame([ 'messages' => [ 'message' => 'Russian Translation', ], @@ -98,12 +98,12 @@ public function testMergeSymfonyAndFollow(): void $catalogue = new Catalogue('ru', []); $catalogue->set('domain', 'message', 'Original Translation'); - $this->assertSame('Original Translation', $catalogue->get('domain', 'message')); + self::assertSame('Original Translation', $catalogue->get('domain', 'message')); $messageCatalogue = new MessageCatalogue('ru', ['domain' => ['message' => 'Translation']]); $catalogue->mergeFrom($messageCatalogue, true); - $this->assertSame('Original Translation', $catalogue->get('domain', 'message')); + self::assertSame('Original Translation', $catalogue->get('domain', 'message')); } public function testMergeSymfonyAndFollowOnEmpty(): void @@ -113,7 +113,7 @@ public function testMergeSymfonyAndFollowOnEmpty(): void $messageCatalogue = new MessageCatalogue('ru', ['domain' => ['message' => 'Translation']]); $catalogue->mergeFrom($messageCatalogue, true); - $this->assertSame('Translation', $catalogue->get('domain', 'message')); + self::assertSame('Translation', $catalogue->get('domain', 'message')); } public function testMergeSymfonyAndReplace(): void @@ -121,12 +121,12 @@ public function testMergeSymfonyAndReplace(): void $catalogue = new Catalogue('ru', []); $catalogue->set('domain', 'message', 'Original Translation'); - $this->assertSame('Original Translation', $catalogue->get('domain', 'message')); + self::assertSame('Original Translation', $catalogue->get('domain', 'message')); $messageCatalogue = new MessageCatalogue('ru', ['domain' => ['message' => 'Translation']]); $catalogue->mergeFrom($messageCatalogue, false); - $this->assertSame('Translation', $catalogue->get('domain', 'message')); + self::assertSame('Translation', $catalogue->get('domain', 'message')); } public function testToCatalogue(): void @@ -142,7 +142,7 @@ public function testToCatalogue(): void $sc = $catalogue->toMessageCatalogue(); - $this->assertSame('ru', $sc->getLocale()); - $this->assertSame(['messages', 'views'], $sc->getDomains()); + self::assertSame('ru', $sc->getLocale()); + self::assertSame(['messages', 'views'], $sc->getDomains()); } } diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 2f53437f..01b7c4fc 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -19,7 +19,7 @@ public function testDefaultLocale(): void 'locale' => 'ru' ]); - $this->assertSame('ru', $config->getDefaultLocale()); + self::assertSame('ru', $config->getDefaultLocale()); } public function testDefaultDomain(): void @@ -28,7 +28,7 @@ public function testDefaultDomain(): void 'locale' => 'ru' ]); - $this->assertSame('messages', $config->getDefaultDomain()); + self::assertSame('messages', $config->getDefaultDomain()); } public function testFallbackLocale(): void @@ -37,20 +37,20 @@ public function testFallbackLocale(): void 'fallbackLocale' => 'ru' ]); - $this->assertSame('ru', $config->getFallbackLocale()); + self::assertSame('ru', $config->getFallbackLocale()); } public function testRegisterMessages(): void { $config = new TranslatorConfig(['autoRegister' => true]); - $this->assertTrue($config->isAutoRegisterMessages()); + self::assertTrue($config->isAutoRegisterMessages()); $config = new TranslatorConfig(['autoRegister' => false]); - $this->assertFalse($config->isAutoRegisterMessages()); + self::assertFalse($config->isAutoRegisterMessages()); //Legacy $config = new TranslatorConfig(['registerMessages' => true]); - $this->assertTrue($config->isAutoRegisterMessages()); + self::assertTrue($config->isAutoRegisterMessages()); } public function testLocalesDirectory(): void @@ -59,7 +59,7 @@ public function testLocalesDirectory(): void 'localesDirectory' => 'directory/' ]); - $this->assertSame('directory/', $config->getLocalesDirectory()); + self::assertSame('directory/', $config->getLocalesDirectory()); } public function testLocaleDirectory(): void @@ -68,7 +68,7 @@ public function testLocaleDirectory(): void 'localesDirectory' => 'directory/' ]); - $this->assertSame('directory/ru/', $config->getLocaleDirectory('ru')); + self::assertSame('directory/ru/', $config->getLocaleDirectory('ru')); } public function testLocaleDirectoryShort(): void @@ -77,7 +77,7 @@ public function testLocaleDirectoryShort(): void 'directory' => 'directory/' ]); - $this->assertSame('directory/ru/', $config->getLocaleDirectory('ru')); + self::assertSame('directory/ru/', $config->getLocaleDirectory('ru')); } public function testLocaleDirectoryWithoutSlash(): void @@ -85,20 +85,20 @@ public function testLocaleDirectoryWithoutSlash(): void $config = new TranslatorConfig([ 'localesDirectory' => 'directory' ]); - $this->assertSame('directory/en/', $config->getLocaleDirectory('en')); + self::assertSame('directory/en/', $config->getLocaleDirectory('en')); $config = new TranslatorConfig([ 'directory' => 'directory' ]); - $this->assertSame('directory/en/', $config->getLocaleDirectory('en')); + self::assertSame('directory/en/', $config->getLocaleDirectory('en')); } public function testLocaleDirectoryWithDirectoryParam(): void { $config = new TranslatorConfig(); - $this->assertSame('directory/en/', $config->getLocaleDirectory('en', 'directory')); - $this->assertSame('directory/en/', $config->getLocaleDirectory('en', 'directory/')); + self::assertSame('directory/en/', $config->getLocaleDirectory('en', 'directory')); + self::assertSame('directory/en/', $config->getLocaleDirectory('en', 'directory/')); } public function testLocaleDirectoryLeadingSlash(): void @@ -107,7 +107,7 @@ public function testLocaleDirectoryLeadingSlash(): void 'directory' => '/directory/locale' ]); - $this->assertSame('/directory/locale/en/', $config->getLocaleDirectory('en')); + self::assertSame('/directory/locale/en/', $config->getLocaleDirectory('en')); } public function testDomains(): void @@ -121,8 +121,8 @@ public function testDomains(): void ] ]); - $this->assertSame('spiral', $config->resolveDomain('spiral-views')); - $this->assertSame('messages', $config->resolveDomain('vendor-views')); + self::assertSame('spiral', $config->resolveDomain('spiral-views')); + self::assertSame('messages', $config->resolveDomain('vendor-views')); } public function testDomainsFallback(): void @@ -135,7 +135,7 @@ public function testDomainsFallback(): void ] ]); - $this->assertSame('external', $config->resolveDomain('external')); + self::assertSame('external', $config->resolveDomain('external')); } public function testHasLoader(): void @@ -144,8 +144,8 @@ public function testHasLoader(): void 'loaders' => ['php' => PhpFileLoader::class] ]); - $this->assertTrue($config->hasLoader('php')); - $this->assertFalse($config->hasLoader('txt')); + self::assertTrue($config->hasLoader('php')); + self::assertFalse($config->hasLoader('txt')); } public function testGetLoader(): void @@ -154,7 +154,7 @@ public function testGetLoader(): void 'loaders' => ['php' => PhpFileLoader::class] ]); - $this->assertInstanceOf(LoaderInterface::class, $config->getLoader('php')); + self::assertInstanceOf(LoaderInterface::class, $config->getLoader('php')); } public function testHasDumper(): void @@ -163,8 +163,8 @@ public function testHasDumper(): void 'dumpers' => ['po' => PoFileDumper::class] ]); - $this->assertTrue($config->hasDumper('po')); - $this->assertFalse($config->hasDumper('xml')); + self::assertTrue($config->hasDumper('po')); + self::assertFalse($config->hasDumper('xml')); } public function testGetDumper(): void @@ -173,13 +173,13 @@ public function testGetDumper(): void 'dumpers' => ['po' => PoFileDumper::class] ]); - $this->assertInstanceOf(DumperInterface::class, $config->getDumper('po')); + self::assertInstanceOf(DumperInterface::class, $config->getDumper('po')); } public function testGetDirectories(): void { $config = new TranslatorConfig(); - $this->assertSame([], $config->getDirectories()); + self::assertSame([], $config->getDirectories()); $config = new TranslatorConfig([ 'directories' => [ @@ -187,6 +187,6 @@ public function testGetDirectories(): void 'bar/' ] ]); - $this->assertSame(['foo', 'bar/'], $config->getDirectories()); + self::assertSame(['foo', 'bar/'], $config->getDirectories()); } } diff --git a/tests/IndexerTest.php b/tests/IndexerTest.php index b9a22021..1e59b8af 100644 --- a/tests/IndexerTest.php +++ b/tests/IndexerTest.php @@ -41,11 +41,11 @@ public function testIndexShortFunctions(): void $indexer->indexInvocations($this->tContainer()->get(InvocationsInterface::class)); - $this->assertTrue($catalogue->has('messages', 'hello')); - $this->assertTrue($catalogue->has('messages', '{n} dog|{n} dogs')); + self::assertTrue($catalogue->has('messages', 'hello')); + self::assertTrue($catalogue->has('messages', '{n} dog|{n} dogs')); - $this->assertTrue($catalogue->has('spiral', 'other')); - $this->assertTrue($catalogue->has('spiral', 'hi-from-class')); + self::assertTrue($catalogue->has('spiral', 'other')); + self::assertTrue($catalogue->has('spiral', 'hi-from-class')); } public function testIndexClasses(): void @@ -62,14 +62,14 @@ public function testIndexClasses(): void $indexer->indexClasses($this->tContainer()->get(ScopedClassesInterface::class)); - $this->assertTrue($catalogue->has('spiral', 'indexer-message')); - $this->assertFalse($catalogue->has('spiral', 'not-message')); + self::assertTrue($catalogue->has('spiral', 'indexer-message')); + self::assertFalse($catalogue->has('spiral', 'not-message')); // from stubs - $this->assertTrue($catalogue->has('spiral', 'some-text')); - $this->assertFalse($catalogue->has('spiral', 'no-message')); + self::assertTrue($catalogue->has('spiral', 'some-text')); + self::assertFalse($catalogue->has('spiral', 'no-message')); - $this->assertTrue($catalogue->has('spiral', 'new-mess')); + self::assertTrue($catalogue->has('spiral', 'new-mess')); } public function testRegisterMessageShouldNotOverrideMessages(): void @@ -83,8 +83,8 @@ public function testRegisterMessageShouldNotOverrideMessages(): void $indexer->indexInvocations($this->tContainer()->get(InvocationsInterface::class)); - $this->assertTrue($catalogue->has('messages', 'hello')); - $this->assertSame('Bonjour', $catalogue->get('messages', 'hello')); + self::assertTrue($catalogue->has('messages', 'hello')); + self::assertSame('Bonjour', $catalogue->get('messages', 'hello')); } protected function tContainer(): Container diff --git a/tests/InterpolateTest.php b/tests/InterpolateTest.php index 0327cddb..eab5aa8a 100644 --- a/tests/InterpolateTest.php +++ b/tests/InterpolateTest.php @@ -21,26 +21,17 @@ class InterpolateTest extends TestCase { public function testInterpolate(): void { - $this->assertSame( - 'Welcome, Antony!', - $this->translator()->trans('Welcome, Antony!', ['name' => 'Antony']) - ); + self::assertSame('Welcome, Antony!', $this->translator()->trans('Welcome, Antony!', ['name' => 'Antony'])); } public function testInterpolateNumbers(): void { - $this->assertSame( - 'Bye, Antony!', - $this->translator()->trans('Bye, Antony!', ['Antony']) - ); + self::assertSame('Bye, Antony!', $this->translator()->trans('Bye, Antony!', ['Antony'])); } public function testInterpolateBad(): void { - $this->assertSame( - 'Bye, {1}!', - $this->translator()->trans('Bye, {1}!', [new self('foo')]) - ); + self::assertSame('Bye, {1}!', $this->translator()->trans('Bye, {1}!', [new self('foo')])); } protected function translator(): Translator diff --git a/tests/LoaderTest.php b/tests/LoaderTest.php index 2c33383c..cf9e3640 100644 --- a/tests/LoaderTest.php +++ b/tests/LoaderTest.php @@ -21,20 +21,20 @@ public function testHasLocale(): void 'directory' => __DIR__ . '/fixtures/locales/', ])); - $this->assertTrue($loader->hasLocale('ru')); - $this->assertTrue($loader->hasLocale('RU')); - $this->assertFalse($loader->hasLocale('fr')); - $this->assertFalse($loader->hasLocale('FR')); + self::assertTrue($loader->hasLocale('ru')); + self::assertTrue($loader->hasLocale('RU')); + self::assertFalse($loader->hasLocale('fr')); + self::assertFalse($loader->hasLocale('FR')); $loader = new CatalogueLoader(new TranslatorConfig([ 'directory' => __DIR__ . '/fixtures/locales/', 'directories' => [__DIR__ . '/fixtures/additional'], ])); - $this->assertTrue($loader->hasLocale('ru')); - $this->assertTrue($loader->hasLocale('RU')); - $this->assertTrue($loader->hasLocale('fr')); - $this->assertTrue($loader->hasLocale('FR')); + self::assertTrue($loader->hasLocale('ru')); + self::assertTrue($loader->hasLocale('RU')); + self::assertTrue($loader->hasLocale('fr')); + self::assertTrue($loader->hasLocale('FR')); } public function testGetLocales(): void @@ -48,7 +48,7 @@ public function testGetLocales(): void sort($shouldBe); sort($compared); - $this->assertSame($shouldBe, $compared); + self::assertSame($shouldBe, $compared); } public function testGetLocalesWithAdditionalDirectories(): void @@ -63,7 +63,7 @@ public function testGetLocalesWithAdditionalDirectories(): void sort($shouldBe); sort($compared); - $this->assertSame($shouldBe, $compared); + self::assertSame($shouldBe, $compared); } public function testLoadCatalogue(): void @@ -77,35 +77,29 @@ public function testLoadCatalogue(): void ])); $catalogue = $loader->loadCatalogue('RU'); - $this->assertInstanceOf(CatalogueInterface::class, $catalogue); - $this->assertSame('ru', $catalogue->getLocale()); + self::assertInstanceOf(CatalogueInterface::class, $catalogue); + self::assertSame('ru', $catalogue->getLocale()); $catalogue = $loader->loadCatalogue('ru'); - $this->assertInstanceOf(CatalogueInterface::class, $catalogue); - $this->assertSame('ru', $catalogue->getLocale()); + self::assertInstanceOf(CatalogueInterface::class, $catalogue); + self::assertSame('ru', $catalogue->getLocale()); - $this->assertCount(2, $catalogue->getDomains()); - $this->assertTrue(in_array('messages', $catalogue->getDomains())); - $this->assertTrue(in_array('views', $catalogue->getDomains())); + self::assertCount(2, $catalogue->getDomains()); + self::assertContains('messages', $catalogue->getDomains()); + self::assertContains('views', $catalogue->getDomains()); $mc = $catalogue->toMessageCatalogue(); - $this->assertTrue($mc->has('message')); - $this->assertSame('translation', $mc->get('message')); + self::assertTrue($mc->has('message')); + self::assertSame('translation', $mc->get('message')); - $this->assertTrue($mc->has('Welcome To Spiral', 'views')); - $this->assertSame( - 'Добро пожаловать в Spiral Framework', - $mc->get('Welcome To Spiral', 'views') - ); + self::assertTrue($mc->has('Welcome To Spiral', 'views')); + self::assertSame('Добро пожаловать в Spiral Framework', $mc->get('Welcome To Spiral', 'views')); - $this->assertTrue($mc->has('Twig Version', 'views')); - $this->assertSame( - 'Twig версия', - $mc->get('Twig Version', 'views') - ); + self::assertTrue($mc->has('Twig Version', 'views')); + self::assertSame('Twig версия', $mc->get('Twig Version', 'views')); - $this->assertFalse($loader->hasLocale('fr')); + self::assertFalse($loader->hasLocale('fr')); } public function testLoadCatalogueWithAdditionalDirectories(): void @@ -121,16 +115,13 @@ public function testLoadCatalogueWithAdditionalDirectories(): void $catalogue = $loader->loadCatalogue('fr'); $mc = $catalogue->toMessageCatalogue(); - $this->assertTrue($mc->has('Welcome To Spiral', 'views')); - $this->assertSame( - 'Bienvenue à Spirale', - $mc->get('Welcome To Spiral', 'views') - ); - - $this->assertTrue($loader->hasLocale('fr')); - $this->assertTrue($loader->hasLocale('FR')); - $this->assertTrue($loader->hasLocale('ru')); - $this->assertTrue($loader->hasLocale('RU')); + self::assertTrue($mc->has('Welcome To Spiral', 'views')); + self::assertSame('Bienvenue à Spirale', $mc->get('Welcome To Spiral', 'views')); + + self::assertTrue($loader->hasLocale('fr')); + self::assertTrue($loader->hasLocale('FR')); + self::assertTrue($loader->hasLocale('ru')); + self::assertTrue($loader->hasLocale('RU')); } public function testApplicationTranslationShouldOverrideAdditionalTranslations(): void @@ -147,8 +138,8 @@ public function testApplicationTranslationShouldOverrideAdditionalTranslations() $catalogue = $loader->loadCatalogue('ru'); $mc = $catalogue->toMessageCatalogue(); - $this->assertTrue($mc->has('should_be_override')); - $this->assertSame('changed by application translation', $mc->get('should_be_override')); + self::assertTrue($mc->has('should_be_override')); + self::assertSame('changed by application translation', $mc->get('should_be_override')); } public function testLoadCatalogueNoLoader(): void @@ -161,22 +152,22 @@ public function testLoadCatalogueNoLoader(): void ])); $catalogue = $loader->loadCatalogue('RU'); - $this->assertInstanceOf(CatalogueInterface::class, $catalogue); - $this->assertSame('ru', $catalogue->getLocale()); + self::assertInstanceOf(CatalogueInterface::class, $catalogue); + self::assertSame('ru', $catalogue->getLocale()); $catalogue = $loader->loadCatalogue('ru'); - $this->assertInstanceOf(CatalogueInterface::class, $catalogue); - $this->assertSame('ru', $catalogue->getLocale()); + self::assertInstanceOf(CatalogueInterface::class, $catalogue); + self::assertSame('ru', $catalogue->getLocale()); - $this->assertCount(1, $catalogue->getDomains()); - $this->assertTrue(in_array('messages', $catalogue->getDomains())); - $this->assertFalse(in_array('views', $catalogue->getDomains())); + self::assertCount(1, $catalogue->getDomains()); + self::assertContains('messages', $catalogue->getDomains()); + self::assertNotContains('views', $catalogue->getDomains()); } public function testStaticLoader(): void { $loader = new RuntimeLoader(); - $this->assertFalse($loader->hasLocale('en')); + self::assertFalse($loader->hasLocale('en')); } public function testStaticLoaderException(): void diff --git a/tests/ManagerTest.php b/tests/ManagerTest.php index 6f49a9fa..e65aae1b 100644 --- a/tests/ManagerTest.php +++ b/tests/ManagerTest.php @@ -31,8 +31,8 @@ public function testLocalesFromLoader(): void ] ])), $cache); - $this->assertTrue($manager->has('ru')); - $this->assertTrue($manager->has('en')); + self::assertTrue($manager->has('ru')); + self::assertTrue($manager->has('en')); } public function testLocalesFromMemory(): void @@ -49,8 +49,8 @@ public function testLocalesFromMemory(): void ] ])), $cache); - $this->assertTrue($manager->has('ru')); - $this->assertTrue($manager->has('en')); + self::assertTrue($manager->has('ru')); + self::assertTrue($manager->has('en')); } public function testCatalogue(): void @@ -69,10 +69,10 @@ public function testCatalogue(): void $cache->shouldReceive('loadLocale')->with('ru')->andReturn([]); $catalogue = $manager->get('ru'); - $this->assertInstanceOf(CatalogueInterface::class, $catalogue); + self::assertInstanceOf(CatalogueInterface::class, $catalogue); - $this->assertTrue($catalogue->has('messages', 'message')); - $this->assertSame('translation', $catalogue->get('messages', 'message')); + self::assertTrue($catalogue->has('messages', 'message')); + self::assertSame('translation', $catalogue->get('messages', 'message')); $cache->shouldReceive('saveLocale')->with( 'ru', @@ -134,10 +134,10 @@ public function testFromMemory(): void $cache->shouldReceive('loadLocale')->with('ru')->andReturn([]); $catalogue = $manager->get('ru'); - $this->assertInstanceOf(CatalogueInterface::class, $catalogue); + self::assertInstanceOf(CatalogueInterface::class, $catalogue); - $this->assertTrue($catalogue->has('messages', 'message')); - $this->assertSame('new message', $catalogue->get('messages', 'message')); + self::assertTrue($catalogue->has('messages', 'message')); + self::assertSame('new message', $catalogue->get('messages', 'message')); $cache->shouldReceive('setLocales')->with(null); $cache->shouldReceive('saveLocale')->with('ru', null); diff --git a/tests/MatcherTest.php b/tests/MatcherTest.php index 46c9b2a3..aa70c166 100644 --- a/tests/MatcherTest.php +++ b/tests/MatcherTest.php @@ -13,16 +13,16 @@ class MatcherTest extends TestCase public function testIsPattern(): void { $patternizer = new Matcher(); - $this->assertFalse($patternizer->isPattern('abc')); - $this->assertTrue($patternizer->isPattern('ab*')); - $this->assertTrue($patternizer->isPattern('ab(d|e)')); + self::assertFalse($patternizer->isPattern('abc')); + self::assertTrue($patternizer->isPattern('ab*')); + self::assertTrue($patternizer->isPattern('ab(d|e)')); } #[DataProvider('patternProvider')] public function testMatch(string $string, string $pattern, bool $result): void { $matcher = new Matcher(); - $this->assertEquals($result, $matcher->matches($string, $pattern)); + self::assertSame($result, $matcher->matches($string, $pattern)); } public static function patternProvider(): \Traversable diff --git a/tests/PluralizeTest.php b/tests/PluralizeTest.php index f4bc21e8..98baed3c 100644 --- a/tests/PluralizeTest.php +++ b/tests/PluralizeTest.php @@ -20,48 +20,27 @@ class PluralizeTest extends TestCase { public function testPluralize(): void { - $this->assertSame( - '1 dog', - $this->translator()->transChoice('{n} dog|{n} dogs', 1) - ); - - $this->assertSame( - '2 dogs', - $this->translator()->transChoice('{n} dog|{n} dogs', 2) - ); - - $this->assertSame( - '2221 dogs', - $this->translator()->transChoice('{n} dog|{n} dogs', 2220, ['n' => 2221]) - ); - - $this->assertSame( - '2221 dog', - $this->translator()->transChoice('{n} dog|{n} dogs', 1, ['n' => 2221]) - ); + self::assertSame('1 dog', $this->translator()->transChoice('{n} dog|{n} dogs', 1)); + + self::assertSame('2 dogs', $this->translator()->transChoice('{n} dog|{n} dogs', 2)); + + self::assertSame('2221 dogs', $this->translator()->transChoice('{n} dog|{n} dogs', 2220, ['n' => 2221])); + + self::assertSame('2221 dog', $this->translator()->transChoice('{n} dog|{n} dogs', 1, ['n' => 2221])); } public function testInterpolation(): void { - $this->assertSame( - '20 dogs', - $this->translator()->transChoice('{n} dog and {c} cat|{n} dogs', 100, [ - 'n' => 20, - 'c' => 3 - ]) - ); - - $this->assertSame( - '1 dog and 3 cat', - $this->translator()->transChoice('{n} dog and {c} cat|{n} dogs', 1, [ - 'c' => 3 - ]) - ); - - $this->assertSame( - '2,220 dogs', - $this->translator()->transChoice('{n} dog|{n} dogs', 2, ['n' => number_format(2220)]) - ); + self::assertSame('20 dogs', $this->translator()->transChoice('{n} dog and {c} cat|{n} dogs', 100, [ + 'n' => 20, + 'c' => 3 + ])); + + self::assertSame('1 dog and 3 cat', $this->translator()->transChoice('{n} dog and {c} cat|{n} dogs', 1, [ + 'c' => 3 + ])); + + self::assertSame('2,220 dogs', $this->translator()->transChoice('{n} dog|{n} dogs', 2, ['n' => number_format(2220)])); } public function testRussian(): void @@ -69,20 +48,11 @@ public function testRussian(): void $tr = $this->translator(); $tr->setLocale('ru'); - $this->assertSame( - '1 собака', - $tr->transChoice('{n} dog|{n} dogs', 1) - ); + self::assertSame('1 собака', $tr->transChoice('{n} dog|{n} dogs', 1)); - $this->assertSame( - '2 собаки', - $tr->transChoice('{n} dog|{n} dogs', 2) - ); + self::assertSame('2 собаки', $tr->transChoice('{n} dog|{n} dogs', 2)); - $this->assertSame( - '8 собак', - $tr->transChoice('{n} dog|{n} dogs', 8) - ); + self::assertSame('8 собак', $tr->transChoice('{n} dog|{n} dogs', 8)); } public function testRussianFallback(): void @@ -90,25 +60,13 @@ public function testRussianFallback(): void $tr = $this->translator(); $tr->setLocale('ru'); - $this->assertSame( - '1 собака', - $tr->transChoice('{n} dog|{n} dogs', 1) - ); - - $this->assertSame( - '1 cat', - $tr->transChoice('{n} cat|{n} cats', 1) - ); - - $this->assertSame( - '2 cats', - $tr->transChoice('{n} cat|{n} cats', 2) - ); - - $this->assertSame( - '8 cats', - $tr->transChoice('{n} cat|{n} cats', 8) - ); + self::assertSame('1 собака', $tr->transChoice('{n} dog|{n} dogs', 1)); + + self::assertSame('1 cat', $tr->transChoice('{n} cat|{n} cats', 1)); + + self::assertSame('2 cats', $tr->transChoice('{n} cat|{n} cats', 2)); + + self::assertSame('8 cats', $tr->transChoice('{n} cat|{n} cats', 8)); } protected function translator(): Translator diff --git a/tests/TraitTest.php b/tests/TraitTest.php index d0045c51..3d41140c 100644 --- a/tests/TraitTest.php +++ b/tests/TraitTest.php @@ -26,10 +26,7 @@ class TraitTest extends TestCase { use TranslatorTrait; - /** - * @var \PHPUnit_Framework_MockObject_MockObject|ContainerInterface - */ - private $container; + private Container $container; public function setUp(): void { @@ -54,24 +51,24 @@ public function setUp(): void public function testScopeException(): void { - $this->assertSame('message', $this->say('message')); + self::assertSame('message', $this->say('message')); } public function testTranslate(): void { ContainerScope::runScope($this->container, function (): void { - $this->assertSame('message', $this->say('message')); + self::assertSame('message', $this->say('message')); }); $this->container->get(TranslatorInterface::class)->setLocale('ru'); ContainerScope::runScope($this->container, function (): void { - $this->assertSame('translation', $this->say('message')); + self::assertSame('translation', $this->say('message')); }); ContainerScope::runScope($this->container, function (): void { - $this->assertSame('translation', $this->say('[[message]]')); + self::assertSame('translation', $this->say('[[message]]')); }); } } diff --git a/tests/TranslatorTest.php b/tests/TranslatorTest.php index 35af4fda..c6b67e70 100644 --- a/tests/TranslatorTest.php +++ b/tests/TranslatorTest.php @@ -21,17 +21,17 @@ class TranslatorTest extends TestCase { public function testIsMessage(): void { - $this->assertTrue(Translator::isMessage('[[hello]]')); - $this->assertFalse(Translator::isMessage('hello')); + self::assertTrue(Translator::isMessage('[[hello]]')); + self::assertFalse(Translator::isMessage('hello')); } public function testLocale(): void { $translator = $this->translator(); - $this->assertSame('en', $translator->getLocale()); + self::assertSame('en', $translator->getLocale()); $translator->setLocale('ru'); - $this->assertSame('ru', $translator->getLocale()); + self::assertSame('ru', $translator->getLocale()); } public function testLocaleException(): void @@ -46,23 +46,23 @@ public function testDomains(): void { $translator = $this->translator(); - $this->assertSame('spiral', $translator->getDomain('spiral-views')); - $this->assertSame('messages', $translator->getDomain('vendor-views')); + self::assertSame('spiral', $translator->getDomain('spiral-views')); + self::assertSame('messages', $translator->getDomain('vendor-views')); } public function testCatalogues(): void { $translator = $this->translator(); - $this->assertCount(2, $translator->getCatalogueManager()->getLocales()); + self::assertCount(2, $translator->getCatalogueManager()->getLocales()); } public function testTrans(): void { $translator = $this->translator(); - $this->assertSame('message', $translator->trans('message')); + self::assertSame('message', $translator->trans('message')); $translator->setLocale('ru'); - $this->assertSame('translation', $translator->trans('message')); + self::assertSame('translation', $translator->trans('message')); } protected function translator(): Translator