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\Component\Addressing\Model\ZoneInterface; |
17
|
|
|
use Sylius\Component\Core\Model\ShippingMethod; |
18
|
|
|
use Sylius\Component\Core\Model\ShippingMethodInterface; |
19
|
|
|
use Sylius\Component\Core\Test\Services\SharedStorageInterface; |
20
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
21
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
22
|
|
|
use Sylius\Component\Shipping\Calculator\DefaultCalculators; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Mateusz Zalewski <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class ShippingContextSpec extends ObjectBehavior |
28
|
|
|
{ |
29
|
|
|
function let(RepositoryInterface $shippingMethodRepository, FactoryInterface $shippingMethodFactory, SharedStorageInterface $sharedStorage) |
30
|
|
|
{ |
31
|
|
|
$this->beConstructedWith($shippingMethodRepository, $shippingMethodFactory, $sharedStorage); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_is_initializable() |
35
|
|
|
{ |
36
|
|
|
$this->shouldHaveType('Sylius\Behat\Context\Setup\ShippingContext'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_implements_context_interface() |
40
|
|
|
{ |
41
|
|
|
$this->shouldImplement(Context::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_configures_store_to_ship_everything_for_free( |
45
|
|
|
$shippingMethodRepository, |
46
|
|
|
$shippingMethodFactory, |
47
|
|
|
$sharedStorage, |
48
|
|
|
ShippingMethod $shippingMethod, |
49
|
|
|
ZoneInterface $zone |
50
|
|
|
) { |
51
|
|
|
$sharedStorage->getCurrentResource('zone')->willReturn($zone); |
52
|
|
|
$shippingMethodFactory->createNew()->willReturn($shippingMethod); |
53
|
|
|
|
54
|
|
|
$shippingMethod->setCode('free')->shouldBeCalled(); |
55
|
|
|
$shippingMethod->setName('Free')->shouldBeCalled(); |
56
|
|
|
$shippingMethod->setCurrentLocale('en')->shouldBeCalled(); |
57
|
|
|
$shippingMethod->setConfiguration(['amount' => 0])->shouldBeCalled(); |
58
|
|
|
$shippingMethod->setCalculator(DefaultCalculators::FLAT_RATE)->shouldBeCalled(); |
59
|
|
|
$shippingMethod->setZone($zone)->shouldBeCalled(); |
60
|
|
|
|
61
|
|
|
$shippingMethodRepository->add($shippingMethod)->shouldBeCalled(); |
62
|
|
|
|
63
|
|
|
$this->storeShipsEverythingForFree(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
function it_configures_shipping_method_with_given_data( |
67
|
|
|
$shippingMethodRepository, |
68
|
|
|
$shippingMethodFactory, |
69
|
|
|
$sharedStorage, |
70
|
|
|
ShippingMethod $shippingMethod, |
71
|
|
|
ZoneInterface $zone |
72
|
|
|
) { |
73
|
|
|
$sharedStorage->getCurrentResource('zone')->willReturn($zone); |
74
|
|
|
$shippingMethodFactory->createNew()->willReturn($shippingMethod); |
75
|
|
|
|
76
|
|
|
$shippingMethod->setCode('test_shipping_method')->shouldBeCalled(); |
77
|
|
|
$shippingMethod->setName('Test shipping method')->shouldBeCalled(); |
78
|
|
|
$shippingMethod->setCurrentLocale('en')->shouldBeCalled(); |
79
|
|
|
$shippingMethod->setConfiguration(['amount' => 1000])->shouldBeCalled(); |
80
|
|
|
$shippingMethod->setCalculator(DefaultCalculators::FLAT_RATE)->shouldBeCalled(); |
81
|
|
|
$shippingMethod->setZone($zone)->shouldBeCalled(); |
82
|
|
|
|
83
|
|
|
$shippingMethodRepository->add($shippingMethod)->shouldBeCalled(); |
84
|
|
|
|
85
|
|
|
$this->storeHasShippingMethodWithFee('Test shipping method', '10.00'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
function it_casts_shipping_method_name_to_string($shippingMethodRepository, ShippingMethodInterface $shippingMethod) |
89
|
|
|
{ |
90
|
|
|
$shippingMethodRepository->findOneBy(['name' => 'DHL'])->willReturn($shippingMethod); |
91
|
|
|
|
92
|
|
|
$this->getShippingMethodByName('DHL')->shouldReturn($shippingMethod); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
function it_throws_exception_if_there_is_no_shipping_method_with_name_passed_to_casting($shippingMethodRepository) |
96
|
|
|
{ |
97
|
|
|
$shippingMethodRepository->findOneBy(['name' => 'DHL'])->willReturn(null); |
98
|
|
|
|
99
|
|
|
$this->shouldThrow(new \Exception('Shipping method with name "DHL" does not exist'))->during('getShippingMethodByName', ['DHL']); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|