Completed
Push — master ( 4c1af7...741b75 )
by Ruud
21:53
created

LoaderTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 17 1
A testLoad() 0 7 1
1
<?php
2
3
namespace Kunstmaan\TranslatorBundle\Tests\Service\Translator;
4
5
use Kunstmaan\TranslatorBundle\Entity\Translation;
6
use Kunstmaan\TranslatorBundle\Repository\TranslationRepository;
7
use Kunstmaan\TranslatorBundle\Service\Translator\Loader;
8
use PHPUnit\Framework\TestCase;
9
10
class LoaderTest extends TestCase
11
{
12
    const TEST_DATA_DOMAIN = 'validation';
13
    const TEST_DATA_LOCALE = 'en';
14
    const TEST_DATA_KEYWORD = 'validation.ok';
15
    const TEST_DATA_TEXT = 'Everything ok';
16
17
    public function setUp()
18
    {
19
        $translation = new Translation();
20
        $translation
21
            ->setDomain(self::TEST_DATA_DOMAIN)
22
            ->setLocale(self::TEST_DATA_LOCALE)
23
            ->setKeyword(self::TEST_DATA_KEYWORD)
24
            ->setText(self::TEST_DATA_TEXT)
25
        ;
26
27
        $translationRepository = $this->createMock(TranslationRepository::class);
28
        $translationRepository->method('findBy')->willReturn([$translation]);
29
30
        /* @var Loader loader */
31
        $this->loader = new Loader();
0 ignored issues
show
Bug introduced by
The property loader does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
        $this->loader->setTranslationRepository($translationRepository);
33
    }
34
35
    public function testLoad()
36
    {
37
        $catalogue = $this->loader->load('', self::TEST_DATA_LOCALE, self::TEST_DATA_DOMAIN);
38
        $messages = $catalogue->all(self::TEST_DATA_DOMAIN);
39
        $this->assertEquals($messages[self::TEST_DATA_KEYWORD], self::TEST_DATA_TEXT);
40
        $this->assertEquals($catalogue->getLocale(), self::TEST_DATA_LOCALE);
41
    }
42
}
43