Completed
Push — master ( 4f4b30...79d213 )
by Kamil
49:20 queued 33s
created

CustomerContextSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
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