Completed
Push — scalar-types/theme ( 71f30c )
by Kamil
21:15
created

ThemeTranslatorResourceProviderSpec   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 0
cbo 6
dl 0
loc 148
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_implements_translator_resource_provider_interface() 0 4 1
A it_returns_translation_files_found_in_given_paths() 0 18 1
B it_returns_inherited_themes_as_the_main_theme_resources() 0 24 1
B it_doubles_resources_if_used_in_more_than_one_theme() 0 26 1
A it_returns_resources_locales_while_using_just_one_theme() 0 16 1
A it_returns_resources_locales_while_using_one_nested_theme() 0 21 1
A it_returns_resources_locales_while_using_more_than_one_theme() 0 22 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
declare(strict_types=1);
13
14
namespace spec\Sylius\Bundle\ThemeBundle\Translation\Provider;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Bundle\ThemeBundle\HierarchyProvider\ThemeHierarchyProviderInterface;
18
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
19
use Sylius\Bundle\ThemeBundle\Repository\ThemeRepositoryInterface;
20
use Sylius\Bundle\ThemeBundle\Translation\Finder\TranslationFilesFinderInterface;
21
use Sylius\Bundle\ThemeBundle\Translation\Provider\Resource\ThemeTranslatorResourceProvider;
22
use Sylius\Bundle\ThemeBundle\Translation\Provider\Resource\TranslatorResourceProviderInterface;
23
use Sylius\Bundle\ThemeBundle\Translation\Resource\ThemeTranslationResource;
24
25
/**
26
 * @author Kamil Kokot <[email protected]>
27
 */
