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\Component\Core\Model; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
15
|
|
|
use Doctrine\Common\Collections\Collection; |
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Component\Addressing\Model\ZoneInterface; |
18
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
19
|
|
|
use Sylius\Component\Core\Model\ShippingMethod; |
20
|
|
|
use Sylius\Component\Core\Model\ShippingMethodInterface; |
21
|
|
|
use Sylius\Component\Shipping\Model\ShippingMethod as BaseShippingMethod; |
22
|
|
|
use Sylius\Component\Taxation\Model\TaxCategoryInterface; |
23
|
|
|
|
24
|
|
|
final class ShippingMethodSpec extends ObjectBehavior |
25
|
|
|
{ |
26
|
|
|
function it_is_initializable() |
27
|
|
|
{ |
28
|
|
|
$this->shouldHaveType(ShippingMethod::class); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
function it_implements_a_shipping_method_interface() |
32
|
|
|
{ |
33
|
|
|
$this->shouldImplement(ShippingMethodInterface::class); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
function it_extends_a_shipping_method() |
37
|
|
|
{ |
38
|
|
|
$this->shouldHaveType(BaseShippingMethod::class); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
function it_does_not_have_any_zone_defined_by_default() |
42
|
|
|
{ |
43
|
|
|
$this->getZone()->shouldReturn(null); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
function it_allows_defining_zone(ZoneInterface $zone) |
47
|
|
|
{ |
48
|
|
|
$this->setZone($zone); |
49
|
|
|
$this->getZone()->shouldReturn($zone); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function its_tax_category_is_mutable(TaxCategoryInterface $category) |
53
|
|
|
{ |
54
|
|
|
$this->setTaxCategory($category); |
55
|
|
|
$this->getTaxCategory()->shouldReturn($category); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function it_has_channels_collection(ChannelInterface $firstChannel, ChannelInterface $secondChannel) |
59
|
|
|
{ |
60
|
|
|
$this->addChannel($firstChannel); |
61
|
|
|
$this->addChannel($secondChannel); |
62
|
|
|
|
63
|
|
|
$this->getChannels()->shouldBeSameAs(new ArrayCollection([$firstChannel, $secondChannel])); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
function it_can_add_and_remove_channels(ChannelInterface $channel) |
67
|
|
|
{ |
68
|
|
|
$this->addChannel($channel); |
69
|
|
|
$this->hasChannel($channel)->shouldReturn(true); |
70
|
|
|
|
71
|
|
|
$this->removeChannel($channel); |
72
|
|
|
$this->hasChannel($channel)->shouldReturn(false); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getMatchers() |
76
|
|
|
{ |
77
|
|
|
return [ |
78
|
|
|
'beSameAs' => function ($subject, $key) { |
79
|
|
|
if (!$subject instanceof Collection || !$key instanceof Collection) { |
80
|
|
|
return false; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
for ($i = 0; $i < $subject->count(); $i++) { |
84
|
|
|
if ($subject->get($i) !== $key->get($i)->getWrappedObject()) { |
85
|
|
|
return false; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return true; |
90
|
|
|
}, |
91
|
|
|
]; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|