Completed
Push — 1.1 ( 013821...c05031 )
by Kamil
91:21 queued 68:26
created

TranslatableEntityLocaleAssignerSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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\Component\Core\Translation;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Locale\Context\LocaleContextInterface;
18
use Sylius\Component\Locale\Context\LocaleNotFoundException;
19
use Sylius\Component\Resource\Model\TranslatableInterface;
20
use Sylius\Component\Resource\Translation\Provider\TranslationLocaleProviderInterface;
21
use Sylius\Component\Resource\Translation\TranslatableEntityLocaleAssignerInterface;
22
23
final class TranslatableEntityLocaleAssignerSpec extends ObjectBehavior
24
{
25
    function let(LocaleContextInterface $localeContext, TranslationLocaleProviderInterface $translationLocaleProvider): void
26
    {
27
        $this->beConstructedWith($localeContext, $translationLocaleProvider);
28
    }
29
30
    function it_implements_traslatable_entity_locale_assigner_interface(): void
31
    {
32
        $this->shouldImplement(TranslatableEntityLocaleAssignerInterface::class);
33
    }
34
35
    function it_should_assign_current_and_default_locale_to_given_translatable_entity(
36
        LocaleContextInterface $localeContext,
37
        TranslationLocaleProviderInterface $translationLocaleProvider,
38
        TranslatableInterface $translatableEntity
39
    ): void {
40
        $localeContext->getLocaleCode()->willReturn('de_DE');
41
        $translationLocaleProvider->getDefaultLocaleCode()->willReturn('en_US');
42
43
        $translatableEntity->setCurrentLocale('de_DE')->shouldBeCalled();
44
        $translatableEntity->setFallbackLocale('en_US')->shouldBeCalled();
45
46
        $this->assignLocale($translatableEntity);
47
    }
48
49
    function it_should_use_default_locale_as_current_if_could_not_resolve_the_current_locale(
50
        LocaleContextInterface $localeContext,
51
        TranslationLocaleProviderInterface $translationLocaleProvider,
52
        TranslatableInterface $translatableEntity
53
    ): void {
54
        $localeContext->getLocaleCode()->willThrow(new LocaleNotFoundException());
55
        $translationLocaleProvider->getDefaultLocaleCode()->willReturn('en_US');
56
57
        $translatableEntity->setCurrentLocale('en_US')->shouldBeCalled();
58
        $translatableEntity->setFallbackLocale('en_US')->shouldBeCalled();
59
60
        $this->assignLocale($translatableEntity);
61
    }
62
}
63