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\Variation\Model; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Collections\Collection; |
15
|
|
|
use PhpSpec\ObjectBehavior; |
16
|
|
|
use Sylius\Component\Variation\Model\OptionInterface; |
17
|
|
|
use Sylius\Component\Variation\Model\OptionValueInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class OptionSpec extends ObjectBehavior |
23
|
|
|
{ |
24
|
|
|
public function let() |
25
|
|
|
{ |
26
|
|
|
$this->setCurrentLocale('en_US'); |
27
|
|
|
$this->setFallbackLocale('en_US'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function it_is_initializable() |
31
|
|
|
{ |
32
|
|
|
$this->shouldHaveType('Sylius\Component\Variation\Model\Option'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function it_implement_Sylius_option_interface() |
36
|
|
|
{ |
37
|
|
|
$this->shouldImplement(OptionInterface::class); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
function it_should_not_have_id_by_default() |
41
|
|
|
{ |
42
|
|
|
$this->getId()->shouldReturn(null); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function it_has_mutable_code() |
46
|
|
|
{ |
47
|
|
|
$this->setCode('O1'); |
48
|
|
|
$this->getCode()->shouldReturn('O1'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function it_should_not_have_name_by_default() |
52
|
|
|
{ |
53
|
|
|
$this->getName()->shouldReturn(null); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
function its_name_should_be_mutable() |
57
|
|
|
{ |
58
|
|
|
$this->setName('Size'); |
59
|
|
|
$this->getName()->shouldReturn('Size'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
function it_returns_name_when_converted_to_string() |
63
|
|
|
{ |
64
|
|
|
$this->setName('T-Shirt color'); |
65
|
|
|
$this->__toString()->shouldReturn('T-Shirt color'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
function it_should_initialize_values_collection_by_default() |
69
|
|
|
{ |
70
|
|
|
$this->getValues()->shouldHaveType(Collection::class); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function it_should_add_value(OptionValueInterface $value) |
74
|
|
|
{ |
75
|
|
|
$value->setOption($this)->shouldBeCalled(); |
76
|
|
|
|
77
|
|
|
$this->addValue($value); |
78
|
|
|
$this->hasValue($value)->shouldReturn(true); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
function it_should_remove_value(OptionValueInterface $value) |
82
|
|
|
{ |
83
|
|
|
$value->setOption($this)->shouldBeCalled(); |
84
|
|
|
|
85
|
|
|
$this->addValue($value); |
86
|
|
|
$this->hasValue($value)->shouldReturn(true); |
87
|
|
|
|
88
|
|
|
$value->setOption(null)->shouldBeCalled(); |
89
|
|
|
|
90
|
|
|
$this->removeValue($value); |
91
|
|
|
$this->hasValue($value)->shouldReturn(false); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
function it_should_initialize_creation_date_by_default() |
95
|
|
|
{ |
96
|
|
|
$this->getCreatedAt()->shouldHaveType(\DateTime::class); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
function it_should_not_have_last_update_date_by_default() |
100
|
|
|
{ |
101
|
|
|
$this->getUpdatedAt()->shouldReturn(null); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|