Completed
Push — master ( 860366...55daec )
by Kamil
19:37
created

UserContextSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
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
namespace spec\Sylius\Behat\Context\Setup;
13
14
use Behat\Behat\Context\Context;
15
use Doctrine\Common\Persistence\ObjectManager;
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Bundle\CoreBundle\Test\Factory\TestUserFactory;
18
use Sylius\Component\Core\Model\AddressInterface;
19
use Sylius\Component\Core\Model\CustomerInterface;
20
use Sylius\Component\Core\Model\UserInterface;
21
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
22
use Sylius\Component\Resource\Factory\FactoryInterface;
23
use Sylius\Component\Resource\Repository\RepositoryInterface;
24
25
/**
26
 * @author Mateusz Zalewski <[email protected]>
27
 */
28
class UserContextSpec extends ObjectBehavior
29
{
30
    function let(
31
        RepositoryInterface $userRepository,
32
        SharedStorageInterface $sharedStorage,
33
        TestUserFactory $userFactory,
34
        FactoryInterface $addressFactory,
35
        ObjectManager $userManager
36
    ) {
37
        $this->beConstructedWith(
38
            $userRepository,
39
            $sharedStorage,
40
            $userFactory,
41
            $addressFactory,
42
            $userManager
43
        );
44
    }
45
46
    function it_is_initializable()
47
    {
48
        $this->shouldHaveType('Sylius\Behat\Context\Setup\UserContext');
49
    }
50
51
    function it_implements_context_interface()
52
    {
53
        $this->shouldImplement(Context::class);
54
    }
55
56
    function it_creates_user_with_given_credentials_and_default_data(
57
        $sharedStorage,
58
        $userFactory,
59
        $userRepository,
60
        UserInterface $user
61
    ) {
62
        $userFactory->create('[email protected]', 'pa$$word')->willReturn($user);
63
64
        $sharedStorage->setCurrentResource('user', $user)->shouldBeCalled();
65
        $userRepository->add($user)->shouldBeCalled();
66
67
        $this->thereIsUserIdentifiedBy('[email protected]', 'pa$$word');
68
    }
69
70
    function it_creates_user_with_given_credentials_default_data_and_shipping_address(
71
        $addressFactory,
72
        $sharedStorage,
73
        $userFactory,
74
        $userRepository,
75
        AddressInterface $address,
76
        CustomerInterface $customer,
77
        UserInterface $user
78
    ) {
79
        $userFactory->create('[email protected]', 'pa$$word')->willReturn($user);
80
        $user->getCustomer()->willReturn($customer);
81
82
        $customer->getFirstName()->willReturn('John');
83
        $customer->getLastName()->willReturn('Doe');
84
85
        $addressFactory->createNew()->willReturn($address);
86
        $address->setFirstName('John')->shouldBeCalled();
87
        $address->setLastName('Doe')->shouldBeCalled();
88
        $address->setStreet('Jones St. 114')->shouldBeCalled();
89
        $address->setCity('Paradise City')->shouldBeCalled();
90
        $address->setPostcode('99999')->shouldBeCalled();
91
        $address->setCountryCode('GB')->shouldBeCalled();
92
93
        $customer->setShippingAddress($address)->shouldBeCalled();
94
95
        $sharedStorage->setCurrentResource('user', $user)->shouldBeCalled();
96
        $userRepository->add($user)->shouldBeCalled();
97
98
        $this->thereIsUserWithShippingCountry('[email protected]', 'pa$$word', 'United Kingdom');
99
    }
100
101
    function it_sets_current_user_shipping_address(
102
        $addressFactory,
103
        $sharedStorage,
104
        $userManager,
105
        AddressInterface $address,
106
        CustomerInterface $customer,
107
        UserInterface $user
108
    ) {
109
        $sharedStorage->getCurrentResource('user')->willReturn($user);
110
        $user->getCustomer()->willReturn($customer);
111
112
        $customer->getFirstName()->willReturn('John');
113
        $customer->getLastName()->willReturn('Doe');
114
115
        $addressFactory->createNew()->willReturn($address);
116
        $address->setFirstName('John')->shouldBeCalled();
117
        $address->setLastName('Doe')->shouldBeCalled();
118
        $address->setStreet('Jones St. 114')->shouldBeCalled();
119
        $address->setCity('Paradise City')->shouldBeCalled();
120
        $address->setPostcode('99999')->shouldBeCalled();
121
        $address->setCountryCode('GB')->shouldBeCalled();
122
123
        $customer->setShippingAddress($address)->shouldBeCalled();
124
125
        $userManager->flush()->shouldBeCalled();
126
127
        $this->myDefaultShippingAddressIs('United Kingdom');
128
    }
129
}
130