|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Jfcherng\Diff\Utility\Test; |
| 6 | + |
| 7 | +use Jfcherng\Diff\Exception\FileNotFoundException; |
| 8 | +use Jfcherng\Diff\Utility\Language; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | + |
| 11 | +/** |
| 12 | + * @coversNothing |
| 13 | + */ |
| 14 | +class LanguageTest extends TestCase |
| 15 | +{ |
| 16 | + /** |
| 17 | + * The Language object. |
| 18 | + * |
| 19 | + * @var \Jfcherng\Diff\Utility\Language |
| 20 | + */ |
| 21 | + protected $languageObj; |
| 22 | + |
| 23 | + /** |
| 24 | + * Set up the test environment. |
| 25 | + */ |
| 26 | + protected function setUp(): void |
| 27 | + { |
| 28 | + $this->languageObj = new Language('eng'); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * Test the Language::setLanguageOrTranslations. |
| 33 | + * |
| 34 | + * @covers \Jfcherng\Diff\Utility\Language::setLanguageOrTranslations |
| 35 | + */ |
| 36 | + public function testSetLanguageOrTranslations(): void |
| 37 | + { |
| 38 | + $this->languageObj->setLanguageOrTranslations('eng'); |
| 39 | + $this->assertArrayHasKey( |
| 40 | + 'differences', |
| 41 | + $this->languageObj->getTranslations() |
| 42 | + ); |
| 43 | + |
| 44 | + $this->languageObj->setLanguageOrTranslations(['hahaha' => '哈哈哈']); |
| 45 | + $this->assertArrayHasKey( |
| 46 | + 'hahaha', |
| 47 | + $this->languageObj->getTranslations() |
| 48 | + ); |
| 49 | + |
| 50 | + $this->expectException(\InvalidArgumentException::class); |
| 51 | + $this->languageObj->setLanguageOrTranslations(5); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Test the Language::getTranslationsByLanguage. |
| 56 | + * |
| 57 | + * @covers \Jfcherng\Diff\Utility\Language::getTranslationsByLanguage |
| 58 | + */ |
| 59 | + public function testGetTranslationsByLanguage(): void |
| 60 | + { |
| 61 | + $this->assertArrayHasKey( |
| 62 | + 'differences', |
| 63 | + $this->languageObj->getTranslationsByLanguage('eng') |
| 64 | + ); |
| 65 | + |
| 66 | + $this->expectException(FileNotFoundException::class); |
| 67 | + $this->languageObj->getTranslationsByLanguage('a_non_existing_language'); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Test the Language::translate. |
| 72 | + * |
| 73 | + * @covers \Jfcherng\Diff\Utility\Language::translate |
| 74 | + */ |
| 75 | + public function testTranslate(): void |
| 76 | + { |
| 77 | + $this->assertSame( |
| 78 | + 'Differences', |
| 79 | + $this->languageObj->translate('differences') |
| 80 | + ); |
| 81 | + |
| 82 | + $this->assertStringMatchesFormat( |
| 83 | + '![%s]', |
| 84 | + $this->languageObj->translate('a_non_existing_translation') |
| 85 | + ); |
| 86 | + } |
| 87 | +} |
0 commit comments