Completed
Push — master ( 749f69...94328c )
by Kamil
27:45
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 0
Metric Value
c 1
b 0
f 0
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 PhpSpec\ObjectBehavior;
16
use Sylius\Component\Core\Model\AddressInterface;
17
use Sylius\Component\Core\Model\CustomerInterface;
18
use Sylius\Component\Core\Model\UserInterface;
19
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
20
use Sylius\Component\Resource\Factory\FactoryInterface;
21
use Sylius\Component\Resource\Repository\RepositoryInterface;
22
23
/**
24
 * @author Mateusz Zalewski <[email protected]>
25
 */
26
class UserContextSpec extends ObjectBehavior
27
{
28
    function let(
29
        RepositoryInterface $userRepository,
30
        SharedStorageInterface $sharedStorage,
31
        FactoryInterface $userFactory,
32
        FactoryInterface $customerFactory,
33
        FactoryInterface $addressFactory
34
    ) {
35
        $this->beConstructedWith($userRepository, $sharedStorage, $userFactory, $customerFactory, $addressFactory);
36
    }
37
38
    function it_is_initializable()
39
    {
40
        $this->shouldHaveType('Sylius\Behat\Context\Setup\UserContext');
41
    }
42
43
    function it_implements_context_interface()
44
    {
45
        $this->shouldImplement(Context::class);
46
    }
47
48
    function it_creates_user_with_given_credentials_and_default_data(
49
        $customerFactory,
50
        $sharedStorage,
51
        $userFactory,
52
        $userRepository,
53
        CustomerInterface $customer,
54
        UserInterface $user
55
    ) {
56
        $customerFactory->createNew()->willReturn($customer);
57
        $customer->setFirstName('John')->shouldBeCalled();
58
        $customer->setLastName('Doe')->shouldBeCalled();
59
60
        $userFactory->createNew()->willReturn($user);
61
        $user->setCustomer($customer)->shouldBeCalled();
62
        $user->setUsername('[email protected]')->shouldBeCalled();
63
        $user->setEmail('[email protected]')->shouldBeCalled();
64
        $user->setPlainPassword('pa$$word')->shouldBeCalled();
65
66
        $sharedStorage->setCurrentResource('user', $user)->shouldBeCalled();
67
        $userRepository->add($user)->shouldBeCalled();
68
69
        $this->thereIsUserIdentifiedBy('[email protected]', 'pa$$word');
70
    }
71
72
    function it_creates_user_with_given_credentials_default_data_and_shipping_address(
73
        $addressFactory,
74
        $customerFactory,
75
        $sharedStorage,
76
        $userFactory,
77
        $userRepository,
78
        AddressInterface $address,
79
        CustomerInterface $customer,
80
        UserInterface $user
81
    ) {
82
        $customerFactory->createNew()->willReturn($customer);
83
        $customer->setFirstName('John')->shouldBeCalled();
84
        $customer->setLastName('Doe')->shouldBeCalled();
85
86
        $customer->getFirstName()->willReturn('John');
87
        $customer->getLastName()->willReturn('Doe');
88
89
        $userFactory->createNew()->willReturn($user);
90
        $user->setCustomer($customer)->shouldBeCalled();
91
        $user->setUsername('[email protected]')->shouldBeCalled();
92
        $user->setEmail('[email protected]')->shouldBeCalled();
93
        $user->setPlainPassword('pa$$word')->shouldBeCalled();
94
95
        $addressFactory->createNew()->willReturn($address);
96
        $address->setFirstName('John')->shouldBeCalled();
97
        $address->setLastName('Doe')->shouldBeCalled();
98
        $address->setStreet('Jones St. 114')->shouldBeCalled();
99
        $address->setCity('Paradise City')->shouldBeCalled();
100
        $address->setPostcode('99999')->shouldBeCalled();
101
        $address->setCountryCode('GB')->shouldBeCalled();
102
103
        $customer->setShippingAddress($address)->shouldBeCalled();
104
105
        $sharedStorage->setCurrentResource('user', $user)->shouldBeCalled();
106
        $userRepository->add($user)->shouldBeCalled();
107
108
        $this->thereIsUserWithShippingCountry('[email protected]', 'pa$$word', 'United Kingdom');
109
    }
110
}
111