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

TranslatorLoaderProviderPassTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_adds_translation_loaders_to_sylius_loader_provider() 0 16 1
A it_adds_translation_loaders_with_its_legacy_alias_to_sylius_loader_provider() 0 16 1
A it_adds_translation_loaders_using_only_the_first_tag_alias() 0 17 1
A it_does_not_force_the_existence_of_translation_loaders() 0 12 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\TranslatorLoaderProviderPass;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Definition;
18
use Symfony\Component\DependencyInjection\Reference;
19
20
/**
21
 * @author Kamil Kokot <[email protected]>
22
 */
23
final class TranslatorLoaderProviderPassTest extends AbstractCompilerPassTestCase
24
{
25
    /**
26
     * @test
27
     */
28
    public function it_adds_translation_loaders_to_sylius_loader_provider()
29
    {
30
        $this->setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]]));
31
32
        $translationLoaderDefinition = new Definition();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $translationLoaderDefinition 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...
33
        $translationLoaderDefinition->addTag('translation.loader', ['alias' => 'yml']);
34
        $this->setDefinition('translation.loader.yml', $translationLoaderDefinition);
35
36
        $this->compile();
37
38
        $this->assertContainerBuilderHasServiceDefinitionWithArgument(
39
            'sylius.theme.translation.loader_provider',
40
            0,
41
            ['yml' => new Reference('translation.loader.yml')]
42
        );
43
    }
44
45
    /**
46
     * @test
47
     */
48
    public function it_adds_translation_loaders_with_its_legacy_alias_to_sylius_loader_provider()
49
    {
50
        $this->setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]]));
51
52
        $translationLoaderDefinition = new Definition();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $translationLoaderDefinition 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...
53
        $translationLoaderDefinition->addTag('translation.loader', ['alias' => 'xlf', 'legacy-alias' => 'xliff']);
54
        $this->setDefinition('translation.loader.xliff', $translationLoaderDefinition);
55
56
        $this->compile();
57
58
        $this->assertContainerBuilderHasServiceDefinitionWithArgument(
59
            'sylius.theme.translation.loader_provider',
60
            0,
61
            ['xlf' => new Reference('translation.loader.xliff'), 'xliff' => new Reference('translation.loader.xliff')]
62
        );
63
    }
64
65
    /**
66
     * @test
67
     */
68
    public function it_adds_translation_loaders_using_only_the_first_tag_alias()
69
    {
70
        $this->setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]]));
71
72
        $translationLoaderDefinition = new Definition();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $translationLoaderDefinition 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...
73
        $translationLoaderDefinition->addTag('translation.loader', ['alias' => 'yml']);
74
        $translationLoaderDefinition->addTag('translation.loader', ['alias' => 'yaml']);
75
        $this->setDefinition('translation.loader.yml', $translationLoaderDefinition);
76
77
        $this->compile();
78
79
        $this->assertContainerBuilderHasServiceDefinitionWithArgument(
80
            'sylius.theme.translation.loader_provider',
81
            0,
82
            ['yml' => new Reference('translation.loader.yml')]
83
        );
84
    }
85
86
    /**
87
     * @test
88
     */
89
    public function it_does_not_force_the_existence_of_translation_loaders()
90
    {
91
        $this->setDefinition('sylius.theme.translation.loader_provider', new Definition(null, [[]]));
92
93
        $this->compile();
94
95
        $this->assertContainerBuilderHasServiceDefinitionWithArgument(
96
            'sylius.theme.translation.loader_provider',
97
            0,
98
            []
99
        );
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    protected function registerCompilerPass(ContainerBuilder $container)
106
    {
107
        $container->addCompilerPass(new TranslatorLoaderProviderPass());
108
    }
109
}
110