|
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
|
|
|
|