Completed
Push — scalar-types/order ( bd3d7c )
by Kamil
21:55
created

it_allows_detaching_itself_from_a_subject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 5
nop 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\Component\Attribute\Model;
15
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Component\Attribute\Model\AttributeInterface;
18
use Sylius\Component\Attribute\Model\AttributeSubjectInterface;
19
use Sylius\Component\Attribute\Model\AttributeValue;
20
use Sylius\Component\Attribute\Model\AttributeValueInterface;
21
22
/**
23
 * @author Paweł Jędrzejewski <[email protected]>
24
 * @author Mateusz Zalewski <[email protected]>
25
 */
26
final class AttributeValueSpec extends ObjectBehavior
27
{
28
    function it_is_initializable(): void
29
    {
30
        $this->shouldHaveType(AttributeValue::class);
31
    }
32
33
    function it_implements_Sylius_subject_attribute_interface(): void
0 ignored issues
show
Coding Style introduced by
function it_implements_S...t_attribute_interface() does not seem to conform to the naming convention (^(?:(?:[a-z]|__)[a-zA-Z0-9]*|[a-z][a-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...
34
    {
35
        $this->shouldImplement(AttributeValueInterface::class);
36
    }
37
38
    function it_has_no_id_by_default(): void
39
    {
40
        $this->getId()->shouldReturn(null);
41
    }
42
43
    function it_does_not_belong_to_a_subject_by_default(): void
44
    {
45
        $this->getSubject()->shouldReturn(null);
46
    }
47
48
    function it_allows_assigning_itself_to_a_subject(AttributeSubjectInterface $subject): void
49
    {
50
        $this->setSubject($subject);
51
        $this->getSubject()->shouldReturn($subject);
52
    }
53
54
    function it_has_no_attribute_defined_by_default(): void
55
    {
56
        $this->getAttribute()->shouldReturn(null);
57
    }
58
59
    function its_attribute_is_definable(AttributeInterface $attribute): void
60
    {
61
        $this->setAttribute($attribute);
62
        $this->getAttribute()->shouldReturn($attribute);
63
    }
64
65
    function it_has_no_default_locale_code(): void
66
    {
67
        $this->getLocaleCode()->shouldReturn(null);
68
    }
69
70
    function its_locale_code_is_mutable(): void
71
    {
72
        $this->setLocaleCode('en');
73
        $this->getLocaleCode()->shouldReturn('en');
74
    }
75
76
    function it_has_no_value_by_default(): void
77
    {
78
        $this->getValue()->shouldReturn(null);
79
    }
80
81
    function its_value_is_mutable_based_on_attribute_storage_type(AttributeInterface $attribute): void
82
    {
83
        $storageTypeToExampleData = [
84
            'boolean' => false,
85
            'text' => 'Lorem ipsum',
86
            'integer' => 42,
87
            'float' => 6.66,
88
            'datetime' => new \DateTime(),
89
            'date' => new \DateTime(),
90
            'json' => ['foo' => 'bar'],
91
        ];
92
93
        foreach ($storageTypeToExampleData as $storageType => $exampleData) {
94
            $attribute->getStorageType()->willReturn($storageType);
95
            $this->setAttribute($attribute);
96
97
            $this->setValue($exampleData);
98
            $this->getValue()->shouldReturn($exampleData);
99
        }
100
    }
101
102
    function its_value_can_be_set_to_null(AttributeInterface $attribute): void
103
    {
104
        $storageTypes = [
105
            'boolean',
106
            'text',
107
            'integer',
108
            'float',
109
            'datetime',
110
            'date',
111
            'json',
112
        ];
113
114
        foreach ($storageTypes as $storageType) {
115
            $attribute->getStorageType()->willReturn($storageType);
116
            $this->setAttribute($attribute);
117
118
            $this->setValue(null);
119
            $this->getValue()->shouldReturn(null);
120
        }
121
    }
122
123
    function it_throws_exception_when_trying_to_get_code_without_attribute_defined(): void
124
    {
125
        $this
126
            ->shouldThrow(\BadMethodCallException::class)
127
            ->during('getCode')
128
        ;
129
    }
130
131
    function it_returns_its_attribute_code(AttributeInterface $attribute): void
132
    {
133
        $attribute->getCode()->willReturn('tshirt_material');
134
        $this->setAttribute($attribute);
135
136
        $this->getCode()->shouldReturn('tshirt_material');
137
    }
138
139
    function it_throws_exception_when_trying_to_get_name_without_attribute_defined(): void
140
    {
141
        $this
142
            ->shouldThrow(\BadMethodCallException::class)
143
            ->during('getName')
144
        ;
145
    }
146
147
    function it_returns_its_attribute_name(AttributeInterface $attribute): void
148
    {
149
        $attribute->getName()->willReturn('T-Shirt material');
150
        $this->setAttribute($attribute);
151
152
        $this->getName()->shouldReturn('T-Shirt material');
153
    }
154
155
    function it_throws_exception_when_trying_to_get_type_without_attribute_defined(): void
156
    {
157
        $this
158
            ->shouldThrow(\BadMethodCallException::class)
159
            ->during('getType')
160
        ;
161
    }
162
163
    function it_returns_its_attribute_type(AttributeInterface $attribute): void
164
    {
165
        $attribute->getType()->willReturn('choice');
166
        $this->setAttribute($attribute);
167
168
        $this->getType()->shouldReturn('choice');
169
    }
170
}
171