Completed
Push — scalar-types/theme ( 71f30c )
by Kamil
21:15
created

ShipmentSpec::it_implements_shipment_interface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\Component\Shipping\Model;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Shipping\Model\ShipmentInterface;
18
use Sylius\Component\Shipping\Model\ShipmentUnitInterface;
19
use Sylius\Component\Shipping\Model\ShippingMethodInterface;
20
21
/**
22
 * @author Paweł Jędrzejewski <[email protected]>
23
 */
24
final class ShipmentSpec extends ObjectBehavior
25
{
26
    function it_implements_shipment_interface(): void
27
    {
28
        $this->shouldImplement(ShipmentInterface::class);
29
    }
30
31
    function it_has_no_id_by_default(): void
32
    {
33
        $this->getId()->shouldReturn(null);
34
    }
35
36
    function it_has_ready_state_by_default(): void
37
    {
38
        $this->getState()->shouldReturn(ShipmentInterface::STATE_CART);
39
    }
40
41
    function its_state_is_mutable(): void
42
    {
43
        $this->setState(ShipmentInterface::STATE_SHIPPED);
44
        $this->getState()->shouldReturn(ShipmentInterface::STATE_SHIPPED);
45
    }
46
47
    function it_has_no_shipping_method_by_default(): void
48
    {
49
        $this->getMethod()->shouldReturn(null);
50
    }
51
52
    function its_shipping_method_is_mutable(ShippingMethodInterface $shippingMethod): void
53
    {
54
        $this->setMethod($shippingMethod);
55
        $this->getMethod()->shouldReturn($shippingMethod);
56
    }
57
58
    function it_initializes_units_collection_by_default(): void
59
    {
60
        $this->getUnits()->shouldHaveType('Doctrine\Common\Collections\Collection');
61
    }
62
63
    function it_adds_units(ShipmentUnitInterface $shipmentUnit): void
64
    {
65
        $this->hasUnit($shipmentUnit)->shouldReturn(false);
66
67
        $shipmentUnit->setShipment($this)->shouldBeCalled();
68
        $this->addUnit($shipmentUnit);
69
70
        $this->hasUnit($shipmentUnit)->shouldReturn(true);
71
    }
72
73
    function it_removes_unit(ShipmentUnitInterface $shipmentUnit): void
74
    {
75
        $this->hasUnit($shipmentUnit)->shouldReturn(false);
76
77
        $shipmentUnit->setShipment($this)->shouldBeCalled();
78
        $this->addUnit($shipmentUnit);
79
80
        $shipmentUnit->setShipment(null)->shouldBeCalled();
81
        $this->removeUnit($shipmentUnit);
82
83
        $this->hasUnit($shipmentUnit)->shouldReturn(false);
84
    }
85
86
    function it_has_no_tracking_code_by_default(): void
87
    {
88
        $this->getTracking()->shouldReturn(null);
89
    }
90
91
    function its_tracking_code_is_mutable(): void
92
    {
93
        $this->setTracking('5346172074');
94
        $this->getTracking()->shouldReturn('5346172074');
95
    }
96
97
    function it_is_not_tracked_by_default(): void
98
    {
99
        $this->shouldNotBeTracked();
100
    }
101
102
    function it_is_tracked_only_if_tracking_code_is_defined(): void
103
    {
104
        $this->shouldNotBeTracked();
105
        $this->setTracking('5346172074');
106
        $this->shouldBeTracked();
107
        $this->setTracking(null);
108
        $this->shouldNotBeTracked();
109
    }
110
111
    function it_initializes_creation_date_by_default(): void
112
    {
113
        $this->getCreatedAt()->shouldHaveType('DateTime');
114
    }
115
116
    function its_creation_date_is_mutable(): void
117
    {
118
        $date = new \DateTime();
119
120
        $this->setCreatedAt($date);
121
        $this->getCreatedAt()->shouldReturn($date);
122
    }
123
124
    function it_has_no_last_update_date_by_default(): void
125
    {
126
        $this->getUpdatedAt()->shouldReturn(null);
127
    }
128
129
    function its_last_update_date_is_mutable(): void
130
    {
131
        $date = new \DateTime();
132
133
        $this->setUpdatedAt($date);
134
        $this->getUpdatedAt()->shouldReturn($date);
135
    }
136
}
137