Skip to content

Commit

Permalink
Improve code coverage (#61)
Browse files Browse the repository at this point in the history
* Improve code coverage

* Apply fixes from StyleCI

---------

Co-authored-by: StyleCI Bot <bot@styleci.io>
  • Loading branch information
darkdef and StyleCIBot committed May 8, 2023
1 parent 83d712f commit 2bb84d2
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/Common/AbstractMessageSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<array{0: string, 1: string, 2: array<string, array<string, string>>}>
*/
Expand Down

0 comments on commit 2bb84d2

Please sign in to comment.