Completed
Push — 1.5 ( 2b4948...3e98ab )
by Kamil
23:10 queued 36s
created

LocaleFixtureSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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\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
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_creates_and_persists_default_locale(
35
        FactoryInterface $localeFactory,
36
        ObjectManager $localeManager,
37
        LocaleInterface $defaultLocale
38
    ): void {
39
        $localeFactory->createNew()->willReturn($defaultLocale);
40
41
        $defaultLocale->setCode('default_LOCALE')->shouldBeCalled();
42
43
        $localeManager->persist($defaultLocale)->shouldBeCalledOnce();
44
45
        $localeManager->flush()->shouldBeCalled();
46
47
        $this->load(['locales' => []]);
48
    }
49
50
    function it_creates_and_persists_default_locale_and_other_specified_locales(
51
        FactoryInterface $localeFactory,
52
        ObjectManager $localeManager,
53
        LocaleInterface $defaultLocale,
54
        LocaleInterface $polishLocale
55
    ): void {
56
        $localeFactory->createNew()->willReturn($defaultLocale, $polishLocale);
57
58
        $defaultLocale->setCode('default_LOCALE')->shouldBeCalled();
59
        $polishLocale->setCode('pl_PL')->shouldBeCalled();
60
61
        $localeManager->persist($defaultLocale)->shouldBeCalledOnce();
62
        $localeManager->persist($polishLocale)->shouldBeCalledOnce();
63
64
        $localeManager->flush()->shouldBeCalled();
65
66
        $this->load(['locales' => ['pl_PL']]);
67
    }
68
69
    function it_deduplicates_passed_locales_and_the_default_one(
70
        FactoryInterface $localeFactory,
71
        ObjectManager $localeManager,
72
        LocaleInterface $defaultLocale,
73
        LocaleInterface $polishLocale
74
    ): void {
75
        $localeFactory->createNew()->willReturn($defaultLocale, $polishLocale);
76
77
        $defaultLocale->setCode('default_LOCALE')->shouldBeCalled();
78
        $polishLocale->setCode('pl_PL')->shouldBeCalled();
79
80
        $localeManager->persist($defaultLocale)->shouldBeCalledOnce();
81
        $localeManager->persist($polishLocale)->shouldBeCalledOnce();
82
83
        $localeManager->flush()->shouldBeCalled();
84
85
        $this->load(['locales' => ['pl_PL', 'default_LOCALE', 'pl_PL']]);
86
    }
87
}
88