Code Duplication    Length = 58-63 lines in 2 locations

src/Tests/Behat/Context/Setup/CustomBlockContext.php 1 location

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

src/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