Completed
Push — 1.3 ( 2923d8...a36271 )
by Kamil
32:20
created

CustomerSpec::its_user_is_mutable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\Core\Model;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use PhpSpec\ObjectBehavior;
18
use Sylius\Component\Core\Model\AddressInterface;
19
use Sylius\Component\Core\Model\CustomerInterface;
20
use Sylius\Component\Core\Model\ShopUserInterface;
21
use Sylius\Component\User\Model\UserInterface;
22
23
final class CustomerSpec extends ObjectBehavior
24
{
25
    function it_implements_a_user_component_interface(): void
26
    {
27
        $this->shouldImplement(CustomerInterface::class);
28
    }
29
30
    function it_has_no_billing_address_by_default(): void
31
    {
32
        $this->getDefaultAddress()->shouldReturn(null);
33
    }
34
35
    function its_addresses_is_collection(): void
36
    {
37
        $this->getAddresses()->shouldHaveType(ArrayCollection::class);
38
    }
39
40
    function it_has_no_addresses_by_default(): void
41
    {
42
        $this->getAddresses()->count()->shouldReturn(0);
43
    }
44
45
    function its_billing_address_is_mutable(AddressInterface $address): void
46
    {
47
        $this->setDefaultAddress($address);
48
        $this->getDefaultAddress()->shouldReturn($address);
49
    }
50
51
    function its_addresses_are_mutable(AddressInterface $address): void
52
    {
53
        $this->addAddress($address);
54
        $this->hasAddress($address)->shouldReturn(true);
55
    }
56
57
    function it_can_remove_addresses(AddressInterface $address): void
58
    {
59
        $this->addAddress($address);
60
        $this->removeAddress($address);
61
        $this->hasAddress($address)->shouldReturn(false);
62
    }
63
64
    function it_adds_address_when_billing_address_is_set(AddressInterface $address): void
65
    {
66
        $this->setDefaultAddress($address);
67
        $this->hasAddress($address)->shouldReturn(true);
68
    }
69
70
    function it_has_no_user_by_default(): void
71
    {
72
        $this->getUser()->shouldReturn(null);
73
    }
74
75
    function its_user_is_mutable(ShopUserInterface $user): void
76
    {
77
        $user->setCustomer($this)->shouldBeCalled();
78
79
        $this->setUser($user);
80
        $this->getUser()->shouldReturn($user);
81
    }
82
83
    function it_throws_an_invalid_argument_exception_when_user_is_not_a_shop_user_type(UserInterface $user): void
84
    {
85
        $this->shouldThrow(\InvalidArgumentException::class)->during('setUser', [$user]);
86
    }
87
88
    function it_resets_customer_of_previous_user(ShopUserInterface $previousUser, ShopUserInterface $user): void
89
    {
90
        $this->setUser($previousUser);
91
92
        $previousUser->setCustomer(null)->shouldBeCalled();
93
94
        $this->setUser($user);
95
    }
96
97
    function it_does_not_replace_user_if_it_is_already_set(ShopUserInterface $user): void
98
    {
99
        $user->setCustomer($this)->shouldBeCalledOnce();
100
101
        $this->setUser($user);
102
        $this->setUser($user);
103
    }
104
}
105