Skip to content

Commit

Permalink
Fix #91: Add IdMessageReader that returns ID as message and doesn't…
Browse files Browse the repository at this point in the history
… support getting all messages at once
  • Loading branch information
vjik committed Nov 10, 2022
1 parent 5d20cd4 commit bc295ef
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -2,7 +2,7 @@

## 2.0.1 under development

- no changes in this release.
- New #91: Add `IdMessageReader` that returns ID as message and doesn't support getting all messages at once (@vjik)

## 2.0.0 November 08, 2022

Expand Down
23 changes: 23 additions & 0 deletions src/IdMessageReader.php
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Translator;

use RuntimeException;

/**
* ID message reader returns ID as message and doesn't support getting all messages at once.
*/
final class IdMessageReader implements MessageReaderInterface
{
public function getMessage(string $id, string $category, string $locale, array $parameters = []): string
{
return $id;
}

public function getMessages(string $category, string $locale): array
{
throw new RuntimeException('IdMessageReader doesn\'t support getting all messages at once.');
}
}
28 changes: 28 additions & 0 deletions tests/IdMessageReaderTest.php
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Translator\Tests;

use PHPUnit\Framework\TestCase;
use RuntimeException;
use Yiisoft\Translator\IdMessageReader;

final class IdMessageReaderTest extends TestCase
{
public function testGetMessage(): void
{
$reader = new IdMessageReader();

$this->assertSame('test', $reader->getMessage('test', 'my-module', 'en_US'));
}

public function testGetMessages(): void
{
$reader = new IdMessageReader();

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('IdMessageReader doesn\'t support getting all messages at once');
$reader->getMessages('my-module', 'en_US');
}
}

0 comments on commit bc295ef

Please sign in to comment.