Completed
Push — master ( 99d457...79eafd )
by Kamil
24:19
created

TranslatorFallbackLocalesPassTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_copies_method_call_that_sets_fallback_locales_to_theme_translator() 0 16 1
A it_filters_out_other_method_calls_to_symfony_translator() 0 18 1
A it_copies_method_calls_that_set_fallback_locales_to_theme_translator() 0 23 1
A it_does_not_force_symfony_translator_to_have_any_method_calls() 0 7 1
A registerCompilerPass() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ThemeBundle\Tests\Translation\DependencyInjection\Compiler;
13
14
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
15
use Sylius\Bundle\ThemeBundle\Translation\DependencyInjection\Compiler\TranslatorFallbackLocalesPass;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Definition;
18
19
/**
20
 * @author Kamil Kokot <[email protected]>
21
 */
22
final class TranslatorFallbackLocalesPassTest extends AbstractCompilerPassTestCase
23
{
24
    /**
25
     * @test
26
     */
27
    public function it_copies_method_call_that_sets_fallback_locales_to_theme_translator()
28
    {
29
        $symfonyTranslatorDefinition = new Definition();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $symfonyTranslatorDefinition exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
30
        $symfonyTranslatorDefinition->addMethodCall('setFallbackLocales', ['pl_PL']);
31
        $this->setDefinition('translator.default', $symfonyTranslatorDefinition);
32
33
        $this->setDefinition('sylius.theme.translation.translator', new Definition());
34
35
        $this->compile();
36
37
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
38
            'sylius.theme.translation.translator',
39
            'setFallbackLocales',
40
            ['pl_PL']
41
        );
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function it_filters_out_other_method_calls_to_symfony_translator()
48
    {
49
        $symfonyTranslatorDefinition = new Definition();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $symfonyTranslatorDefinition exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
50
        $symfonyTranslatorDefinition->addMethodCall('doFooAndBar', ['argument1', 'argument2']);
51
        $symfonyTranslatorDefinition->addMethodCall('setFallbackLocales', ['pl_PL']);
52
        $symfonyTranslatorDefinition->addMethodCall('doFoo', ['argument1']);
53
        $this->setDefinition('translator.default', $symfonyTranslatorDefinition);
54
55
        $this->setDefinition('sylius.theme.translation.translator', new Definition());
56
57
        $this->compile();
58
59
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
60
            'sylius.theme.translation.translator',
61
            'setFallbackLocales',
62
            ['pl_PL']
63
        );
64
    }
65
66
    /**
67
     * @test
68
     */
69
    public function it_copies_method_calls_that_set_fallback_locales_to_theme_translator()
70
    {
71
        $symfonyTranslatorDefinition = new Definition();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $symfonyTranslatorDefinition exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
72
        $symfonyTranslatorDefinition->addMethodCall('setFallbackLocales', ['pl_PL']);
73
        $symfonyTranslatorDefinition->addMethodCall('setFallbackLocales', ['en_US']);
74
        $this->setDefinition('translator.default', $symfonyTranslatorDefinition);
75
76
        $this->setDefinition('sylius.theme.translation.translator', new Definition());
77
78
        $this->compile();
79
80
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
81
            'sylius.theme.translation.translator',
82
            'setFallbackLocales',
83
            ['pl_PL']
84
        );
85
86
        $this->assertContainerBuilderHasServiceDefinitionWithMethodCall(
87
            'sylius.theme.translation.translator',
88
            'setFallbackLocales',
89
            ['en_US']
90
        );
91
    }
92
93
    /**
94
     * @test
95
     */
96
    public function it_does_not_force_symfony_translator_to_have_any_method_calls()
97
    {
98
        $this->setDefinition('translator.default', new Definition());
99
        $this->setDefinition('sylius.theme.translation.translator', new Definition());
100
101
        $this->compile();
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107
    protected function registerCompilerPass(ContainerBuilder $container)
108
    {
109
        $container->addCompilerPass(new TranslatorFallbackLocalesPass());
110
    }
111
}
112