FileTranslatorTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 56
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructCorrectInstance() 0 6 1
A testConstructThrowsUpOnUnsupportedLanguage() 0 7 1
A testConstructThrowsUpOnInvalidTranslationFile() 0 7 1
A testTranslateWIthInvalidKey() 0 6 1
A testTranslateWIthValidKey() 0 6 1
1
<?php
2
3
namespace OpCacheGUITest\Unit\I18n;
4
5
use OpCacheGUI\I18n\FileTranslator;
6
use OpCacheGUI\I18n\Translator;
7
use PHPUnit\Framework\TestCase;
8
9
class FileTranslatorTest extends TestCase
10
{
11
    /**
12
     * @covers OpCacheGUI\I18n\FileTranslator::__construct
13
     */
14
    public function testConstructCorrectInstance()
15
    {
16
        $translator = new FileTranslator(__DIR__ . '/../../Data/texts', 'en');
17
18
        $this->assertInstanceOf(Translator::class, $translator);
19
    }
20
21
    /**
22
     * @covers OpCacheGUI\I18n\FileTranslator::__construct
23
     */
24
    public function testConstructThrowsUpOnUnsupportedLanguage()
25
    {
26
        $this->expectException(\Exception::class);
27
        $this->expectExceptionMessage('Unsupported language (`abcdef`).');
28
29
        new FileTranslator(__DIR__ . '/../../Data/texts', 'abcdef');
30
    }
31
32
    /**
33
     * @covers OpCacheGUI\I18n\FileTranslator::__construct
34
     */
35
    public function testConstructThrowsUpOnInvalidTranslationFile()
36
    {
37
        $this->expectException(\Exception::class);
38
        $this->expectExceptionMessage('The translation file (`' . __DIR__ . '/../../Data/texts/invalid.php`) has an invalid format.');
39
40
        new FileTranslator(__DIR__ . '/../../Data/texts', 'invalid');
41
    }
42
43
    /**
44
     * @covers OpCacheGUI\I18n\FileTranslator::__construct
45
     * @covers OpCacheGUI\I18n\FileTranslator::translate
46
     */
47
    public function testTranslateWIthInvalidKey()
48
    {
49
        $translator = new FileTranslator(__DIR__ . '/../../Data/texts', 'en');
50
51
        $this->assertSame('{{invalidkey}}', $translator->translate('invalidkey'));
52
    }
53
54
    /**
55
     * @covers OpCacheGUI\I18n\FileTranslator::__construct
56
     * @covers OpCacheGUI\I18n\FileTranslator::translate
57
     */
58
    public function testTranslateWIthValidKey()
59
    {
60
        $translator = new FileTranslator(__DIR__ . '/../../Data/texts', 'en');
61
62
        $this->assertSame('bar', $translator->translate('foo'));
63
    }
64
}
65