generated from yiisoft/package-template
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
… support getting all messages at once
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} | ||
} |