|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Respect\StringFormatter\Test\Unit; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 8 | +use PHPUnit\Framework\Attributes\Test; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use Respect\StringFormatter\BypassTranslator; |
| 11 | + |
| 12 | +#[CoversClass(BypassTranslator::class)] |
| 13 | +final class BypassTranslatorTest extends TestCase |
| 14 | +{ |
| 15 | + private BypassTranslator $translator; |
| 16 | + |
| 17 | + protected function setUp(): void |
| 18 | + { |
| 19 | + parent::setUp(); |
| 20 | + |
| 21 | + $this->translator = new BypassTranslator(); |
| 22 | + } |
| 23 | + |
| 24 | + #[Test] |
| 25 | + public function itShouldReturnOriginalIdForTranslation(): void |
| 26 | + { |
| 27 | + $id = 'some.translation.key'; |
| 28 | + $parameters = ['param1' => 'value1']; |
| 29 | + $domain = 'messages'; |
| 30 | + $locale = 'en'; |
| 31 | + |
| 32 | + $result = $this->translator->trans($id, $parameters, $domain, $locale); |
| 33 | + |
| 34 | + self::assertSame($id, $result); |
| 35 | + } |
| 36 | + |
| 37 | + #[Test] |
| 38 | + public function itShouldReturnOriginalIdForTranslationWithMinimalParameters(): void |
| 39 | + { |
| 40 | + $id = 'simple.key'; |
| 41 | + |
| 42 | + $result = $this->translator->trans($id); |
| 43 | + |
| 44 | + self::assertSame($id, $result); |
| 45 | + } |
| 46 | + |
| 47 | + #[Test] |
| 48 | + public function itShouldReturnOriginalIdForTranslationWithEmptyParameters(): void |
| 49 | + { |
| 50 | + $id = 'key.with.no.params'; |
| 51 | + |
| 52 | + $result = $this->translator->trans($id, []); |
| 53 | + |
| 54 | + self::assertSame($id, $result); |
| 55 | + } |
| 56 | + |
| 57 | + #[Test] |
| 58 | + public function itShouldReturnOriginalIdForTranslationWithNullDomainAndLocale(): void |
| 59 | + { |
| 60 | + $id = 'key.with.nulls'; |
| 61 | + |
| 62 | + $result = $this->translator->trans($id, ['param' => 'value'], null, null); |
| 63 | + |
| 64 | + self::assertSame($id, $result); |
| 65 | + } |
| 66 | + |
| 67 | + #[Test] |
| 68 | + public function itShouldAlwaysReturnEnglishAsDefaultLocale(): void |
| 69 | + { |
| 70 | + $locale = $this->translator->getLocale(); |
| 71 | + |
| 72 | + self::assertSame('en', $locale); |
| 73 | + } |
| 74 | + |
| 75 | + #[Test] |
| 76 | + public function itShouldHandleEmptyStringTranslation(): void |
| 77 | + { |
| 78 | + $result = $this->translator->trans(''); |
| 79 | + |
| 80 | + self::assertSame('', $result); |
| 81 | + } |
| 82 | + |
| 83 | + #[Test] |
| 84 | + public function itShouldHandleComplexTranslationKeyId(): void |
| 85 | + { |
| 86 | + $complexId = 'nested.deep.very.complex.translation.key.with.dots'; |
| 87 | + |
| 88 | + $result = $this->translator->trans($complexId, ['param' => 'value'], 'domain', 'fr_FR'); |
| 89 | + |
| 90 | + self::assertSame($complexId, $result); |
| 91 | + } |
| 92 | + |
| 93 | + #[Test] |
| 94 | + public function itShouldHandleSpecialCharactersInTranslationKey(): void |
| 95 | + { |
| 96 | + $specialId = 'key.with-special_chars@123#$%'; |
| 97 | + |
| 98 | + $result = $this->translator->trans($specialId); |
| 99 | + |
| 100 | + self::assertSame($specialId, $result); |
| 101 | + } |
| 102 | +} |
0 commit comments