Completed
Push — master ( 749f69...94328c )
by Kamil
27:45
created

ZoneContextSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 3
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\Behat\Context\Setup;
13
14
use Behat\Behat\Context\Context;
15
use PhpSpec\ObjectBehavior;
16
use Sylius\Bundle\AddressingBundle\Factory\ZoneFactoryInterface;
17
use Sylius\Bundle\SettingsBundle\Manager\SettingsManagerInterface;
18
use Sylius\Bundle\SettingsBundle\Model\Settings;
19
use Sylius\Component\Addressing\Model\ZoneInterface;
20
use Sylius\Component\Resource\Repository\RepositoryInterface;
21
22
/**
23
 * @author Mateusz Zalewski <[email protected]>
24
 */
25
class ZoneContextSpec extends ObjectBehavior
26
{
27
    function let(
28
        RepositoryInterface $zoneRepository,
29
        SettingsManagerInterface $settingsManager,
30
        ZoneFactoryInterface $zoneFactory
31
    ) {
32
        $this->beConstructedWith($zoneRepository, $settingsManager, $zoneFactory);
33
    }
34
35
    function it_is_initializable()
36
    {
37
        $this->shouldHaveType('Sylius\Behat\Context\Setup\ZoneContext');
38
    }
39
40
    function it_implements_context_interface()
41
    {
42
        $this->shouldImplement(Context::class);
43
    }
44
45
    function it_creates_eu_zone_with_european_zone_members(
46
        $zoneRepository,
47
        $zoneFactory,
48
        ZoneInterface $zone
49
    ) {
50
        $zoneFactory->createWithMembers([
51
            'BE', 'BG', 'CZ', 'DK', 'DE', 'EE', 'IE', 'GR', 'ES',
52
            'FR', 'IT', 'CY', 'LV', 'LT', 'LU', 'HU', 'MT', 'NL',
53
            'AT', 'PL', 'PT', 'RO', 'SI', 'SK', 'FI', 'SE', 'GB',
54
        ])->willReturn($zone);
55
56
        $zone->setType(ZoneInterface::TYPE_COUNTRY)->shouldBeCalled();
57
        $zone->setName('European Union')->shouldBeCalled();
58
        $zone->setCode('EU')->shouldBeCalled();
59
60
        $zoneRepository->add($zone)->shouldBeCalled();
61
62
        $this->thereIsEUZoneContainingAllMembersOfEuropeanUnion();
63
    }
64
65
    function it_sets_default_tax_zone($zoneRepository, $settingsManager, Settings $settings, ZoneInterface $zone)
66
    {
67
        $zoneRepository->findOneBy(['code' => 'EU'])->willReturn($zone);
68
69
        $settingsManager->loadSettings('sylius_taxation')->willReturn($settings);
70
        $settings->set('default_tax_zone', $zone)->shouldBeCalled();
71
        $settingsManager->saveSettings('sylius_taxation', $settings)->shouldBeCalled();
72
73
        $this->defaultTaxZoneIs('EU');
74
    }
75
76
    function it_throws_exception_if_zone_with_given_code_does_not_exist($zoneRepository)
77
    {
78
        $zoneRepository->findOneBy(['code' => 'EU'])->willReturn(null);
79
80
        $this->shouldThrow(new \InvalidArgumentException('Zone with code "EU" does not exist'))->during('defaultTaxZoneIs', ['EU']);
81
    }
82
}
83