Completed
Push — master ( b4619a...ab6ee6 )
by Kamil
12:06 queued 06:35
created

CustomerProviderSpec::it_is_a_customer_provider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
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
declare(strict_types=1);
13
14
namespace spec\Sylius\Bundle\ApiBundle\Provider;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Bundle\ApiBundle\Provider\CustomerProviderInterface;
18
use Sylius\Component\Core\Model\CustomerInterface;
19
use Sylius\Component\Core\Repository\CustomerRepositoryInterface;
20
use Sylius\Component\Resource\Factory\FactoryInterface;
21
use Sylius\Component\User\Canonicalizer\CanonicalizerInterface;
22
23
class CustomerProviderSpec extends ObjectBehavior
24
{
25
    function let(
26
        CanonicalizerInterface $canonicalizer,
27
        FactoryInterface $customerFactory,
28
        CustomerRepositoryInterface $customerRepository
29
    ): void {
30
        $this->beConstructedWith($canonicalizer, $customerFactory, $customerRepository);
31
    }
32
33
    function it_is_a_customer_provider(): void
34
    {
35
        $this->shouldImplement(CustomerProviderInterface::class);
36
    }
37
38
    function it_creates_a_customer_if_there_is_no_existing_one_with_given_email(
39
        CanonicalizerInterface $canonicalizer,
40
        FactoryInterface $customerFactory,
41
        CustomerRepositoryInterface $customerRepository,
42
        CustomerInterface $customer
43
    ): void {
44
        $canonicalizer->canonicalize('[email protected]')->willReturn('[email protected]');
45
        $customerRepository->findOneBy(['emailCanonical' => '[email protected]'])->willReturn(null);
46
47
        $customerFactory->createNew()->willReturn($customer);
48
        $customer->setEmail('[email protected]')->shouldBeCalled();
49
50
        $this->provide('[email protected]')->shouldReturn($customer);
51
    }
52
53
    function it_doesn_not_create_a_customer_if_customer_with_given_email_already_exists(
54
        CanonicalizerInterface $canonicalizer,
55
        FactoryInterface $customerFactory,
56
        CustomerRepositoryInterface $customerRepository,
57
        CustomerInterface $customer
58
    ): void {
59
        $canonicalizer->canonicalize('[email protected]')->willReturn('[email protected]');
60
        $customerRepository->findOneBy(['emailCanonical' => '[email protected]'])->willReturn($customer);
61
62
        $customerFactory->createNew()->shouldNotBeCalled();
63
64
        $this->provide('[email protected]')->shouldReturn($customer);
65
    }
66
}
67