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 Prophecy\Argument; |
17
|
|
|
use Sylius\Bundle\AddressingBundle\Factory\ZoneFactoryInterface; |
18
|
|
|
use Sylius\Bundle\SettingsBundle\Manager\SettingsManagerInterface; |
19
|
|
|
use Sylius\Bundle\SettingsBundle\Model\Settings; |
20
|
|
|
use Sylius\Component\Addressing\Model\ZoneInterface; |
21
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @author Mateusz Zalewski <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class ZoneContextSpec extends ObjectBehavior |
27
|
|
|
{ |
28
|
|
|
function let( |
29
|
|
|
RepositoryInterface $zoneRepository, |
30
|
|
|
SettingsManagerInterface $settingsManager, |
31
|
|
|
ZoneFactoryInterface $zoneFactory |
32
|
|
|
) { |
33
|
|
|
$this->beConstructedWith($zoneRepository, $settingsManager, $zoneFactory); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_is_initializable() |
37
|
|
|
{ |
38
|
|
|
$this->shouldHaveType('Sylius\Behat\Context\Setup\ZoneContext'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function it_implements_context_interface() |
42
|
|
|
{ |
43
|
|
|
$this->shouldImplement(Context::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function it_creates_eu_zone_with_european_zone_members($zoneRepository, $zoneFactory, ZoneInterface $zone) |
47
|
|
|
{ |
48
|
|
|
$zoneFactory->createWithMembers([ |
49
|
|
|
'BE', 'BG', 'CZ', 'DK', 'DE', 'EE', 'IE', 'GR', 'ES', |
50
|
|
|
'FR', 'IT', 'CY', 'LV', 'LT', 'LU', 'HU', 'MT', 'NL', |
51
|
|
|
'AT', 'PL', 'PT', 'RO', 'SI', 'SK', 'FI', 'SE', 'GB', |
52
|
|
|
])->willReturn($zone); |
53
|
|
|
|
54
|
|
|
$zone->setType(ZoneInterface::TYPE_COUNTRY)->shouldBeCalled(); |
55
|
|
|
$zone->setName('European Union')->shouldBeCalled(); |
56
|
|
|
$zone->setCode('EU')->shouldBeCalled(); |
57
|
|
|
|
58
|
|
|
$zoneRepository->add($zone)->shouldBeCalled(); |
59
|
|
|
|
60
|
|
|
$this->thereIsEUZoneContainingAllMembersOfEuropeanUnion(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
function it_creates_rest_of_the_world_zone($zoneRepository, $zoneFactory, ZoneInterface $zone) |
64
|
|
|
{ |
65
|
|
|
$zoneFactory->createWithMembers(Argument::type('array'))->willReturn($zone); |
66
|
|
|
|
67
|
|
|
$zone->setType(ZoneInterface::TYPE_COUNTRY)->shouldBeCalled(); |
68
|
|
|
$zone->setName('Rest of the World')->shouldBeCalled(); |
69
|
|
|
$zone->setCode('RoW')->shouldBeCalled(); |
70
|
|
|
|
71
|
|
|
$zoneRepository->add($zone)->shouldBeCalled(); |
72
|
|
|
|
73
|
|
|
$this->thereIsRestOfTheWorldZoneContainingAllOtherCountries(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
function it_sets_default_zone($zoneRepository, $settingsManager, Settings $settings, ZoneInterface $zone) |
77
|
|
|
{ |
78
|
|
|
$zoneRepository->findOneBy(['code' => 'EU'])->willReturn($zone); |
79
|
|
|
|
80
|
|
|
$settingsManager->loadSettings('sylius_taxation')->willReturn($settings); |
81
|
|
|
$settings->set('default_tax_zone', $zone)->shouldBeCalled(); |
82
|
|
|
$settingsManager->saveSettings('sylius_taxation', $settings)->shouldBeCalled(); |
83
|
|
|
|
84
|
|
|
$this->defaultTaxZoneIs('EU'); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
function it_throws_exception_if_zone_with_given_code_does_not_exist_while_setting_default_zone($zoneRepository) |
88
|
|
|
{ |
89
|
|
|
$zoneRepository->findOneBy(['code' => 'EU'])->willReturn(null); |
90
|
|
|
|
91
|
|
|
$this->shouldThrow(new \InvalidArgumentException('Zone with code "EU" does not exist.'))->during('defaultTaxZoneIs', ['EU']); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
function it_returns_zone_by_its_code($zoneRepository, ZoneInterface $zone) |
95
|
|
|
{ |
96
|
|
|
$zoneRepository->findOneBy(['code' => 'EU'])->willReturn($zone); |
97
|
|
|
|
98
|
|
|
$this->getZoneByCode('EU')->shouldReturn($zone); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
function it_throws_exception_if_zone_with_given_code_does_not_exist($zoneRepository) |
102
|
|
|
{ |
103
|
|
|
$zoneRepository->findOneBy(['code' => 'EU'])->willReturn(null); |
104
|
|
|
|
105
|
|
|
$this->shouldThrow(new \Exception('Zone with code "EU" does not exist.'))->during('getZoneByCode', ['EU']); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
function it_returns_the_rest_of_the_world_zone($zoneRepository, ZoneInterface $zone) |
109
|
|
|
{ |
110
|
|
|
$zoneRepository->findOneBy(['code' => 'RoW'])->willReturn($zone); |
111
|
|
|
|
112
|
|
|
$this->getRestOfTheWorldZone()->shouldReturn($zone); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
function it_throws_exception_if_there_is_no_rest_of_the_world_zone($zoneRepository) |
116
|
|
|
{ |
117
|
|
|
$zoneRepository->findOneBy(['code' => 'RoW'])->willReturn(null); |
118
|
|
|
|
119
|
|
|
$this->shouldThrow(new \Exception('Rest of the world zone does not exist.'))->during('getRestOfTheWorldZone'); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|