TranslationTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testTranslationInvalidText() 0 5 1
A testTranslationPlaceHoldersCaseInsensitivity() 0 11 1
A testTranslationPlaceHoldersDynamicLanguage() 0 6 1
A testTranslationPlaceHoldersMultipleOfTheSame() 0 9 1
A testTranslationPlaceHoldersMultiple() 0 12 1
1
<?php
2
3
namespace JosephNC\Translation\Tests;
4
5
use Illuminate\Support\Facades\Cache;
6
use JosephNC\Translation\Facades\Translation;
7
use JosephNC\Translation\Models\Translation as TranslationModel;
8
9
class TranslationTest extends FunctionalTestCase
10
{
11
    public function testTranslationInvalidText()
12
    {
13
        $this->setExpectedException('InvalidArgumentException');
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit_Framework_TestCase::setExpectedException() has been deprecated: Method deprecated since Release 5.2.0; use expectException() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

13
        /** @scrutinizer ignore-deprecated */ $this->setExpectedException('InvalidArgumentException');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
14
15
        Translation::translate( [ 'Invalid' ] );
0 ignored issues
show
Bug introduced by
The method translate() does not exist on JosephNC\Translation\Facades\Translation. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
        Translation::/** @scrutinizer ignore-call */ 
16
                     translate( [ 'Invalid' ] );
Loading history...
16
    }
17
18
    public function testTranslationPlaceHoldersDynamicLanguage()
19
    {
20
        $replace = ['name' => 'John'];
21
22
        $this->assertEquals('Hello John', Translation::translate('Hello :name', $replace, 'en'));
23
        $this->assertEquals('Bonjour John', Translation::translate('Hello :name', $replace, 'fr'));
24
    }
25
26
    public function testTranslationPlaceHoldersMultiple()
27
    {
28
        $replace = [
29
            'name'    => 'John',
30
            'apples'  => '10',
31
            'bananas' => '15',
32
            'grapes'  => '20',
33
        ];
34
        $expected = 'Hello John, I see you have 10 apples, 15 bananas, and 20 grapes.';
35
        $translation = 'Hello :name, I see you have :apples apples, :bananas bananas, and :grapes grapes.';
36
37
        $this->assertEquals($expected, Translation::translate($translation, $replace));
38
    }
39
40
    public function testTranslationPlaceHoldersMultipleOfTheSame()
41
    {
42
        $replace = [
43
            'name' => 'Name',
44
        ];
45
        $expected = 'Name Name Name Name Name';
46
        $translation = ':name :name :name :name :name';
47
48
        $this->assertEquals($expected, Translation::translate($translation, $replace));
49
    }
50
51
    public function testTranslationPlaceHoldersCaseInsensitivity()
52
    {
53
        $replace = [
54
            'name' => 'John',
55
            'NAME' => 'Test',
56
        ];
57
58
        $translation = ':name :NAME';
59
        $expected = 'John John';
60
61
        $this->assertEquals($expected, Translation::translate($translation, $replace));
62
    }
63
}