|
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\Core\Model; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use Doctrine\Common\Collections\Collection; |
|
18
|
|
|
use PhpSpec\ObjectBehavior; |
|
19
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
20
|
|
|
use Sylius\Component\Core\Model\ChannelPricingInterface; |
|
21
|
|
|
use Sylius\Component\Core\Model\Product; |
|
22
|
|
|
use Sylius\Component\Core\Model\ProductImageInterface; |
|
23
|
|
|
use Sylius\Component\Core\Model\ProductImagesAwareInterface; |
|
24
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
|
25
|
|
|
use Sylius\Component\Product\Model\ProductVariant as BaseProductVariant; |
|
26
|
|
|
use Sylius\Component\Resource\Model\VersionedInterface; |
|
27
|
|
|
use Sylius\Component\Shipping\Model\ShippableInterface; |
|
28
|
|
|
use Sylius\Component\Shipping\Model\ShippingCategoryInterface; |
|
29
|
|
|
use Sylius\Component\Taxation\Model\TaxableInterface; |
|
30
|
|
|
use Sylius\Component\Taxation\Model\TaxCategoryInterface; |
|
31
|
|
|
|
|
32
|
|
|
final class ProductVariantSpec extends ObjectBehavior |
|
33
|
|
|
{ |
|
34
|
|
|
function it_implements_a_product_variant_interface(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$this->shouldImplement(ProductVariantInterface::class); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
function it_implements_a_taxable_interface(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$this->shouldImplement(TaxableInterface::class); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
function it_extends_a_product_variant_model(): void |
|
45
|
|
|
{ |
|
46
|
|
|
$this->shouldHaveType(BaseProductVariant::class); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
function it_implements_a_shippable_interface(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->shouldImplement(ShippableInterface::class); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function it_implements_versioned_interface(): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->shouldImplement(VersionedInterface::class); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
function it_implements_a_product_image_aware_interface(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$this->shouldImplement(ProductImagesAwareInterface::class); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
function it_has_version_1_by_default(): void |
|
65
|
|
|
{ |
|
66
|
|
|
$this->getVersion()->shouldReturn(1); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
function it_has_no_weight_by_default(): void |
|
70
|
|
|
{ |
|
71
|
|
|
$this->getWeight()->shouldReturn(null); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
function its_weight_is_mutable(): void |
|
75
|
|
|
{ |
|
76
|
|
|
$this->setWeight(120.00); |
|
77
|
|
|
$this->getWeight()->shouldReturn(120.00); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
function it_has_no_width_by_default(): void |
|
81
|
|
|
{ |
|
82
|
|
|
$this->getWidth()->shouldReturn(null); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
function its_width_is_mutable(): void |
|
86
|
|
|
{ |
|
87
|
|
|
$this->setWidth(15.00); |
|
88
|
|
|
$this->getWidth()->shouldReturn(15.00); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
function it_has_no_height_by_default(): void |
|
92
|
|
|
{ |
|
93
|
|
|
$this->getHeight()->shouldReturn(null); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
function its_height_is_mutable(): void |
|
97
|
|
|
{ |
|
98
|
|
|
$this->setHeight(40.00); |
|
99
|
|
|
$this->getHeight()->shouldReturn(40.00); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
function it_returns_correct_shipping_weight(): void |
|
103
|
|
|
{ |
|
104
|
|
|
$this->setWeight(140.00); |
|
105
|
|
|
$this->getShippingWeight()->shouldReturn(140.00); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
function it_returns_correct_shipping_volume(): void |
|
109
|
|
|
{ |
|
110
|
|
|
$this->setWidth(10.00); |
|
111
|
|
|
$this->setHeight(20.00); |
|
112
|
|
|
$this->setDepth(10.00); |
|
113
|
|
|
$this->getShippingVolume()->shouldReturn(2000.00); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
function it_returns_correct_shipping_width(): void |
|
117
|
|
|
{ |
|
118
|
|
|
$this->setWidth(100.00); |
|
119
|
|
|
$this->getShippingWidth()->shouldReturn(100.00); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
function it_returns_correct_shipping_height(): void |
|
123
|
|
|
{ |
|
124
|
|
|
$this->setHeight(110.00); |
|
125
|
|
|
$this->getShippingHeight()->shouldReturn(110.00); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
function it_has_no_code_by_default(): void |
|
129
|
|
|
{ |
|
130
|
|
|
$this->getCode()->shouldReturn(null); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
function its_code_is_mutable(): void |
|
134
|
|
|
{ |
|
135
|
|
|
$this->setCode('dummy-sku123'); |
|
136
|
|
|
$this->getCode()->shouldReturn('dummy-sku123'); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
function it_does_not_have_tax_category_by_default(): void |
|
140
|
|
|
{ |
|
141
|
|
|
$this->getTaxCategory()->shouldReturn(null); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
function it_allows_setting_the_tax_category(TaxCategoryInterface $taxCategory): void |
|
145
|
|
|
{ |
|
146
|
|
|
$this->setTaxCategory($taxCategory); |
|
147
|
|
|
$this->getTaxCategory()->shouldReturn($taxCategory); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
function it_allows_resetting_the_tax_category(TaxCategoryInterface $taxCategory): void |
|
151
|
|
|
{ |
|
152
|
|
|
$this->setTaxCategory($taxCategory); |
|
153
|
|
|
$this->getTaxCategory()->shouldReturn($taxCategory); |
|
154
|
|
|
|
|
155
|
|
|
$this->setTaxCategory(null); |
|
156
|
|
|
$this->getTaxCategory()->shouldReturn(null); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
function it_has_no_shipping_category_by_default(): void |
|
160
|
|
|
{ |
|
161
|
|
|
$this->getShippingCategory()->shouldReturn(null); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
function its_shipping_category_is_mutable(ShippingCategoryInterface $shippingCategory): void |
|
165
|
|
|
{ |
|
166
|
|
|
$this->setShippingCategory($shippingCategory); |
|
167
|
|
|
$this->getShippingCategory()->shouldReturn($shippingCategory); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
function it_adds_and_removes_channel_pricings(ChannelPricingInterface $channelPricing): void |
|
171
|
|
|
{ |
|
172
|
|
|
$channelPricing->getChannelCode()->willReturn('WEB'); |
|
173
|
|
|
|
|
174
|
|
|
$channelPricing->setProductVariant($this)->shouldBeCalled(); |
|
175
|
|
|
$this->addChannelPricing($channelPricing); |
|
176
|
|
|
$this->hasChannelPricing($channelPricing)->shouldReturn(true); |
|
177
|
|
|
|
|
178
|
|
|
$channelPricing->setProductVariant(null)->shouldBeCalled(); |
|
179
|
|
|
$this->removeChannelPricing($channelPricing); |
|
180
|
|
|
$this->hasChannelPricing($channelPricing)->shouldReturn(false); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
function it_has_channel_pricings_collection( |
|
184
|
|
|
ChannelPricingInterface $firstChannelPricing, |
|
185
|
|
|
ChannelPricingInterface $secondChannelPricing |
|
186
|
|
|
): void { |
|
187
|
|
|
$firstChannelPricing->getChannelCode()->willReturn('WEB'); |
|
188
|
|
|
$secondChannelPricing->getChannelCode()->willReturn('MOB'); |
|
189
|
|
|
|
|
190
|
|
|
$firstChannelPricing->setProductVariant($this)->shouldBeCalled(); |
|
191
|
|
|
$secondChannelPricing->setProductVariant($this)->shouldBeCalled(); |
|
192
|
|
|
|
|
193
|
|
|
$this->addChannelPricing($firstChannelPricing); |
|
194
|
|
|
$this->addChannelPricing($secondChannelPricing); |
|
195
|
|
|
|
|
196
|
|
|
$this->getChannelPricings()->shouldBeLike(new ArrayCollection([ |
|
197
|
|
|
'WEB' => $firstChannelPricing->getWrappedObject(), |
|
|
|
|
|
|
198
|
|
|
'MOB' => $secondChannelPricing->getWrappedObject(), |
|
|
|
|
|
|
199
|
|
|
])); |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
function it_checks_if_contains_channel_pricing_for_given_channel( |
|
203
|
|
|
ChannelInterface $firstChannel, |
|
204
|
|
|
ChannelInterface $secondChannel, |
|
205
|
|
|
ChannelPricingInterface $firstChannelPricing |
|
206
|
|
|
): void { |
|
207
|
|
|
$firstChannelPricing->getChannelCode()->willReturn('WEB'); |
|
208
|
|
|
$firstChannel->getCode()->willReturn('WEB'); |
|
209
|
|
|
$secondChannel->getCode()->willReturn('MOB'); |
|
210
|
|
|
|
|
211
|
|
|
$firstChannelPricing->setProductVariant($this)->shouldBeCalled(); |
|
212
|
|
|
$this->addChannelPricing($firstChannelPricing); |
|
213
|
|
|
|
|
214
|
|
|
$firstChannelPricing->getChannelCode()->willReturn($firstChannel); |
|
215
|
|
|
|
|
216
|
|
|
$this->hasChannelPricingForChannel($firstChannel)->shouldReturn(true); |
|
217
|
|
|
$this->hasChannelPricingForChannel($secondChannel)->shouldReturn(false); |
|
218
|
|
|
} |
|
219
|
|
|
|
|
220
|
|
|
function it_returns_channel_pricing_for_given_channel( |
|
221
|
|
|
ChannelInterface $channel, |
|
222
|
|
|
ChannelPricingInterface $channelPricing |
|
223
|
|
|
): void { |
|
224
|
|
|
$channelPricing->getChannelCode()->willReturn('WEB'); |
|
225
|
|
|
$channel->getCode()->willReturn('WEB'); |
|
226
|
|
|
|
|
227
|
|
|
$channelPricing->setProductVariant($this)->shouldBeCalled(); |
|
228
|
|
|
$this->addChannelPricing($channelPricing); |
|
229
|
|
|
|
|
230
|
|
|
$channelPricing->getChannelCode()->willReturn($channel); |
|
231
|
|
|
|
|
232
|
|
|
$this->getChannelPricingForChannel($channel)->shouldReturn($channelPricing); |
|
233
|
|
|
} |
|
234
|
|
|
|
|
235
|
|
|
function it_requires_shipping_by_default(): void |
|
236
|
|
|
{ |
|
237
|
|
|
$this->isShippingRequired()->shouldReturn(true); |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
function its_shipping_can_be_not_required(): void |
|
241
|
|
|
{ |
|
242
|
|
|
$this->setShippingRequired(false); |
|
243
|
|
|
$this->isShippingRequired()->shouldReturn(false); |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
function it_initializes_image_collection_by_default(): void |
|
247
|
|
|
{ |
|
248
|
|
|
$this->getImages()->shouldHaveType(Collection::class); |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
function it_adds_an_image(ProductImageInterface $image): void |
|
252
|
|
|
{ |
|
253
|
|
|
$this->addImage($image); |
|
254
|
|
|
$this->hasImages()->shouldReturn(true); |
|
255
|
|
|
$this->hasImage($image)->shouldReturn(true); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
function it_removes_an_image(ProductImageInterface $image): void |
|
259
|
|
|
{ |
|
260
|
|
|
$this->addImage($image); |
|
261
|
|
|
$this->removeImage($image); |
|
262
|
|
|
$this->hasImage($image)->shouldReturn(false); |
|
263
|
|
|
} |
|
264
|
|
|
|
|
265
|
|
|
function it_returns_images_by_type(ProductImageInterface $image, Product $product): void |
|
266
|
|
|
{ |
|
267
|
|
|
$image->getType()->willReturn('thumbnail'); |
|
268
|
|
|
|
|
269
|
|
|
$image->setOwner($product)->shouldBeCalled(); |
|
270
|
|
|
$image->addProductVariant($this)->shouldBeCalled(); |
|
271
|
|
|
|
|
272
|
|
|
$this->setProduct($product); |
|
273
|
|
|
$this->addImage($image); |
|
274
|
|
|
$this->getImagesByType('thumbnail')->shouldBeLike(new ArrayCollection([$image->getWrappedObject()])); |
|
|
|
|
|
|
275
|
|
|
} |
|
276
|
|
|
} |
|
277
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.