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

AttributeFactorySpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_attribute_factory_interface() 0 4 1
A it_creates_new_attribute() 0 12 1
A it_creates_typed_attribute() 0 13 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\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