Completed
Push — 1.0-community-org ( 019488 )
by Kamil
24:49
created

AttributeSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 0
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\Model;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Attribute\AttributeType\CheckboxAttributeType;
18
use Sylius\Component\Attribute\AttributeType\TextAttributeType;
19
use Sylius\Component\Attribute\Model\Attribute;
20
use Sylius\Component\Attribute\Model\AttributeInterface;
21
22
/**
23
 * @author Paweł Jędrzejewski <[email protected]>
24
 * @author Gonzalo Vilaseca <[email protected]>
25
 */
26
final class AttributeSpec extends ObjectBehavior
27
{
28
    function let(): void
29
    {
30
        $this->setCurrentLocale('en_US');
31
        $this->setFallbackLocale('en_US');
32
    }
33
34
    function it_is_initializable(): void
35
    {
36
        $this->shouldHaveType(Attribute::class);
37
    }
38
39
    function it_implements_attribute_interface(): void
40
    {
41
        $this->shouldImplement(AttributeInterface::class);
42
    }
43
44
    function it_has_no_id_by_default(): void
45
    {
46
        $this->getId()->shouldReturn(null);
47
    }
48
49
    function its_code_is_mutable(): void
50
    {
51
        $this->setCode('t_shirt_collection');
52
        $this->getCode()->shouldReturn('t_shirt_collection');
53
    }
54
55
    function it_has_no_name_by_default(): void
56
    {
57
        $this->getName()->shouldReturn(null);
58
    }
59
60
    function its_name_is_mutable(): void
61
    {
62
        $this->setName('T-Shirt collection');
63
        $this->getName()->shouldReturn('T-Shirt collection');
64
    }
65
66
    function it_returns_name_when_converted_to_string(): void
67
    {
68
        $this->setName('T-Shirt material');
69
        $this->__toString()->shouldReturn('T-Shirt material');
70
    }
71
72
    function it_has_text_type_by_default(): void
73
    {
74
        $this->getType()->shouldReturn(TextAttributeType::TYPE);
75
    }
76
77
    function its_type_is_mutable(): void
78
    {
79
        $this->setType(CheckboxAttributeType::TYPE);
80
        $this->getType()->shouldReturn(CheckboxAttributeType::TYPE);
81
    }
82
83
    function it_initializes_empty_configuration_array_by_default(): void
84
    {
85
        $this->getConfiguration()->shouldReturn([]);
86
    }
87
88
    function its_configuration_is_mutable(): void
89
    {
90
        $this->setConfiguration(['format' => 'd/m/Y']);
91
        $this->getConfiguration()->shouldReturn(['format' => 'd/m/Y']);
92
    }
93
94
    function its_storage_type_is_mutable(): void
95
    {
96
        $this->setStorageType('text');
97
        $this->getStorageType()->shouldReturn('text');
98
    }
99
100
    function it_initializes_creation_date_by_default(): void
101
    {
102
        $this->getCreatedAt()->shouldHaveType(\DateTimeInterface::class);
103
    }
104
105
    function its_creation_date_is_mutable(\DateTime $date): void
106
    {
107
        $this->setCreatedAt($date);
108
        $this->getCreatedAt()->shouldReturn($date);
109
    }
110
111
    function it_has_no_last_update_date_by_default(): void
112
    {
113
        $this->getUpdatedAt()->shouldReturn(null);
114
    }
115
116
    function its_last_update_date_is_mutable(\DateTime $date): void
117
    {
118
        $this->setUpdatedAt($date);
119
        $this->getUpdatedAt()->shouldReturn($date);
120
    }
121
122
    function it_has_position(): void
123
    {
124
        $this->getPosition()->shouldReturn(null);
125
        $this->setPosition(0);
126
        $this->getPosition()->shouldReturn(0);
127
    }
128
}
129