Completed
Push — theme-bundle ( 69304b...bce4cb )
by Kamil
18:15
created

ThemeAwareSourcesPassSpec::getFirstThemePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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 spec\Sylius\Bundle\ThemeBundle\Translation\DependencyInjection\Compiler;
13
14
use PhpSpec\ObjectBehavior;
15
use Prophecy\Argument;
16
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
17
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
18
use Sylius\Bundle\ThemeBundle\Translation\DependencyInjection\Compiler\ThemeAwareSourcesPass;
19
use Sylius\Bundle\ThemeBundle\Translation\TranslationFilesFinderInterface;
20
use Symfony\Component\Config\Resource\FileResource;
21
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
22
use Symfony\Component\DependencyInjection\ContainerBuilder;
23
use Symfony\Component\DependencyInjection\Definition;
24
25
/**
26
 * @mixin ThemeAwareSourcesPass
27
 *
28
 * @author Kamil Kokot <[email protected]>
29
 */
30
class ThemeAwareSourcesPassSpec extends ObjectBehavior
31
{
32
    function it_is_initializable()
33
    {
34
        $this->shouldHaveType('Sylius\Bundle\ThemeBundle\Translation\DependencyInjection\Compiler\ThemeAwareSourcesPass');
35
    }
36
37
    function it_implements_compiler_pass_interface()
38
    {
39
        $this->shouldImplement(CompilerPassInterface::class);
40
    }
41
42
    function it_does_nothing_if_there_is_no_theme(
43
        ContainerBuilder $containerBuilder,
44
        ThemeRepositoryInterface $themeRepository,
45
        TranslationFilesFinderInterface $translationFilesFinder
46
    ) {
47
        $containerBuilder->get('sylius.theme.repository')->willReturn($themeRepository);
48
        $themeRepository->findAll()->willReturn([]);
49
50
        $containerBuilder->get('sylius.theme.translation.files_finder')->willReturn($translationFilesFinder);
51
52
        $this->process($containerBuilder);
53
    }
54
55
    function it_finds_translation_files_and_adds_them_to_translator(
56
        ContainerBuilder $containerBuilder,
57
        ThemeRepositoryInterface $themeRepository,
58
        TranslationFilesFinderInterface $translationFilesFinder,
59
        ThemeInterface $firstTheme,
60
        ThemeInterface $secondTheme,
61
        Definition $translatorDefinition
62
    ) {
63
        $containerBuilder->get('sylius.theme.repository')->willReturn($themeRepository);
64
        $themeRepository->findAll()->willReturn([$firstTheme, $secondTheme]);
65
        
66
        $containerBuilder->get('sylius.theme.translation.files_finder')->willReturn($translationFilesFinder);
67
        $translationFilesFinder->findTranslationFiles($firstTheme)->willReturn([
68
            '/theme1/SampleBundle/translations/messages.en.yml',
69
            '/theme1/translations/messages.pl.yml',
70
        ]);
71
        $translationFilesFinder->findTranslationFiles($secondTheme)->willReturn([
72
            '/theme2/translations/messages.en.yml',
73
        ]);
74
75
        $containerBuilder->findDefinition('translator.default')->willReturn($translatorDefinition);
76
77
        $translatorDefinition->getArgument(3)->willReturn([
78
            'resource_files' => [
79
                'en' => [
80
                    '/lorem/ipsum/messages.en.yml',
81
                ],
82
            ],
83
        ]);
84
        $translatorDefinition->replaceArgument(3, [
85
            'resource_files' => [
86
                'en' => [
87
                    '/lorem/ipsum/messages.en.yml',
88
                    '/theme1/SampleBundle/translations/messages.en.yml',
89
                    '/theme2/translations/messages.en.yml',
90
                ],
91
                'pl' => [
92
                    '/theme1/translations/messages.pl.yml',
93
                ],
94
            ]
95
        ])->shouldBeCalled();
96
97
        $containerBuilder->addResource(Argument::type(FileResource::class))->shouldBeCalledTimes(3);
98
99
        $this->process($containerBuilder);
100
    }
101
}
102