Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

Tests/unit/Service/Translator/LoaderTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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