Completed
Push — master ( 9800c9...34c9ed )
by Kamil
18:26
created

TextAttributeTypeSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
lcom 0
cbo 7
dl 0
loc 52
rs 10
c 1
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A it_is_initializable() 0 4 1
A it_implements_attribute_type_interface() 0 4 1
A its_storage_type_is_text() 0 4 1
A its_type_is_text() 0 4 1
B it_checks_if_attribute_value_is_valid() 0 29 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
namespace spec\Sylius\Component\Attribute\AttributeType;
13
14
use PhpSpec\ObjectBehavior;
15
use Prophecy\Argument;
16
use Sylius\Component\Attribute\AttributeType\AttributeTypeInterface;
17
use Sylius\Component\Attribute\Model\AttributeInterface;
18
use Sylius\Component\Attribute\Model\AttributeValueInterface;
19
use Symfony\Component\Validator\Constraints\Length;
20
use Symfony\Component\Validator\ConstraintViolationInterface;
21
use Symfony\Component\Validator\ConstraintViolationListInterface;
22
use Symfony\Component\Validator\Context\ExecutionContextInterface;
23
use Symfony\Component\Validator\Validator\ValidatorInterface;
24
use Symfony\Component\Validator\Violation\ConstraintViolationBuilderInterface;
25
26
/**
27
 * @author Mateusz Zalewski <[email protected]>
28
 */
29
class TextAttributeTypeSpec extends ObjectBehavior
30
{
31
    function it_is_initializable()
32
    {
33
        $this->shouldHaveType('Sylius\Component\Attribute\AttributeType\TextAttributeType');
34
    }
35
36
    function it_implements_attribute_type_interface()
37
    {
38
        $this->shouldImplement(AttributeTypeInterface::class);
39
    }
40
41
    function its_storage_type_is_text()
42
    {
43
        $this->getStorageType()->shouldReturn('text');
44
    }
45
46
    function its_type_is_text()
47
    {
48
        $this->getType()->shouldReturn('text');
49
    }
50
51
    function it_checks_if_attribute_value_is_valid(
52
        AttributeInterface $attribute,
53
        AttributeValueInterface $attributeValue,
54
        ConstraintViolationBuilderInterface $constraintViolationBuilder,
55
        ConstraintViolationInterface $constraintViolation,
56
        ConstraintViolationListInterface $constraintViolationList,
57
        ExecutionContextInterface $context,
58
        ValidatorInterface $validator
59
    ) {
60
        $attributeValue->getAttribute()->willReturn($attribute);
61
62
        $attributeValue->getValue()->willReturn('X');
63
64
        $context->getValidator()->willReturn($validator);
65
        $validator->validate('X', Argument::type(Length::class))->willReturn($constraintViolationList);
66
67
        $constraintViolationList->rewind()->shouldBeCalled();
68
        $constraintViolationList->valid()->willReturn(true, false);
69
        $constraintViolationList->current()->willReturn($constraintViolation);
70
        $constraintViolationList->next()->shouldBeCalled();
71
72
        $constraintViolation->getMessage()->willReturn('error message');
73
74
        $context->buildViolation('error message')->willReturn($constraintViolationBuilder);
75
        $constraintViolationBuilder->atPath('value')->willReturn($constraintViolationBuilder);
76
        $constraintViolationBuilder->addViolation()->shouldBeCalled();
77
78
        $this->validate($attributeValue, $context, array('min' => 2, 'max' => 255));
79
    }
80
}
81