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\CustomerInterface; |
17
|
|
|
use Sylius\Component\Core\Test\Services\SharedStorageInterface; |
18
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
19
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Łukasz Chruściel <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class CustomerContextSpec extends ObjectBehavior |
25
|
|
|
{ |
26
|
|
|
function let( |
27
|
|
|
RepositoryInterface $customerRepository, |
28
|
|
|
FactoryInterface $customerFactory |
29
|
|
|
) { |
30
|
|
|
$this->beConstructedWith($customerRepository, $customerFactory); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_is_initializable() |
34
|
|
|
{ |
35
|
|
|
$this->shouldHaveType('Sylius\Behat\Context\Setup\CustomerContext'); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_implements_context_interface() |
39
|
|
|
{ |
40
|
|
|
$this->shouldImplement(Context::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_creates_new_customer_if_it_does_not_exist( |
44
|
|
|
CustomerInterface $customer, |
45
|
|
|
FactoryInterface $customerFactory, |
46
|
|
|
RepositoryInterface $customerRepository |
47
|
|
|
) { |
48
|
|
|
$customerRepository->findOneBy(['email' => '[email protected]'])->willReturn(null); |
49
|
|
|
|
50
|
|
|
$customerFactory->createNew()->willReturn($customer); |
51
|
|
|
$customer->setEmail('[email protected]')->shouldBeCalled(); |
52
|
|
|
|
53
|
|
|
$customerRepository->add($customer)->shouldBeCalled(); |
54
|
|
|
|
55
|
|
|
$this->getOrCreateCustomerByEmail('[email protected]')->shouldReturn($customer); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
function it_provides_new_customer_from_repository_if_it_exists( |
59
|
|
|
CustomerInterface $customer, |
60
|
|
|
RepositoryInterface $customerRepository |
61
|
|
|
) { |
62
|
|
|
$customerRepository->findOneBy(['email' => '[email protected]'])->willReturn($customer); |
63
|
|
|
|
64
|
|
|
$this->getOrCreateCustomerByEmail('[email protected]')->shouldReturn($customer); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|