testConstructThrowsUpOnUnsupportedLanguage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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