From ea8d3498d05c3f39b45991dd79a812d3db54ec37 Mon Sep 17 00:00:00 2001 From: bocharsky-bw Date: Mon, 29 Jan 2024 17:22:39 +0100 Subject: [PATCH] Drop bad files --- tests/Unit/Storage/ChainStorageTest.php | 114 ------------ tests/Unit/Storage/FileStorageTest.php | 233 ------------------------ tests/Unit/XliffConverterTest.php | 41 ----- 3 files changed, 388 deletions(-) delete mode 100644 tests/Unit/Storage/ChainStorageTest.php delete mode 100644 tests/Unit/Storage/FileStorageTest.php delete mode 100644 tests/Unit/XliffConverterTest.php diff --git a/tests/Unit/Storage/ChainStorageTest.php b/tests/Unit/Storage/ChainStorageTest.php deleted file mode 100644 index 0fc54fb..0000000 --- a/tests/Unit/Storage/ChainStorageTest.php +++ /dev/null @@ -1,114 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Translation\common\tests\Unit\Storage; - -use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; -use Symfony\Component\Translation\MessageCatalogueInterface; -use Translation\Common\Model\Message; -use Translation\Common\Storage\ChainStorage; -use Translation\Common\Storage\StorageInterface; - -class ChainStorageTest extends TestCase -{ - use ProphecyTrait; - private $childStorage1; - private $childStorage2; - private $storage; - - protected function setUp(): void - { - $this->childStorage1 = $this->prophesize(StorageInterface::class); - $this->childStorage2 = $this->prophesize(StorageInterface::class); - - $this->storage = new ChainStorage(); - $this->storage->addStorage($this->childStorage1->reveal()); - $this->storage->addStorage($this->childStorage2->reveal()); - } - - public function testGetWithMessageInFirstStorage() - { - $expectedMessage = new Message('PHP Translation IS awesome!'); - - $this->childStorage1->get('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1)->willReturn($expectedMessage); - $this->childStorage2->get('en', 'messages', 'php_translation_is_awesome')->shouldNotBeCalled(); - - $message = $this->storage->get('en', 'messages', 'php_translation_is_awesome'); - $this->assertSame($expectedMessage, $message); - } - - public function testGetWithMessageInSecondStorage() - { - $expectedMessage = new Message('PHP Translation IS awesome!'); - - $this->childStorage1->get('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1)->willReturn(null); - $this->childStorage2->get('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1)->willReturn($expectedMessage); - - $message = $this->storage->get('en', 'messages', 'php_translation_is_awesome'); - $this->assertSame($expectedMessage, $message); - } - - public function testGetWithMessageNotFound() - { - $this->childStorage1->get('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1)->willReturn(null); - $this->childStorage2->get('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1)->willReturn(null); - - $message = $this->storage->get('en', 'messages', 'php_translation_is_awesome'); - $this->assertNull($message); - } - - public function testCreateCallAllStorages() - { - $message = new Message('PHP Translation IS awesome!'); - - $this->childStorage1->create($message)->shouldBeCalledtimes(1); - $this->childStorage2->create($message)->shouldBeCalledtimes(1); - - $this->storage->create($message); - } - - public function testUpdateCallAllStorages() - { - $message = new Message('PHP Translation IS awesome!'); - - $this->childStorage1->update($message)->shouldBeCalledtimes(1); - $this->childStorage2->update($message)->shouldBeCalledtimes(1); - - $this->storage->update($message); - } - - public function testDeleteCallAllStorages() - { - $this->childStorage1->delete('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1); - $this->childStorage2->delete('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1); - - $this->storage->delete('en', 'messages', 'php_translation_is_awesome'); - } - - public function testExportCallOnlyTransferrableStorage() - { - $messageCatalogue = $this->prophesize(MessageCatalogueInterface::class)->reveal(); - - $this->childStorage2->export($messageCatalogue, [])->shouldBeCalledtimes(1); - - $this->storage->export($messageCatalogue, []); - } - - public function testImportCallOnlyTransferrableStorage() - { - $messageCatalogue = $this->prophesize(MessageCatalogueInterface::class)->reveal(); - - $this->childStorage2->import($messageCatalogue, [])->shouldBeCalledtimes(1); - - $this->storage->import($messageCatalogue, []); - } -} diff --git a/tests/Unit/Storage/FileStorageTest.php b/tests/Unit/Storage/FileStorageTest.php deleted file mode 100644 index 7b0afb1..0000000 --- a/tests/Unit/Storage/FileStorageTest.php +++ /dev/null @@ -1,233 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Translation\Common\Tests\Unit\Storage; - -use PHPUnit\Framework\TestCase; -use Symfony\Component\Translation\Loader\XliffFileLoader; -use Symfony\Component\Translation\MessageCatalogue; -use Symfony\Component\Translation\MessageCatalogueInterface; -use Symfony\Component\Translation\Reader\TranslationReader; -use Symfony\Component\Translation\Writer\TranslationWriter; -use Translation\Common\Model\Message; -use Translation\Common\Storage\FileStorage; - -/** - * @author Tobias Nyholm - */ -class FileStorageTest extends TestCase -{ - public function testConstructor() - { - $storage = new FileStorage(new TranslationWriter(), $this->createTranslationLoader(), ['foo']); - $this->assertInstanceOf(FileStorage::class, $storage); - } - - public function testConstructorEmptyArray() - { - $this->expectException(\LogicException::class); - - new FileStorage(new TranslationWriter(), $this->createTranslationLoader(), []); - } - - public function testCreateNewCatalogue() - { - $writer = $this->getMockBuilder(TranslationWriter::class) - ->onlyMethods([$this->getMethodNameToWriteTranslations()]) - ->disableOriginalConstructor() - ->getMock(); - $writer->expects($this->once()) - ->method($this->getMethodNameToWriteTranslations()) - ->with( - $this->isInstanceOf(MessageCatalogueInterface::class), - 'xlf', - ['path' => 'foo', 'xliff_version' => '2.0'] - ); - - $storage = new FileStorage($writer, $this->createTranslationLoader(), ['foo']); - $storage->create(new Message('key', 'domain', 'en', 'Message')); - - $writer = $this->getMockBuilder(TranslationWriter::class) - ->onlyMethods([$this->getMethodNameToWriteTranslations()]) - ->disableOriginalConstructor() - ->getMock(); - $writer->expects($this->once()) - ->method($this->getMethodNameToWriteTranslations()) - ->with( - $this->isInstanceOf(MessageCatalogueInterface::class), - 'format', - ['path' => 'bar', 'default_output_format' => 'format', 'xliff_version' => '2.0'] - ); - - $storage = new FileStorage($writer, $this->createTranslationLoader(), ['bar'], ['default_output_format' => 'format']); - $storage->create(new Message('key', 'domain', 'en', 'Message')); - } - - public function testCreateExistingCatalogue() - { - $writer = $this->getMockBuilder(TranslationWriter::class) - ->onlyMethods([$this->getMethodNameToWriteTranslations()]) - ->disableOriginalConstructor() - ->getMock(); - $writer->expects($this->once()) - ->method($this->getMethodNameToWriteTranslations()) - ->with( - $this->isInstanceOf(MessageCatalogueInterface::class), - 'xlf', - ['path' => $this->getFixturePath(), 'xliff_version' => '2.0'] - ); - - $loader = $this->createTranslationLoader(); - $loader->addLoader('xlf', new XliffFileLoader()); - $storage = new FileStorage($writer, $loader, ['foo', $this->getFixturePath()]); - - $storage->create(new Message('key', 'messages', 'en', 'Translation')); - } - - public function testGet() - { - $writer = $this->getMockBuilder(TranslationWriter::class) - ->disableOriginalConstructor() - ->getMock(); - - $loader = $this->createTranslationLoader(); - $loader->addLoader('xlf', new XliffFileLoader()); - $storage = new FileStorage($writer, $loader, [$this->getFixturePath()]); - - $this->assertEquals('Bazbar', $storage->get('en', 'messages', 'test_1')->getTranslation()); - - // Missing locale - $this->assertEquals('test_1', $storage->get('sv', 'messages', 'test_1')->getTranslation()); - - // Missing domain - $this->assertEquals('test_1', $storage->get('en', 'xx', 'test_1')->getTranslation()); - - // Missing key - $this->assertEquals('miss', $storage->get('en', 'messages', 'miss')->getTranslation()); - } - - public function testUpdate() - { - $writer = $this->getMockBuilder(TranslationWriter::class) - ->onlyMethods([$this->getMethodNameToWriteTranslations()]) - ->disableOriginalConstructor() - ->getMock(); - $writer->expects($this->exactly(2)) - ->method($this->getMethodNameToWriteTranslations()) - ->with( - $this->isInstanceOf(MessageCatalogueInterface::class), - 'xlf', - ['path' => $this->getFixturePath(), 'xliff_version' => '2.0'] - ); - - $loader = $this->createTranslationLoader(); - $loader->addLoader('xlf', new XliffFileLoader()); - $storage = new FileStorage($writer, $loader, [$this->getFixturePath()]); - - $storage->update(new Message('key', 'messages', 'en', 'Translation')); - $storage->update(new Message('test_1', 'messages', 'en', 'Translation')); - } - - public function testDelete() - { - $writer = $this->getMockBuilder(TranslationWriter::class) - ->onlyMethods([$this->getMethodNameToWriteTranslations()]) - ->disableOriginalConstructor() - ->getMock(); - - $writer->expects($this->once()) - ->method($this->getMethodNameToWriteTranslations()) - ->with( - $this->callback(function (MessageCatalogueInterface $catalogue) { - return !$catalogue->defines('test_0', 'messages'); - }), - 'xlf', - ['path' => $this->getFixturePath(), 'xliff_version' => '2.0'] - ); - - $loader = $this->createTranslationLoader(); - $loader->addLoader('xlf', new XliffFileLoader()); - $storage = new FileStorage($writer, $loader, [$this->getFixturePath()]); - - $storage->delete('en', 'messages', 'test_0'); - } - - public function testImport() - { - $writer = $this->getMockBuilder(TranslationWriter::class) - ->onlyMethods([$this->getMethodNameToWriteTranslations()]) - ->disableOriginalConstructor() - ->getMock(); - - $writer->expects($this->once()) - ->method($this->getMethodNameToWriteTranslations()) - ->with( - $this->callback(function (MessageCatalogueInterface $catalogue) { - return $catalogue->defines('test_4711', 'messages'); - }), - 'xlf', - ['path' => $this->getFixturePath(), 'xliff_version' => '2.0'] - ); - - $loader = $this->createTranslationLoader(); - $loader->addLoader('xlf', new XliffFileLoader()); - $storage = new FileStorage($writer, $loader, [$this->getFixturePath()]); - $catalogue = new MessageCatalogue('en', ['messages' => ['test_4711' => 'foobar']]); - - $storage->import($catalogue); - } - - public function testExport() - { - $writer = $this->getMockBuilder(TranslationWriter::class) - ->disableOriginalConstructor() - ->getMock(); - - $loader = $this->createTranslationLoader(); - $loader->addLoader('xlf', new XliffFileLoader()); - $storage = new FileStorage($writer, $loader, [$this->getFixturePath()]); - - $catalogue = new MessageCatalogue('en'); - $storage->export($catalogue); - $this->assertTrue($catalogue->defines('test_0', 'messages')); - $this->assertTrue($catalogue->defines('test_1', 'messages')); - - // Wrong locale - $catalogue = new MessageCatalogue('sv'); - $storage->export($catalogue); - $this->assertFalse($catalogue->defines('test_0', 'messages')); - } - - /** - * @return string - */ - private function getFixturePath() - { - return realpath(__DIR__.'/../../Fixtures/single-file'); - } - - /** - * @return TranslationReader - */ - private function createTranslationLoader() - { - return new TranslationReader(); - } - - private function getMethodNameToWriteTranslations() - { - if (method_exists(TranslationWriter::class, 'write')) { - return 'write'; - } - - return 'writeTranslations'; - } -} diff --git a/tests/Unit/XliffConverterTest.php b/tests/Unit/XliffConverterTest.php deleted file mode 100644 index 351c0c9..0000000 --- a/tests/Unit/XliffConverterTest.php +++ /dev/null @@ -1,41 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Translation\Common\Tests\Unit; - -use PHPUnit\Framework\TestCase; -use Symfony\Component\Translation\MessageCatalogue; -use Translation\Common\XliffConverter; - -/** - * @author Tobias Nyholm - */ -class XliffConverterTest extends TestCase -{ - public function testContentToCatalogue() - { - $content = file_get_contents(__DIR__.'/../Fixtures/single-file/messages.en.xlf'); - $catalogue = XliffConverter::contentToCatalogue($content, 'en', 'messages'); - - $this->assertEquals('en', $catalogue->getLocale()); - $this->assertEquals(['messages'], $catalogue->getDomains()); - $this->assertCount(2, $catalogue->all('messages')); - } - - public function testCatalogueToContent() - { - $catalogue = new MessageCatalogue('en'); - $catalogue->add(['foobar' => 'bar']); - $content = XliffConverter::catalogueToContent($catalogue, 'messages'); - - $this->assertMatchesRegularExpression('/foobar/', $content); - } -}