TranslatorTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 75
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testTranslate() 0 5 1
A canTranslateProvider() 0 8 1
A testCanTranslate() 0 5 1
A setUp() 0 5 1
A translateProvider() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\I18n;
6
7
use PHPUnit\Framework\TestCase;
8
9
class TranslatorTest extends TestCase
10
{
11
    /** @var Translator - System Under Test */
12
    protected Translator $sut;
13
14
    /**
15
     * @var array[]
16
     */
17
    protected array $translationData = [
18
        'foo' => [
19
            'bar'        => 'baz',
20
            'replacable' => 'baz %2$s %1$s',
21
        ],
22
    ];
23
24
    public function setUp(): void
25
    {
26
        parent::setUp();
27
28
        $this->sut = new Translator($this->translationData);
29
    }
30
31
    /**
32
     * @return array[]
33
     */
34
    public function translateProvider(): array
35
    {
36
        return [
37
            ['foo:bar', [], 'baz'],
38
            ['foo:replacable', ['second', 'first'], 'baz first second'],
39
            ['foo:replacable', ['foo:bar', 'first'], 'baz first baz'],
40
        ];
41
    }
42
43
    /**
44
     * @dataProvider translateProvider
45
     *
46
     * @param string $expression
47
     * @param array  $args
48
     * @param string $expectedResult
49
     */
50
    public function testTranslate(string $expression, array $args, string $expectedResult): void
51
    {
52
        $actualResult = $this->sut->translate($expression, ...$args);
53
54
        $this->assertEquals($expectedResult, $actualResult);
55
    }
56
57
58
    /**
59
     * @return array[]
60
     */
61
    public function canTranslateProvider(): array
62
    {
63
        return [
64
            ['foo:bar', [], true],
65
            ['foo', [], false],
66
            ['foo:bar:baz', [], false],
67
            ['foo:replacable', ['second', 'first'], true],
68
            ['foo:replacable', ['foo:bar', 'first'], true],
69
        ];
70
    }
71
72
    /**
73
     * @dataProvider canTranslateProvider
74
     *
75
     * @param string $expression
76
     * @param array  $args
77
     * @param bool   $expectedResult
78
     */
79
    public function testCanTranslate(string $expression, array $args, bool $expectedResult): void
80
    {
81
        $actualResult = $this->sut->canTranslate($expression, ...$args);
82
83
        $this->assertEquals($expectedResult, $actualResult);
84
    }
85
}
86