|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Budgegeria\Bundle\IntlBundle\Tests\Twig; |
| 6 | + |
| 7 | +use Budgegeria\Bundle\IntlBundle\Twig\IntlFormatterExtension; |
| 8 | +use Budgegeria\IntlFormat\Factory; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use Twig\Environment; |
| 11 | +use Twig\Loader\ArrayLoader; |
| 12 | + |
| 13 | +class TwigExtensionTest extends TestCase |
| 14 | +{ |
| 15 | + /** @test */ |
| 16 | + public function intlFormatFilterFormat(): void |
| 17 | + { |
| 18 | + $twig = $this->createTwigEnv(); |
| 19 | + |
| 20 | + self::assertInstanceOf(Environment::class, $twig); |
| 21 | + |
| 22 | + self::assertSame('This is the 4 time that the number 6.000 appear', $twig->render('intlformat-filter-format')); |
| 23 | + } |
| 24 | + |
| 25 | + /** @test */ |
| 26 | + public function intlFormatFunctionFormat(): void |
| 27 | + { |
| 28 | + $twig = $this->createTwigEnv(); |
| 29 | + |
| 30 | + self::assertInstanceOf(Environment::class, $twig); |
| 31 | + |
| 32 | + self::assertSame('This is the 4 time that the number 6.000 appear', $twig->render('intlformat-function-format')); |
| 33 | + } |
| 34 | + |
| 35 | + /** @test */ |
| 36 | + public function intlFormatCurrency(): void |
| 37 | + { |
| 38 | + $twig = $this->createTwigEnv(); |
| 39 | + |
| 40 | + self::assertInstanceOf(Environment::class, $twig); |
| 41 | + |
| 42 | + self::assertSame('€', $twig->render('intlformat-function-curreny')); |
| 43 | + } |
| 44 | + |
| 45 | + private function createTwigEnv(): Environment |
| 46 | + { |
| 47 | + $templates = [ |
| 48 | + 'intlformat-filter-format' => '{{ "This is the %integer time that the number %integer appear"|intl_format(4, 6000) }}', |
| 49 | + 'intlformat-function-format' => '{{ intl_format("This is the %integer time that the number %integer appear", 4, 6000) }}', |
| 50 | + 'intlformat-function-curreny' => '{{ currency_symbol() }}', |
| 51 | + ]; |
| 52 | + |
| 53 | + $loader = new ArrayLoader($templates); |
| 54 | + $twig = new Environment($loader); |
| 55 | + $twig->addExtension(new IntlFormatterExtension((new Factory())->createIntlFormat('de_DE'), 'EUR')); |
| 56 | + |
| 57 | + return $twig; |
| 58 | + } |
| 59 | +} |
0 commit comments