Completed
Push — master ( ab6ee6...8da333 )
by Kamil
32:30 queued 09:03
created

ZoneCannotContainItselfValidatorSpec   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 5 1
A it_is_a_constraint_validator() 0 4 1
A it_does_nothing_if_value_is_null() 0 6 1
A it_throws_an_exception_if_constraint_is_not_of_expected_type() 0 8 1
A it_does_not_add_violation_if_zone_does_not_contain_itself_in_members() 0 13 1
A it_adds_violation_if_zone_contains_itself_in_members() 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\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 {
0 ignored issues
show
Coding Style introduced by
anonymous//src/Sylius/Bu...selfValidatorSpec.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...
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