Completed
Push — master ( a13c2f...df1c7f )
by Kamil
9s
created

StringBlockContext::theStoreHasStringBlock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
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\StringBlock;
8
use Sylius\Behat\Service\SharedStorageInterface;
9
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface;
10
use Sylius\Component\Resource\Factory\FactoryInterface;
11
12 View Code Duplication
final class StringBlockContext implements Context
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
13
{
14
    /**
15
     * @var SharedStorageInterface
16
     */
17
    private $sharedStorage;
18
19
    /**
20
     * @var ExampleFactoryInterface
21
     */
22
    private $stringBlockExampleFactory;
23
24
    /**
25
     * @var ObjectManager
26
     */
27
    private $stringBlockManager;
28
29
    /**
30
     * @param SharedStorageInterface $sharedStorage
31
     * @param ExampleFactoryInterface $stringBlockExampleFactory
32
     * @param ObjectManager $stringBlockManager
33
     */
34
    public function __construct(
35
        SharedStorageInterface $sharedStorage,
36
        ExampleFactoryInterface $stringBlockExampleFactory,
37
        ObjectManager $stringBlockManager
38
    ) {
39
        $this->sharedStorage = $sharedStorage;
40
        $this->stringBlockExampleFactory = $stringBlockExampleFactory;
41
        $this->stringBlockManager = $stringBlockManager;
42
    }
43
44
    /**
45
     * @Given the store has string block :name
46
     */
47
    public function theStoreHasStringBlock($name)
48
    {
49
        $stringBlock = $this->stringBlockExampleFactory->create([
50
            'name' => $name,
51
        ]);
52
53
        $this->stringBlockManager->persist($stringBlock);
54
        $this->stringBlockManager->flush();
55
56
        $this->sharedStorage->set('string_block', $stringBlock);
57
    }
58
59
    /**
60
     * @Given the store has string block :name with body :body
61
     */
62
    public function theStoreHasStringBlockWithBody($name, $body)
63
    {
64
        $stringBlock = $this->stringBlockExampleFactory->create([
65
            'name' => $name,
66
            'body' => $body,
67
        ]);
68
69
        $this->stringBlockManager->persist($stringBlock);
70
        $this->stringBlockManager->flush();
71
72
        $this->sharedStorage->set('string_block', $stringBlock);
73
    }
74
}
75