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\AddressingBundle\Validator\Constraints; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Prophecy\Argument; |
18
|
|
|
use Sylius\Bundle\AddressingBundle\Validator\Constraints\ZoneCannotContainItself; |
19
|
|
|
use Sylius\Component\Addressing\Model\ZoneInterface; |
20
|
|
|
use Sylius\Component\Addressing\Model\ZoneMemberInterface; |
21
|
|
|
use Symfony\Component\Validator\Constraint; |
22
|
|
|
use Symfony\Component\Validator\ConstraintValidatorInterface; |
23
|
|
|
use Symfony\Component\Validator\Context\ExecutionContextInterface; |
24
|
|
|
|
25
|
|
|
final class ZoneCannotContainItselfValidatorSpec extends ObjectBehavior |
26
|
|
|
{ |
27
|
|
|
function let(ExecutionContextInterface $executionContext): void |
28
|
|
|
{ |
29
|
|
|
$this->beConstructedWith(); |
30
|
|
|
$this->initialize($executionContext); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_is_a_constraint_validator(): void |
34
|
|
|
{ |
35
|
|
|
$this->shouldImplement(ConstraintValidatorInterface::class); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_does_nothing_if_value_is_null(ExecutionContextInterface $executionContext): void |
39
|
|
|
{ |
40
|
|
|
$executionContext->addViolation(Argument::cetera())->shouldNotBeCalled(); |
41
|
|
|
|
42
|
|
|
$this->validate(null, new ZoneCannotContainItself()); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function it_throws_an_exception_if_constraint_is_not_of_expected_type(): void |
46
|
|
|
{ |
47
|
|
|
$this |
48
|
|
|
->shouldThrow(\InvalidArgumentException::class) |
49
|
|
|
->during('validate', ['', new class() extends Constraint { |
|
|
|
|
50
|
|
|
}]) |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function it_does_not_add_violation_if_zone_does_not_contain_itself_in_members( |
55
|
|
|
ExecutionContextInterface $executionContext, |
56
|
|
|
ZoneInterface $zone, |
57
|
|
|
ZoneMemberInterface $zoneMember |
58
|
|
|
): void { |
59
|
|
|
$zone->getCode()->willReturn('WORLD'); |
60
|
|
|
$zoneMember->getCode()->willReturn('EU'); |
61
|
|
|
$zoneMember->getBelongsTo()->willReturn($zone); |
62
|
|
|
|
63
|
|
|
$executionContext->addViolation(Argument::cetera())->shouldNotBeCalled(); |
64
|
|
|
|
65
|
|
|
$this->validate([$zoneMember], new ZoneCannotContainItself()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
function it_adds_violation_if_zone_contains_itself_in_members( |
69
|
|
|
ExecutionContextInterface $executionContext, |
70
|
|
|
ZoneInterface $zone, |
71
|
|
|
ZoneMemberInterface $zoneMember |
72
|
|
|
): void { |
73
|
|
|
$zone->getCode()->willReturn('EU'); |
74
|
|
|
$zoneMember->getCode()->willReturn('EU'); |
75
|
|
|
$zoneMember->getBelongsTo()->willReturn($zone); |
76
|
|
|
|
77
|
|
|
$executionContext->addViolation(Argument::cetera())->shouldBeCalled(); |
78
|
|
|
|
79
|
|
|
$this->validate([$zoneMember], new ZoneCannotContainItself()); |
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.