Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark authored and StyleCIBot committed Nov 20, 2020
1 parent 3b2cc49 commit e99af56
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
16 changes: 10 additions & 6 deletions src/MessageSource.php
Expand Up @@ -61,11 +61,13 @@ private function readFromDb(string $category, string $locale): array
$query = (new Query($this->db))
->select(['message_id', 'translation'])
->from(['ts' => $this->sourceMessageTable])
->innerJoin(['td' => $this->messageTable],
->innerJoin(
['td' => $this->messageTable],
[
'td.id' => new Expression('[[ts.id]]'),
'ts.category' => $category
])
'ts.category' => $category,
]
)
->where([
'locale' => $locale,
]);
Expand All @@ -89,8 +91,9 @@ public function write(string $category, string $locale, array $messages): void
foreach ($messages as $messageId => $translation) {
if (!isset($sourceMessages[$messageId])) {
$result = $this->db->getSchema()->insert($this->sourceMessageTable, ['category' => $category, 'message_id' => $messageId]);
if ($result === false)
if ($result === false) {
throw new \RuntimeException('Can not create source message with id ' . $messageId);
}
$sourceMessages[$messageId] = $result['id'];
}

Expand All @@ -102,8 +105,9 @@ public function write(string $category, string $locale, array $messages): void

if ($needUpdate || !isset($translatedMessages[$messageId])) {
$result = $this->db->getSchema()->insert($this->messageTable, ['id' => $sourceMessages[$messageId], 'locale' => $locale, 'translation' => $translation]);
if ($result === false)
if ($result === false) {
throw new \RuntimeException('Can not create source message with id ' . $messageId);
}
}
}
}
Expand All @@ -113,7 +117,7 @@ private function getCacheKey(string $category, string $locale): string
$key = [
__CLASS__,
$category,
$locale
$locale,
];

$jsonKey = json_encode($key);
Expand Down
21 changes: 10 additions & 11 deletions tests/MessageSourceTest.php
Expand Up @@ -10,25 +10,24 @@
use Psr\Log\NullLogger;
use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Yiisoft\Aliases\Aliases;
use Yiisoft\Cache\ArrayCache;
use Yiisoft\Cache\Cache;
use Yiisoft\Cache\CacheInterface;
use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Sqlite\Connection;
use Yiisoft\Di\Container;
use Yiisoft\Translator\Message\Db\MessageSource;
use Yiisoft\Factory\Definitions\Reference;
use Yiisoft\Translator\Message\Db\MessageSource;
use Yiisoft\Yii\Console\Application;
use Yiisoft\Yii\Db\Migration\Command\DownCommand;
use Yiisoft\Yii\Db\Migration\Command\UpdateCommand;
use Yiisoft\Yii\Db\Migration\Helper\ConsoleHelper;
use Yiisoft\Yii\Db\Migration\Service\MigrationService;
use Symfony\Component\Console\Tester\CommandTester;

final class MessageSourceTest extends TestCase
{

private ContainerInterface $container;
private Application $application;
private Aliases $aliases;
Expand Down Expand Up @@ -74,15 +73,15 @@ public function generateTranslationsData(): array
'test.id1' => 'app: Test 1 on the (de)',
'test.id2' => 'app: Test 2 on the (de)',
'test.id3' => 'app: Test 3 on the (de)',
]
],
],
[
'app',
'de-DE',
[
'test.id1' => 'app: Test 1 on the (de-DE)',
'test.id2' => 'app: Test 2 on the (de-DE)',
]
],
],
];
}
Expand Down Expand Up @@ -113,7 +112,7 @@ public function testMultiWrite(): void

foreach ($allData as $fileData) {
[$category, $locale, $data] = $fileData;
foreach ($data as $id=>$value) {
foreach ($data as $id => $value) {
$this->assertEquals($value, $messageSource->getMessage($id, $category, $locale));
}
}
Expand All @@ -132,7 +131,7 @@ public function testMultiWriteWithCache(): void

foreach ($allData as $fileData) {
[$category, $locale, $data] = $fileData;
foreach ($data as $id=>$value) {
foreach ($data as $id => $value) {
$this->assertEquals($value, $messageSource->getMessage($id, $category, $locale));
}
}
Expand Down Expand Up @@ -166,12 +165,12 @@ private function config(): array
return [
Aliases::class => [
'@root' => dirname(__DIR__, 1),
'@yiisoft/yii/db/migration' => dirname(__DIR__, 1)
'@yiisoft/yii/db/migration' => dirname(__DIR__, 1),
],

Cache::class => [
'__class' => Cache::class,
'__construct()' => [Reference::to(ArrayCache::class)]
'__construct()' => [Reference::to(ArrayCache::class)],
],

CacheInterface::class => Cache::class,
Expand All @@ -181,8 +180,8 @@ private function config(): array
ConnectionInterface::class => [
'__class' => Connection::class,
'__construct()' => [
'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3'
]
'dsn' => 'sqlite:' . __DIR__ . '/Data/yiitest.sq3',
],
],
];
}
Expand Down
3 changes: 3 additions & 0 deletions tests/Migration.php
@@ -1,11 +1,14 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Translator\Message\Db\Tests;

use Yiisoft\Yii\Db\Migration\Migration as BaseMigration;

/**
* Stub Migration class
*
* @package Yiisoft\Yii\Db\Migration\Tests
*/
class Migration extends BaseMigration
Expand Down

0 comments on commit e99af56

Please sign in to comment.