Completed
Push — master ( 749f69...94328c )
by Kamil
27:45
created

UserContextSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 4
dl 0
loc 85
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 9 1
A it_is_initializable() 0 4 1
A it_implements_context_interface() 0 4 1
A it_creates_user_with_given_credentials_and_default_data() 0 23 1
B it_creates_user_with_given_credentials_default_data_and_shipping_address() 0 38 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
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