Completed
Push — checkout-consistent-prices ( af49ca )
by Kamil
13:24
created

LocaleFixtureSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_a_fixture() 0 4 1
A it_loads_all_provided_locales() 0 18 1
A it_loads_all_provided_locales_and_the_default_one() 0 21 1
A it_allows_to_load_default_locale_and_specify_it_explicitly() 0 15 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\CoreBundle\Fixture;
15
16
use Doctrine\Common\Persistence\ObjectManager;
17
use PhpSpec\ObjectBehavior;
18
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface;
19
use Sylius\Component\Locale\Model\LocaleInterface;
20
use Sylius\Component\Resource\Factory\FactoryInterface;
21
22
final class LocaleFixtureSpec extends ObjectBehavior
23
{
24
    function let(FactoryInterface $localeFactory, ObjectManager $localeManager): void
25
    {
26
        $this->beConstructedWith($localeFactory, $localeManager, 'default_LOCALE');
27
    }
28
29
    function it_is_a_fixture(): void
30
    {
31
        $this->shouldImplement(FixtureInterface::class);
32
    }
33
34
    function it_loads_all_provided_locales(
35
        FactoryInterface $localeFactory,
36
        ObjectManager $localeManager,
37
        LocaleInterface $germanLocale,
38
        LocaleInterface $englishLocale
39
    ): void {
40
        $localeFactory->createNew()->willReturn($englishLocale, $germanLocale);
41
42
        $englishLocale->setCode('en_US')->shouldBeCalled();
43
        $germanLocale->setCode('de_DE')->shouldBeCalled();
44
45
        $localeManager->persist($englishLocale)->shouldBeCalled();
46
        $localeManager->persist($germanLocale)->shouldBeCalled();
47
48
        $localeManager->flush()->shouldBeCalledOnce();
49
50
        $this->load(['locales' => ['en_US', 'de_DE'], 'load_default_locale' => false]);
51
    }
52
53
    function it_loads_all_provided_locales_and_the_default_one(
54
        FactoryInterface $localeFactory,
55
        ObjectManager $localeManager,
56
        LocaleInterface $defaultLocale,
57
        LocaleInterface $germanLocale,
58
        LocaleInterface $englishLocale
59
    ): void {
60
        $localeFactory->createNew()->willReturn($defaultLocale, $englishLocale, $germanLocale);
61
62
        $defaultLocale->setCode('default_LOCALE')->shouldBeCalled();
63
        $englishLocale->setCode('en_US')->shouldBeCalled();
64
        $germanLocale->setCode('de_DE')->shouldBeCalled();
65
66
        $localeManager->persist($defaultLocale)->shouldBeCalled();
67
        $localeManager->persist($englishLocale)->shouldBeCalled();
68
        $localeManager->persist($germanLocale)->shouldBeCalled();
69
70
        $localeManager->flush()->shouldBeCalledOnce();
71
72
        $this->load(['locales' => ['en_US', 'de_DE'], 'load_default_locale' => true]);
73
    }
74
75
    function it_allows_to_load_default_locale_and_specify_it_explicitly(
76
        FactoryInterface $localeFactory,
77
        ObjectManager $localeManager,
78
        LocaleInterface $defaultLocale
79
    ): void {
80
        $localeFactory->createNew()->willReturn($defaultLocale);
81
82
        $defaultLocale->setCode('default_LOCALE')->shouldBeCalled();
83
84
        $localeManager->persist($defaultLocale)->shouldBeCalledOnce();
85
86
        $localeManager->flush()->shouldBeCalledOnce();
87
88
        $this->load(['locales' => ['default_LOCALE'], 'load_default_locale' => true]);
89
    }
90
}
91