Code Duplication    Length = 58-63 lines in 2 locations

tests/Behat/Context/Setup/CustomBlockContext.php 1 location

@@ 10-67 (lines=58) @@
7
use Sylius\Behat\Service\SharedStorageInterface;
8
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface;
9
10
final class CustomBlockContext implements Context
11
{
12
    /**
13
     * @var SharedStorageInterface
14
     */
15
    private $sharedStorage;
16
17
    /**
18
     * @var ExampleFactoryInterface
19
     */
20
    private $customBlockExampleFactory;
21
22
    /**
23
     * @var ObjectManager
24
     */
25
    private $customBlockManager;
26
27
    /**
28
     * @param SharedStorageInterface $sharedStorage
29
     * @param ExampleFactoryInterface $customBlockExampleFactory
30
     * @param ObjectManager $customBlockManager
31
     */
32
    public function __construct(
33
        SharedStorageInterface $sharedStorage,
34
        ExampleFactoryInterface $customBlockExampleFactory,
35
        ObjectManager $customBlockManager
36
    ) {
37
        $this->sharedStorage = $sharedStorage;
38
        $this->customBlockExampleFactory = $customBlockExampleFactory;
39
        $this->customBlockManager = $customBlockManager;
40
    }
41
42
    /**
43
     * @Given the store has custom block :name
44
     */
45
    public function theStoreHasCustomBlock($name)
46
    {
47
        $customBlock = $this->customBlockExampleFactory->create(['name' => $name]);
48
49
        $this->customBlockManager->persist($customBlock);
50
        $this->customBlockManager->flush();
51
52
        $this->sharedStorage->set('custom_block', $customBlock);
53
    }
54
55
    /**
56
     * @Given /^the store has custom block "([^"]+)" with (body|title|link) "([^"]+)"$/
57
     */
58
    public function theStoreHasCustomBlockWithField($name, $field, $value)
59
    {
60
        $customBlock = $this->customBlockExampleFactory->create(['name' => $name, $field => $value]);
61
62
        $this->customBlockManager->persist($customBlock);
63
        $this->customBlockManager->flush();
64
65
        $this->sharedStorage->set('custom_block', $customBlock);
66
    }
67
}
68

tests/Behat/Context/Setup/StringBlockContext.php 1 location

@@ 12-74 (lines=63) @@
9
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface;
10
use Sylius\Component\Resource\Factory\FactoryInterface;
11
12
final class StringBlockContext implements Context
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