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