Passed
Pull Request — master (#416)
by Sergei
02:35
created

ConfigTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
dl 0
loc 21
rs 10
c 3
b 1
f 0
eloc 9
wmc 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ testSimpleMessageFormatter() 0 19 1
A hp$0 ➔ format() 0 3 1
testSimpleMessageFormatter() 0 19 ?
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Validator\Tests\TestEnvironments\WithoutIntl;
6
7
use Yiisoft\Translator\CategorySource;
8
use Yiisoft\Translator\MessageFormatterInterface;
9
use Yiisoft\Validator\Tests\BaseConfigTest;
10
11
final class ConfigTest extends BaseConfigTest
12
{
13
    public function testSimpleMessageFormatter(): void
14
    {
15
        $container = $this->createContainer();
16
17
        $customFormatter = new class () implements MessageFormatterInterface {
18
            public function format(string $message, array $parameters, string $locale): string
19
            {
20
                return 'test';
21
            }
22
        };
23
24
        /** @var CategorySource $translationCategorySource */
25
        $translationCategorySource = $container->get('[email protected]')[0];
26
        $message = '{n, selectordinal, one{#-one} two{#-two} few{#-few} other{#-other}}';
27
28
        // The default formatter argument is ignored in favor of formatter set in config.
29
        $this->assertSame(
30
            '1',
31
            $translationCategorySource->format($message, ['n' => 1], 'en', $customFormatter),
32
        );
33
    }
34
}
35