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 Sylius\Behat\Context\Setup; |
13
|
|
|
|
14
|
|
|
use Behat\Behat\Context\Context; |
15
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
16
|
|
|
use Sylius\Behat\Service\SharedStorageInterface; |
17
|
|
|
use Sylius\Component\Core\Formatter\StringInflector; |
18
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
19
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
20
|
|
|
use Sylius\Component\Shipping\Model\ShippingCategoryInterface; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Anna Walasek <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
final class ShippingCategoryContext implements Context |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var SharedStorageInterface |
29
|
|
|
*/ |
30
|
|
|
private $sharedStorage; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var FactoryInterface |
34
|
|
|
*/ |
35
|
|
|
private $shippingCategoryFactory; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var RepositoryInterface |
39
|
|
|
*/ |
40
|
|
|
private $shippingCategoryRepository; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var ObjectManager |
44
|
|
|
*/ |
45
|
|
|
private $shippingCategoryManager; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param SharedStorageInterface $sharedStorage |
49
|
|
|
* @param FactoryInterface $shippingCategoryFactory |
50
|
|
|
* @param RepositoryInterface $shippingCategoryRepository |
51
|
|
|
* @param ObjectManager $shippingCategoryManager |
52
|
|
|
*/ |
53
|
|
|
public function __construct( |
54
|
|
|
SharedStorageInterface $sharedStorage, |
55
|
|
|
FactoryInterface $shippingCategoryFactory, |
|
|
|
|
56
|
|
|
RepositoryInterface $shippingCategoryRepository, |
|
|
|
|
57
|
|
|
ObjectManager $shippingCategoryManager |
|
|
|
|
58
|
|
|
) { |
59
|
|
|
$this->sharedStorage = $sharedStorage; |
60
|
|
|
$this->shippingCategoryFactory = $shippingCategoryFactory; |
61
|
|
|
$this->shippingCategoryRepository = $shippingCategoryRepository; |
62
|
|
|
$this->shippingCategoryManager = $shippingCategoryManager; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @Given the store has :firstShippingCategoryName shipping category |
67
|
|
|
* @Given the store has :firstShippingCategoryName and :secondShippingCategoryName shipping category |
68
|
|
|
*/ |
69
|
|
|
public function theStoreHasAndShippingCategory($firstShippingCategoryName, $secondShippingCategoryName = null) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$this->createShippingCategory($firstShippingCategoryName); |
72
|
|
|
(null === $secondShippingCategoryName)? : $this->createShippingCategory($secondShippingCategoryName); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @Given the store has :shippingCategoryName shipping category identified by :shippingCategoryCode |
77
|
|
|
*/ |
78
|
|
|
public function theStoreHasShippingCategoryIdentifiedBy($shippingCategoryName, $shippingCategoryCode) |
79
|
|
|
{ |
80
|
|
|
$this->createShippingCategory($shippingCategoryName, $shippingCategoryCode); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $shippingCategoryName |
85
|
|
|
* @param string $shippingCategoryCode |
|
|
|
|
86
|
|
|
*/ |
87
|
|
|
private function createShippingCategory($shippingCategoryName, $shippingCategoryCode = null) |
88
|
|
|
{ |
89
|
|
|
/** @var ShippingCategoryInterface $shippingCategory */ |
90
|
|
|
$shippingCategory = $this->shippingCategoryFactory->createNew(); |
91
|
|
|
$shippingCategory->setName($shippingCategoryName); |
92
|
|
|
$shippingCategory->setCode($shippingCategoryCode); |
93
|
|
|
|
94
|
|
|
if(null === $shippingCategoryCode) { |
95
|
|
|
$shippingCategory->setCode(StringInflector::nameToCode($shippingCategoryName)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$this->shippingCategoryRepository->add($shippingCategory); |
99
|
|
|
$this->sharedStorage->set('shipping_category', $shippingCategory); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.