|
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\Promotion\Model; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\Collection; |
|
17
|
|
|
use PhpSpec\ObjectBehavior; |
|
18
|
|
|
use Sylius\Component\Promotion\Model\PromotionActionInterface; |
|
19
|
|
|
use Sylius\Component\Promotion\Model\PromotionCouponInterface; |
|
20
|
|
|
use Sylius\Component\Promotion\Model\PromotionInterface; |
|
21
|
|
|
use Sylius\Component\Promotion\Model\PromotionRuleInterface; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @author Saša Stamenković <[email protected]> |
|
25
|
|
|
*/ |
|
26
|
|
|
final class PromotionSpec extends ObjectBehavior |
|
27
|
|
|
{ |
|
28
|
|
|
function it_is_a_promotion(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$this->shouldImplement(PromotionInterface::class); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
function it_does_not_have_id_by_default(): void |
|
34
|
|
|
{ |
|
35
|
|
|
$this->getId()->shouldReturn(null); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
function it_has_mutable_code(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->setCode('P1'); |
|
41
|
|
|
$this->getCode()->shouldReturn('P1'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function its_name_is_mutable(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$this->setName('New Year Sale'); |
|
47
|
|
|
$this->getName()->shouldReturn('New Year Sale'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
function its_description_is_mutable(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$this->setDescription('New Year Sale 50% off.'); |
|
53
|
|
|
$this->getDescription()->shouldReturn('New Year Sale 50% off.'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
function its_priority_is_mutable(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->setPriority(5); |
|
59
|
|
|
$this->getPriority()->shouldReturn(5); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
function its_not_exclusive_by_default(): void |
|
63
|
|
|
{ |
|
64
|
|
|
$this->isExclusive()->shouldReturn(false); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
function its_exclusive_is_mutable(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$this->setExclusive(true); |
|
70
|
|
|
$this->isExclusive()->shouldReturn(true); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
function it_does_not_have_usage_limit_by_default(): void |
|
74
|
|
|
{ |
|
75
|
|
|
$this->getUsageLimit()->shouldReturn(null); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
function its_usage_limit_is_mutable(): void |
|
79
|
|
|
{ |
|
80
|
|
|
$this->setUsageLimit(10); |
|
81
|
|
|
$this->getUsageLimit()->shouldReturn(10); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
function it_does_not_have_used_by_default(): void |
|
85
|
|
|
{ |
|
86
|
|
|
$this->getUsed()->shouldReturn(0); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
function its_used_is_mutable(): void |
|
90
|
|
|
{ |
|
91
|
|
|
$this->setUsed(5); |
|
92
|
|
|
$this->getUsed()->shouldReturn(5); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
function its_increments_and_decrements_its_used_value(): void |
|
96
|
|
|
{ |
|
97
|
|
|
$this->incrementUsed(); |
|
98
|
|
|
$this->incrementUsed(); |
|
99
|
|
|
$this->getUsed()->shouldReturn(2); |
|
100
|
|
|
|
|
101
|
|
|
$this->decrementUsed(); |
|
102
|
|
|
$this->getUsed()->shouldReturn(1); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
function its_starts_at_is_mutable(\DateTime $date): void |
|
106
|
|
|
{ |
|
107
|
|
|
$this->setStartsAt($date); |
|
108
|
|
|
$this->getStartsAt()->shouldReturn($date); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
function its_ends_at_is_mutable(\DateTime $date): void |
|
112
|
|
|
{ |
|
113
|
|
|
$this->setEndsAt($date); |
|
114
|
|
|
$this->getEndsAt()->shouldReturn($date); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
function it_initializes_coupons_collection_by_default(): void |
|
118
|
|
|
{ |
|
119
|
|
|
$this->getCoupons()->shouldHaveType(Collection::class); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
function it_adds_coupons_properly(PromotionCouponInterface $coupon): void |
|
123
|
|
|
{ |
|
124
|
|
|
$this->hasCoupon($coupon)->shouldReturn(false); |
|
125
|
|
|
|
|
126
|
|
|
$coupon->setPromotion($this)->shouldBeCalled(); |
|
127
|
|
|
$this->addCoupon($coupon); |
|
128
|
|
|
|
|
129
|
|
|
$this->hasCoupon($coupon)->shouldReturn(true); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
function it_removes_coupons_properly(PromotionCouponInterface $coupon): void |
|
133
|
|
|
{ |
|
134
|
|
|
$this->hasCoupon($coupon)->shouldReturn(false); |
|
135
|
|
|
|
|
136
|
|
|
$coupon->setPromotion($this)->shouldBeCalled(); |
|
137
|
|
|
$this->addCoupon($coupon); |
|
138
|
|
|
|
|
139
|
|
|
$coupon->setPromotion(null)->shouldBeCalled(); |
|
140
|
|
|
$this->removeCoupon($coupon); |
|
141
|
|
|
|
|
142
|
|
|
$this->hasCoupon($coupon)->shouldReturn(false); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
function it_initializes_rules_collection_by_default(): void |
|
146
|
|
|
{ |
|
147
|
|
|
$this->getRules()->shouldHaveType(Collection::class); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
function it_adds_rules_properly(PromotionRuleInterface $rule): void |
|
151
|
|
|
{ |
|
152
|
|
|
$this->hasRule($rule)->shouldReturn(false); |
|
153
|
|
|
|
|
154
|
|
|
$rule->setPromotion($this)->shouldBeCalled(); |
|
155
|
|
|
$this->addRule($rule); |
|
156
|
|
|
|
|
157
|
|
|
$this->hasRule($rule)->shouldReturn(true); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
function it_removes_rules_properly(PromotionRuleInterface $rule): void |
|
161
|
|
|
{ |
|
162
|
|
|
$this->hasRule($rule)->shouldReturn(false); |
|
163
|
|
|
|
|
164
|
|
|
$rule->setPromotion($this)->shouldBeCalled(); |
|
165
|
|
|
$this->addRule($rule); |
|
166
|
|
|
|
|
167
|
|
|
$rule->setPromotion(null)->shouldBeCalled(); |
|
168
|
|
|
$this->removeRule($rule); |
|
169
|
|
|
|
|
170
|
|
|
$this->hasRule($rule)->shouldReturn(false); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
function it_initializes_actions_collection_by_default(): void |
|
174
|
|
|
{ |
|
175
|
|
|
$this->getActions()->shouldHaveType(Collection::class); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
function it_adds_actions_properly(PromotionActionInterface $action): void |
|
179
|
|
|
{ |
|
180
|
|
|
$this->hasAction($action)->shouldReturn(false); |
|
181
|
|
|
|
|
182
|
|
|
$action->setPromotion($this)->shouldBeCalled(); |
|
183
|
|
|
$this->addAction($action); |
|
184
|
|
|
|
|
185
|
|
|
$this->hasAction($action)->shouldReturn(true); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
function it_removes_actions_properly(PromotionActionInterface $action): void |
|
189
|
|
|
{ |
|
190
|
|
|
$this->hasAction($action)->shouldReturn(false); |
|
191
|
|
|
|
|
192
|
|
|
$action->setPromotion($this)->shouldBeCalled(); |
|
193
|
|
|
$this->addAction($action); |
|
194
|
|
|
|
|
195
|
|
|
$action->setPromotion(null)->shouldBeCalled(); |
|
196
|
|
|
$this->removeAction($action); |
|
197
|
|
|
|
|
198
|
|
|
$this->hasAction($action)->shouldReturn(false); |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|