Completed
Push — master ( 3182b0...115a8b )
by Arkadiusz
11s
created

StringBlockContext::theStoreHasStringBlock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Lakion\SyliusCmsBundle\Tests\Behat\Context\Setup;
4
5
use Behat\Behat\Context\Context;
6
use Doctrine\Common\Persistence\ObjectManager;
7
use Sylius\Behat\Service\SharedStorageInterface;
8
use Sylius\Component\Resource\Factory\FactoryInterface;
9
10
final class StringBlockContext implements Context
11
{
12
    /**
13
     * @var SharedStorageInterface
14
     */
15
    private $sharedStorage;
16
17
    /**
18
     * @var FactoryInterface
19
     */
20
    private $factory;
21
22
    /**
23
     * @var ObjectManager
24
     */
25
    private $manager;
26
27
    /**
28
     * @param SharedStorageInterface $sharedStorage
29
     * @param FactoryInterface $factory
30
     * @param ObjectManager $manager
31
     */
32
    public function __construct(
33
        SharedStorageInterface $sharedStorage,
34
        FactoryInterface $factory,
35
        ObjectManager $manager
36
    ) {
37
        $this->sharedStorage = $sharedStorage;
38
        $this->factory = $factory;
39
        $this->manager = $manager;
40
    }
41
42
    /**
43
     * @Given the store has string block :name
44
     */
45
    public function theStoreHasStringBlock($name)
46
    {
47
        $this->theStoreHasStringBlockWithBody($name, 'Random content');
48
    }
49
50
    /**
51
     * @Given the store has string block :name with body :body
52
     */
53
    public function theStoreHasStringBlockWithBody($name, $body)
54
    {
55
        $block = $this->factory->createNew();
56
57
        $block->setName($name);
58
        $block->setBody($body);
59
60
        $this->manager->persist($block);
61
        $this->manager->flush();
62
63
        $this->sharedStorage->set('string_block', $block);
64
    }
65
}
66