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