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\Behat\Context\Setup; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
18
|
|
|
use Sylius\Component\Core\Model\TaxonInterface; |
19
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
20
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
21
|
|
|
use Sylius\Component\Taxonomy\Factory\TaxonFactoryInterface; |
22
|
|
|
use Sylius\Component\Taxonomy\Model\TaxonomyInterface; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @author Mateusz Zalewski <[email protected]> |
26
|
|
|
*/ |
27
|
|
|
class TaxonomyContextSpec extends ObjectBehavior |
28
|
|
|
{ |
29
|
|
|
function let(RepositoryInterface $taxonRepository, FactoryInterface $taxonFactory, ObjectManager $objectManager) |
30
|
|
|
{ |
31
|
|
|
$this->beConstructedWith($taxonRepository, $taxonFactory, $objectManager); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_is_initializable() |
35
|
|
|
{ |
36
|
|
|
$this->shouldHaveType('Sylius\Behat\Context\Setup\TaxonomyContext'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_implements_context_interface() |
40
|
|
|
{ |
41
|
|
|
$this->shouldImplement(Context::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_creates_one_taxons_with_given_name( |
45
|
|
|
FactoryInterface $taxonFactory, |
46
|
|
|
RepositoryInterface $taxonRepository, |
47
|
|
|
TaxonInterface $firstTaxon |
48
|
|
|
) { |
49
|
|
|
$taxonFactory->createNew()->willReturn($firstTaxon); |
50
|
|
|
|
51
|
|
|
$firstTaxon->setName('Swords')->shouldBeCalled(); |
52
|
|
|
$firstTaxon->setCode('swords')->shouldBeCalled(); |
53
|
|
|
|
54
|
|
|
$taxonRepository->add($firstTaxon)->shouldBeCalled(); |
55
|
|
|
|
56
|
|
|
$this->storeClassifiesItsProductsAs('Swords'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_creates_two_taxons_with_given_name( |
60
|
|
|
FactoryInterface $taxonFactory, |
61
|
|
|
RepositoryInterface $taxonRepository, |
62
|
|
|
TaxonInterface $firstTaxon, |
63
|
|
|
TaxonInterface $secondTaxon |
64
|
|
|
) { |
65
|
|
|
$taxonFactory->createNew()->willReturn($firstTaxon, $secondTaxon); |
66
|
|
|
|
67
|
|
|
$firstTaxon->setName('Swords')->shouldBeCalled(); |
68
|
|
|
$firstTaxon->setCode('swords')->shouldBeCalled(); |
69
|
|
|
|
70
|
|
|
$secondTaxon->setName('Composite bows')->shouldBeCalled(); |
71
|
|
|
$secondTaxon->setCode('composite_bows')->shouldBeCalled(); |
72
|
|
|
|
73
|
|
|
$taxonRepository->add($firstTaxon)->shouldBeCalled(); |
74
|
|
|
$taxonRepository->add($secondTaxon)->shouldBeCalled(); |
75
|
|
|
|
76
|
|
|
$this->storeClassifiesItsProductsAs('Swords', 'Composite bows'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
function it_creates_three_taxons_with_given_name( |
80
|
|
|
FactoryInterface $taxonFactory, |
81
|
|
|
RepositoryInterface $taxonRepository, |
82
|
|
|
TaxonInterface $firstTaxon, |
83
|
|
|
TaxonInterface $secondTaxon, |
84
|
|
|
TaxonInterface $thirdTaxon |
85
|
|
|
) { |
86
|
|
|
$taxonFactory->createNew()->willReturn($firstTaxon, $secondTaxon, $thirdTaxon); |
87
|
|
|
|
88
|
|
|
$firstTaxon->setName('Swords')->shouldBeCalled(); |
89
|
|
|
$firstTaxon->setCode('swords')->shouldBeCalled(); |
90
|
|
|
|
91
|
|
|
$secondTaxon->setName('Composite bows')->shouldBeCalled(); |
92
|
|
|
$secondTaxon->setCode('composite_bows')->shouldBeCalled(); |
93
|
|
|
|
94
|
|
|
$thirdTaxon->setName('Axes')->shouldBeCalled(); |
95
|
|
|
$thirdTaxon->setCode('axes')->shouldBeCalled(); |
96
|
|
|
|
97
|
|
|
$taxonRepository->add($firstTaxon)->shouldBeCalled(); |
98
|
|
|
$taxonRepository->add($secondTaxon)->shouldBeCalled(); |
99
|
|
|
$taxonRepository->add($thirdTaxon)->shouldBeCalled(); |
100
|
|
|
|
101
|
|
|
$this->storeClassifiesItsProductsAs('Swords', 'Composite bows', 'Axes'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
function it_adds_taxon_to_product(ProductInterface $product, TaxonInterface $taxon) |
105
|
|
|
{ |
106
|
|
|
$product->addTaxon($taxon)->shouldBeCalled(); |
107
|
|
|
|
108
|
|
|
$this->itBelongsTo($product, $taxon); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|