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 { |
|
|
|
|
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
|
|
|
|
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.