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

UniqueShopUserEmailValidatorSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 56
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 8 1
A it_is_a_constraint_validator() 0 4 1
A is_does_nothing_if_value_is_null() 0 6 1
A it_throws_an_exception_if_constraint_is_not_of_expected_type() 0 5 1
A it_does_not_add_violation_if_a_user_with_given_email_is_not_found() 0 12 1
A it_adds_violation_if_a_user_with_given_email_is_found() 0 13 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
declare(strict_types=1);
13
14
namespace spec\Sylius\Bundle\ApiBundle\Validator\Constraints;
15
16
use PhpSpec\ObjectBehavior;
17
use Prophecy\Argument;
18
use Sylius\Bundle\ApiBundle\Validator\Constraints\UniqueShopUserEmail;
19
use Sylius\Component\Core\Model\ShopUserInterface;
20
use Sylius\Component\User\Canonicalizer\CanonicalizerInterface;
21
use Sylius\Component\User\Repository\UserRepositoryInterface;
22
use Symfony\Component\Validator\Constraint;
23
use Symfony\Component\Validator\ConstraintValidatorInterface;
24
use Symfony\Component\Validator\Context\ExecutionContextInterface;
25
26
final class UniqueShopUserEmailValidatorSpec extends ObjectBehavior
27
{
28
    function let(
29
        CanonicalizerInterface $canonicalizer,
30
        UserRepositoryInterface $shopUserRepository,
31
        ExecutionContextInterface $executionContext
32
    ): void {
33
        $this->beConstructedWith($canonicalizer, $shopUserRepository);
34
        $this->initialize($executionContext);
35
    }
36
37
    function it_is_a_constraint_validator(): void
38
    {
39
        $this->shouldImplement(ConstraintValidatorInterface::class);
40
    }
41
42
    function is_does_nothing_if_value_is_null(ExecutionContextInterface $executionContext): void
43
    {
44
        $executionContext->addViolation(Argument::cetera())->shouldNotBeCalled();
45
46
        $this->validate(null, new UniqueShopUserEmail());
47
    }
48
49
    function it_throws_an_exception_if_constraint_is_not_of_expected_type(): void
50
    {
51
        $this->shouldThrow(\InvalidArgumentException::class)->during('validate', ['', new class() extends Constraint {
0 ignored issues
show
Coding Style introduced by
anonymous//src/Sylius/Bu...mailValidatorSpec.php$0 does not seem to conform to the naming convention (^[A-Z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
52
        }]);
53
    }
54
55
    function it_does_not_add_violation_if_a_user_with_given_email_is_not_found(
56
        CanonicalizerInterface $canonicalizer,
57
        UserRepositoryInterface $shopUserRepository,
58
        ExecutionContextInterface $executionContext
59
    ): void {
60
        $canonicalizer->canonicalize('[email protected]')->willReturn('[email protected]');
61
        $shopUserRepository->findOneByEmail('[email protected]')->willReturn(null);
62
63
        $executionContext->addViolation(Argument::cetera())->shouldNotBeCalled();
64
65
        $this->validate('[email protected]', new UniqueShopUserEmail());
66
    }
67
68
    function it_adds_violation_if_a_user_with_given_email_is_found(
69
        CanonicalizerInterface $canonicalizer,
70
        UserRepositoryInterface $shopUserRepository,
71
        ExecutionContextInterface $executionContext,
72
        ShopUserInterface $shopUser
73
    ): void {
74
        $canonicalizer->canonicalize('[email protected]')->willReturn('[email protected]');
75
        $shopUserRepository->findOneByEmail('[email protected]')->willReturn($shopUser);
76
77
        $executionContext->addViolation(Argument::cetera())->shouldBeCalled();
78
79
        $this->validate('[email protected]', new UniqueShopUserEmail());
80
    }
81
}
82