|
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\Product\Factory; |
|
13
|
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
|
15
|
|
|
use Sylius\Component\Product\Factory\ProductVariantFactoryInterface; |
|
16
|
|
|
use Sylius\Component\Product\Model\ProductInterface; |
|
17
|
|
|
use Sylius\Component\Product\Model\VariantInterface; |
|
18
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
|
19
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class ProductVariantFactorySpec extends ObjectBehavior |
|
25
|
|
|
{ |
|
26
|
|
|
function let(FactoryInterface $factory, RepositoryInterface $productRepository) |
|
27
|
|
|
{ |
|
28
|
|
|
$this->beConstructedWith($factory, $productRepository); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
function it_is_initializable() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->shouldHaveType('Sylius\Component\Product\Factory\ProductVariantFactory'); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_is_a_resource_factory() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->shouldImplement(FactoryInterface::class); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function it_implements_variant_factory_interface() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->shouldImplement(ProductVariantFactoryInterface::class); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
function it_creates_new_variant(FactoryInterface $factory, VariantInterface $variant) |
|
47
|
|
|
{ |
|
48
|
|
|
$factory->createNew()->willReturn($variant); |
|
49
|
|
|
|
|
50
|
|
|
$this->createNew()->shouldReturn($variant); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
function it_throws_an_exception_when_product_is_not_found(RepositoryInterface $productRepository) |
|
54
|
|
|
{ |
|
55
|
|
|
$productRepository->find(15)->willReturn(null); |
|
56
|
|
|
|
|
57
|
|
|
$this |
|
58
|
|
|
->shouldThrow(\InvalidArgumentException::class) |
|
59
|
|
|
->during('createForProductWithId', [15]) |
|
60
|
|
|
; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
function it_creates_a_variant_and_assigns_a_product_to_id( |
|
64
|
|
|
FactoryInterface $factory, |
|
65
|
|
|
RepositoryInterface $productRepository, |
|
66
|
|
|
ProductInterface $product, |
|
67
|
|
|
VariantInterface $variant |
|
68
|
|
|
) { |
|
69
|
|
|
$factory->createNew()->willReturn($variant); |
|
70
|
|
|
$productRepository->find(13)->willReturn($product); |
|
71
|
|
|
$variant->setProduct($product)->shouldBeCalled(); |
|
72
|
|
|
|
|
73
|
|
|
$this->createForProductWithId(13)->shouldReturn($variant); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|