Skip to content

Commit

Permalink
prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
spiralbot committed Jan 22, 2025
1 parent 958b94e commit 4978235
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 164 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
6 changes: 3 additions & 3 deletions tests/AutoRegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 22 additions & 22 deletions tests/CatalogueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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',
],
Expand All @@ -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
Expand All @@ -113,20 +113,20 @@ 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
{
$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
Expand All @@ -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());
}
}
50 changes: 25 additions & 25 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function testDefaultLocale(): void
'locale' => 'ru'
]);

self::assertSame('ru', $config->getDefaultLocale());
$this->assertSame('ru', $config->getDefaultLocale());
}

public function testDefaultDomain(): void
Expand All @@ -28,7 +28,7 @@ public function testDefaultDomain(): void
'locale' => 'ru'
]);

self::assertSame('messages', $config->getDefaultDomain());
$this->assertSame('messages', $config->getDefaultDomain());
}

public function testFallbackLocale(): void
Expand All @@ -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
Expand All @@ -59,7 +59,7 @@ public function testLocalesDirectory(): void
'localesDirectory' => 'directory/'
]);

self::assertSame('directory/', $config->getLocalesDirectory());
$this->assertSame('directory/', $config->getLocalesDirectory());
}

public function testLocaleDirectory(): void
Expand All @@ -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
Expand All @@ -77,28 +77,28 @@ public function testLocaleDirectoryShort(): void
'directory' => 'directory/'
]);

self::assertSame('directory/ru/', $config->getLocaleDirectory('ru'));
$this->assertSame('directory/ru/', $config->getLocaleDirectory('ru'));
}

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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -135,7 +135,7 @@ public function testDomainsFallback(): void
]
]);

self::assertSame('external', $config->resolveDomain('external'));
$this->assertSame('external', $config->resolveDomain('external'));
}

public function testHasLoader(): void
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -173,20 +173,20 @@ 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' => [
'foo',
'bar/'
]
]);
self::assertSame(['foo', 'bar/'], $config->getDirectories());
$this->assertSame(['foo', 'bar/'], $config->getDirectories());
}
}
22 changes: 11 additions & 11 deletions tests/IndexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
15 changes: 12 additions & 3 deletions tests/InterpolateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 4978235

Please sign in to comment.