1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Tests\Lakion\SyliusCmsBundle\Behat\Context\Setup; |
4
|
|
|
|
5
|
|
|
use Behat\Behat\Context\Context; |
6
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
7
|
|
|
use Lakion\SyliusCmsBundle\Document\StaticContent; |
8
|
|
|
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface; |
9
|
|
|
use Sylius\Behat\Service\SharedStorageInterface; |
10
|
|
|
|
11
|
|
|
final class StaticContentContext implements Context |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var SharedStorageInterface |
15
|
|
|
*/ |
16
|
|
|
private $sharedStorage; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var ExampleFactoryInterface |
20
|
|
|
*/ |
21
|
|
|
private $staticContentExampleFactory; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ObjectManager |
25
|
|
|
*/ |
26
|
|
|
private $staticContentManager; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param SharedStorageInterface $sharedStorage |
30
|
|
|
* @param ExampleFactoryInterface $staticContentExampleFactory |
31
|
|
|
* @param ObjectManager $staticContentManager |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
SharedStorageInterface $sharedStorage, |
35
|
|
|
ExampleFactoryInterface $staticContentExampleFactory, |
36
|
|
|
ObjectManager $staticContentManager |
37
|
|
|
) { |
38
|
|
|
$this->sharedStorage = $sharedStorage; |
39
|
|
|
$this->staticContentExampleFactory = $staticContentExampleFactory; |
40
|
|
|
$this->staticContentManager = $staticContentManager; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @Given the store has static content :title |
45
|
|
|
*/ |
46
|
|
View Code Duplication |
public function theStoreHasStaticContent($title) |
|
|
|
|
47
|
|
|
{ |
48
|
|
|
$staticContent = $this->staticContentExampleFactory->create(['title' => $title]); |
49
|
|
|
|
50
|
|
|
$this->staticContentManager->persist($staticContent); |
51
|
|
|
$this->staticContentManager->flush(); |
52
|
|
|
|
53
|
|
|
$this->sharedStorage->set('static_content', $staticContent); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Given the store has static contents :firstTitle and :secondTitle |
58
|
|
|
*/ |
59
|
|
|
public function theStoreHasStaticContents(...$titles) |
60
|
|
|
{ |
61
|
|
|
foreach ($titles as $title) { |
62
|
|
|
$this->theStoreHasStaticContent($title); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Given the store has static content :title with body :body |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function theStoreHasStaticContentWithBody($title, $body) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$staticContent = $this->staticContentExampleFactory->create(['title' => $title, 'body' => $body]); |
72
|
|
|
|
73
|
|
|
$this->staticContentManager->persist($staticContent); |
74
|
|
|
$this->staticContentManager->flush(); |
75
|
|
|
|
76
|
|
|
$this->sharedStorage->set('static_content', $staticContent); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @Given the store has static content :title with name :name |
81
|
|
|
*/ |
82
|
|
View Code Duplication |
public function theStoreHasStaticContentWithName($title, $name) |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
$staticContent = $this->staticContentExampleFactory->create(['title' => $title, 'name' => $name]); |
85
|
|
|
|
86
|
|
|
$this->staticContentManager->persist($staticContent); |
87
|
|
|
$this->staticContentManager->flush(); |
88
|
|
|
|
89
|
|
|
$this->sharedStorage->set('static_content', $staticContent); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @Given /^(it) is not published yet$/ |
94
|
|
|
*/ |
95
|
|
|
public function itIsNotPublishedYet(StaticContent $staticContent) |
96
|
|
|
{ |
97
|
|
|
$staticContent->setPublishable(false); |
98
|
|
|
|
99
|
|
|
$this->staticContentManager->flush(); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.