From 2bb84d2acd4a9b1ca4080f15169501a0dc84730c Mon Sep 17 00:00:00 2001 From: Valerii Gorbachev Date: Mon, 8 May 2023 20:44:24 +0300 Subject: [PATCH] Improve code coverage (#61) * Improve code coverage * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot --- tests/Common/AbstractMessageSourceTest.php | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/Common/AbstractMessageSourceTest.php b/tests/Common/AbstractMessageSourceTest.php index 94a96c7..84d5936 100644 --- a/tests/Common/AbstractMessageSourceTest.php +++ b/tests/Common/AbstractMessageSourceTest.php @@ -6,15 +6,18 @@ use JsonException; use PHPUnit\Framework\TestCase; +use RuntimeException; use Throwable; use Yiisoft\Cache\ArrayCache; use Yiisoft\Cache\Cache; use Yiisoft\Cache\CacheInterface; +use Yiisoft\Db\Command\CommandInterface; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidArgumentException; use Yiisoft\Db\Exception\InvalidCallException; use Yiisoft\Db\Exception\InvalidConfigException; +use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; use Yiisoft\Translator\Message\Db\DbSchemaManager; use Yiisoft\Translator\Message\Db\MessageSource; @@ -235,6 +238,40 @@ public function testReadMessages(string $category, string $locale, array $data): $this->assertEquals($messages, $data); } + public function testReadMessageError(): void + { + $qbMock = $this->createMock(QueryBuilderInterface::class); + $qbMock->expects(self::atLeastOnce()) + ->method('build') + ->willReturn(['', []]); + + $commandMock = $this->createMock(CommandInterface::class); + $commandMock->expects(self::once()) + ->method('insertWithReturningPks') + ->willReturn(false); + $commandMock->expects(self::atLeastOnce()) + ->method('queryAll') + ->willReturn([]); + + $dbMock = $this->createMock(ConnectionInterface::class); + $dbMock->expects(self::atLeastOnce()) + ->method('createCommand') + ->willReturn($commandMock); + $dbMock->expects(self::atLeastOnce()) + ->method('getQueryBuilder') + ->willReturn($qbMock); + + $messageSource = new MessageSource($dbMock); + + $this->expectException(RuntimeException::class); + $messageSource->write('app', 'de', [ + 'test.id1' => [ + 'comment' => 'Translate wisely!', + 'message' => 'app: Test 1 on the (de)', + ], + ]); + } + /** * @psalm-return array>}> */