28
final class ThemeTranslatorResourceProviderSpec extends ObjectBehavior
29
{
30
    function let(
31
        TranslationFilesFinderInterface $translationFilesFinder,
32
        ThemeRepositoryInterface $themeRepository,
33
        ThemeHierarchyProviderInterface $themeHierarchyProvider
34
    ): void {
35
        $this->beConstructedWith($translationFilesFinder, $themeRepository, $themeHierarchyProvider);
36
    }
37
38
    function it_implements_translator_resource_provider_interface(): void
39
    {
40
        $this->shouldImplement(TranslatorResourceProviderInterface::class);
41
    }
42
43
    function it_returns_translation_files_found_in_given_paths(
44
        TranslationFilesFinderInterface $translationFilesFinder,
45
        ThemeRepositoryInterface $themeRepository,
46
        ThemeHierarchyProviderInterface $themeHierarchyProvider,
47
        ThemeInterface $theme
48
    ): void {
49
        $themeRepository->findAll()->willReturn([$theme]);
50
        $themeHierarchyProvider->getThemeHierarchy($theme)->willReturn([$theme]);
51
52
        $theme->getPath()->willReturn('/theme/path');
53
        $theme->getName()->willReturn('theme/name');
54
55
        $translationFilesFinder->findTranslationFiles('/theme/path')->willReturn(['/theme/path/messages.en.yml']);
56
57
        $this->getResources()->shouldBeLike([
58
            new ThemeTranslationResource($theme->getWrappedObject(), '/theme/path/messages.en.yml'),
59
        ]);
60
    }
61
62
    function it_returns_inherited_themes_as_the_main_theme_resources(
63
        TranslationFilesFinderInterface $translationFilesFinder,
64
        ThemeRepositoryInterface $themeRepository,
65
        ThemeHierarchyProviderInterface $themeHierarchyProvider,
66
        ThemeInterface $mainTheme,
67
        ThemeInterface $parentTheme
68
    ): void {
69
        $themeRepository->findAll()->willReturn([$mainTheme]);
70
        $themeHierarchyProvider->getThemeHierarchy($mainTheme)->willReturn([$mainTheme, $parentTheme]);
71
72
        $mainTheme->getPath()->willReturn('/main/theme/path');
73
        $mainTheme->getName()->willReturn('main-theme/name');
74
75
        $parentTheme->getPath()->willReturn('/parent/theme/path');
76
        $parentTheme->getName()->willReturn('parent-theme/name');
77
78
        $translationFilesFinder->findTranslationFiles('/main/theme/path')->willReturn(['/main/theme/path/messages.en.yml']);
79
        $translationFilesFinder->findTranslationFiles('/parent/theme/path')->willReturn(['/parent/theme/path/messages.en.yml']);
80
81
        $this->getResources()->shouldBeLike([
82
            new ThemeTranslationResource($mainTheme->getWrappedObject(), '/parent/theme/path/messages.en.yml'),
83
            new ThemeTranslationResource($mainTheme->getWrappedObject(), '/main/theme/path/messages.en.yml'),
84
        ]);
85
    }
86
87
    function it_doubles_resources_if_used_in_more_than_one_theme(
88
        TranslationFilesFinderInterface $translationFilesFinder,
89
        ThemeRepositoryInterface $themeRepository,
90
        ThemeHierarchyProviderInterface $themeHierarchyProvider,
91
        ThemeInterface $mainTheme,
92
        ThemeInterface $parentTheme
93
    ): void {
94
        $themeRepository->findAll()->willReturn([$mainTheme, $parentTheme]);
95
        $themeHierarchyProvider->getThemeHierarchy($mainTheme)->willReturn([$mainTheme, $parentTheme]);
96
        $themeHierarchyProvider->getThemeHierarchy($parentTheme)->willReturn([$parentTheme]);
97
98
        $mainTheme->getPath()->willReturn('/main/theme/path');
99
        $mainTheme->getName()->willReturn('main-theme/name');
100
101
        $parentTheme->getPath()->willReturn('/parent/theme/path');
102
        $parentTheme->getName()->willReturn('parent-theme/name');
103
104
        $translationFilesFinder->findTranslationFiles('/main/theme/path')->willReturn(['/main/theme/path/messages.en.yml']);
105
        $translationFilesFinder->findTranslationFiles('/parent/theme/path')->willReturn(['/parent/theme/path/messages.en.yml']);
106
107
        $this->getResources()->shouldBeLike([
108
            new ThemeTranslationResource($mainTheme->getWrappedObject(), '/parent/theme/path/messages.en.yml'),
109
            new ThemeTranslationResource($mainTheme->getWrappedObject(), '/main/theme/path/messages.en.yml'),
110
            new ThemeTranslationResource($parentTheme->getWrappedObject(), '/parent/theme/path/messages.en.yml'),
111
        ]);
112
    }
113
114
    function it_returns_resources_locales_while_using_just_one_theme(
115
        TranslationFilesFinderInterface $translationFilesFinder,
116
        ThemeRepositoryInterface $themeRepository,
117
        ThemeHierarchyProviderInterface $themeHierarchyProvider,
118
        ThemeInterface $theme
119
    ): void {
120
        $themeRepository->findAll()->willReturn([$theme]);
121
        $themeHierarchyProvider->getThemeHierarchy($theme)->willReturn([$theme]);
122
123
        $theme->getPath()->willReturn('/theme/path');
124
        $theme->getName()->willReturn('theme/name');
125
126
        $translationFilesFinder->findTranslationFiles('/theme/path')->willReturn(['/theme/path/messages.en.yml']);
127
128
        $this->getResourcesLocales()->shouldReturn(['en@theme-name']);
129
    }
130
131
    function it_returns_resources_locales_while_using_one_nested_theme(
132
        TranslationFilesFinderInterface $translationFilesFinder,
133
        ThemeRepositoryInterface $themeRepository,
134
        ThemeHierarchyProviderInterface $themeHierarchyProvider,
135
        ThemeInterface $mainTheme,
136
        ThemeInterface $parentTheme
137
    ): void {
138
        $themeRepository->findAll()->willReturn([$mainTheme]);
139
        $themeHierarchyProvider->getThemeHierarchy($mainTheme)->willReturn([$mainTheme, $parentTheme]);
140
141
        $mainTheme->getPath()->willReturn('/main/theme/path');
142
        $mainTheme->getName()->willReturn('main-theme/name');
143
144
        $parentTheme->getPath()->willReturn('/parent/theme/path');
145
        $parentTheme->getName()->willReturn('parent-theme/name');
146
147
        $translationFilesFinder->findTranslationFiles('/main/theme/path')->willReturn(['/main/theme/path/messages.en.yml']);
148
        $translationFilesFinder->findTranslationFiles('/parent/theme/path')->willReturn(['/parent/theme/path/messages.en.yml']);
149
150
        $this->getResourcesLocales()->shouldReturn(['en@main-theme-name']);
151
    }
152
153
    function it_returns_resources_locales_while_using_more_than_one_theme(
154
        TranslationFilesFinderInterface $translationFilesFinder,
155
        ThemeRepositoryInterface $themeRepository,
156
        ThemeHierarchyProviderInterface $themeHierarchyProvider,
157
        ThemeInterface $mainTheme,
158
        ThemeInterface $parentTheme
159
    ): void {
160
        $themeRepository->findAll()->willReturn([$mainTheme, $parentTheme]);
161
        $themeHierarchyProvider->getThemeHierarchy($mainTheme)->willReturn([$mainTheme, $parentTheme]);
162
        $themeHierarchyProvider->getThemeHierarchy($parentTheme)->willReturn([$parentTheme]);
163
164
        $mainTheme->getPath()->willReturn('/main/theme/path');
165
        $mainTheme->getName()->willReturn('main-theme/name');
166
167
        $parentTheme->getPath()->willReturn('/parent/theme/path');
168
        $parentTheme->getName()->willReturn('parent-theme/name');
169
170
        $translationFilesFinder->findTranslationFiles('/main/theme/path')->willReturn(['/main/theme/path/messages.en.yml']);
171
        $translationFilesFinder->findTranslationFiles('/parent/theme/path')->willReturn(['/parent/theme/path/messages.en.yml']);
172
173
        $this->getResourcesLocales()->shouldReturn(['en@main-theme-name', 'en@parent-theme-name']);
174
    }
175
}
176