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
|
|
|
$user->enable()->shouldBeCalled(); |
66
|
|
|
|
67
|
|
|
$sharedStorage->setCurrentResource('user', $user)->shouldBeCalled(); |
68
|
|
|
$userRepository->add($user)->shouldBeCalled(); |
69
|
|
|
|
70
|
|
|
$this->thereIsUserIdentifiedBy('[email protected]', 'pa$$word'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function it_creates_user_with_given_credentials_default_data_and_shipping_address( |
|
|
|
|
74
|
|
|
$addressFactory, |
75
|
|
|
$customerFactory, |
76
|
|
|
$sharedStorage, |
77
|
|
|
$userFactory, |
78
|
|
|
$userRepository, |
79
|
|
|
AddressInterface $address, |
80
|
|
|
CustomerInterface $customer, |
81
|
|
|
UserInterface $user |
82
|
|
|
) { |
83
|
|
|
$customerFactory->createNew()->willReturn($customer); |
84
|
|
|
$customer->setFirstName('John')->shouldBeCalled(); |
85
|
|
|
$customer->setLastName('Doe')->shouldBeCalled(); |
86
|
|
|
|
87
|
|
|
$customer->getFirstName()->willReturn('John'); |
88
|
|
|
$customer->getLastName()->willReturn('Doe'); |
89
|
|
|
|
90
|
|
|
$userFactory->createNew()->willReturn($user); |
91
|
|
|
$user->setCustomer($customer)->shouldBeCalled(); |
92
|
|
|
$user->setUsername('[email protected]')->shouldBeCalled(); |
93
|
|
|
$user->setEmail('[email protected]')->shouldBeCalled(); |
94
|
|
|
$user->setPlainPassword('pa$$word')->shouldBeCalled(); |
95
|
|
|
$user->enable()->shouldBeCalled(); |
96
|
|
|
|
97
|
|
|
$addressFactory->createNew()->willReturn($address); |
98
|
|
|
$address->setFirstName('John')->shouldBeCalled(); |
99
|
|
|
$address->setLastName('Doe')->shouldBeCalled(); |
100
|
|
|
$address->setStreet('Jones St. 114')->shouldBeCalled(); |
101
|
|
|
$address->setCity('Paradise City')->shouldBeCalled(); |
102
|
|
|
$address->setPostcode('99999')->shouldBeCalled(); |
103
|
|
|
$address->setCountryCode('GB')->shouldBeCalled(); |
104
|
|
|
|
105
|
|
|
$customer->setShippingAddress($address)->shouldBeCalled(); |
106
|
|
|
|
107
|
|
|
$sharedStorage->setCurrentResource('user', $user)->shouldBeCalled(); |
108
|
|
|
$userRepository->add($user)->shouldBeCalled(); |
109
|
|
|
|
110
|
|
|
$this->thereIsUserWithShippingCountry('[email protected]', 'pa$$word', 'United Kingdom'); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
This check marks method names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.