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

AttributeFactorySpec::it_creates_new_attribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 12
rs 9.4286
c 1
b 1
f 0
cc 1
eloc 7
nc 1
nop 4
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\Factory;
13
14
use PhpSpec\ObjectBehavior;
15
use Sylius\Component\Attribute\AttributeType\AttributeTypeInterface;
16
use Sylius\Component\Attribute\Factory\AttributeFactoryInterface;
17
use Sylius\Component\Attribute\Model\Attribute;
18
use Sylius\Component\Registry\ServiceRegistryInterface;
19
use Sylius\Component\Resource\Factory\FactoryInterface;
20
21
/**
22
 * @author Mateusz Zalewski <[email protected]>
23
 */
24
class AttributeFactorySpec extends ObjectBehavior
25
{
26
    function let(FactoryInterface $factory, ServiceRegistryInterface $attributeTypesRegistry)
27
    {
28
        $this->beConstructedWith($factory, $attributeTypesRegistry);
29
    }
30
31
    function it_is_initializable()
32
    {
33
        $this->shouldHaveType('Sylius\Component\Attribute\Factory\AttributeFactory');
34
    }
35
36
    function it_implements_attribute_factory_interface()
37
    {
38
        $this->shouldImplement(AttributeFactoryInterface::class);
39
    }
40
41
    function it_creates_new_attribute($attributeTypesRegistry, $factory, Attribute $attribute, AttributeTypeInterface $attributeType)
42
    {
43
        $factory->createNew()->willReturn($attribute);
44
45
        $attributeType->getStorageType()->willReturn('text');
46
        $attributeTypesRegistry->get('text')->willReturn($attributeType);
47
48
        $attribute->getType()->willReturn('text');
49
        $attribute->setStorageType('text')->shouldBeCalled();
50
51
        $this->createNew()->shouldReturn($attribute);
52
    }
53
54
    function it_creates_typed_attribute($attributeTypesRegistry, $factory, Attribute $typedAttribute, AttributeTypeInterface $attributeType)
55
    {
56
        $factory->createNew()->willReturn($typedAttribute);
57
58
        $attributeType->getStorageType()->willReturn('datetime');
59
        $attributeTypesRegistry->get('datetime')->willReturn($attributeType);
60
61
        $typedAttribute->setType('datetime')->shouldBeCalled();
62
        $typedAttribute->getType()->willReturn('datetime');
63
        $typedAttribute->setStorageType('datetime')->shouldBeCalled();
64
65
        $this->createTyped('datetime')->shouldReturn($typedAttribute);
66
    }
67
}
68