Completed
Pull Request — master (#45)
by Jan
02:36
created

RouteContext   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 78
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A theStoreHasRoute() 0 9 1
A theStoreHasRoutes() 0 6 2
A theStoreHasRouteWithAsItsContent() 0 11 1
1
<?php
2
3
namespace Tests\Lakion\CmsPlugin\Behat\Context\Setup;
4
5
use Behat\Behat\Context\Context;
6
use Doctrine\Common\Persistence\ObjectManager;
7
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface;
8
use Sylius\Behat\Service\SharedStorageInterface;
9
use Sylius\Component\Resource\Repository\RepositoryInterface;
10
11
final class RouteContext implements Context
12
{
13
    /**
14
     * @var SharedStorageInterface
15
     */
16
    private $sharedStorage;
17
18
    /**
19
     * @var ExampleFactoryInterface
20
     */
21
    private $routeExampleFactory;
22
23
    /**
24
     * @var ObjectManager
25
     */
26
    private $routeManager;
27
28
    /**
29
     * @var RepositoryInterface
30
     */
31
    private $staticContentRepository;
32
33
    /**
34
     * @param SharedStorageInterface $sharedStorage
35
     * @param ExampleFactoryInterface $routeExampleFactory
36
     * @param ObjectManager $routeManager
37
     * @param RepositoryInterface $staticContentRepository
38
     */
39
    public function __construct(
40
        SharedStorageInterface $sharedStorage,
41
        ExampleFactoryInterface $routeExampleFactory,
42
        ObjectManager $routeManager,
43
        RepositoryInterface $staticContentRepository
44
    ) {
45
        $this->sharedStorage = $sharedStorage;
46
        $this->routeExampleFactory = $routeExampleFactory;
47
        $this->routeManager = $routeManager;
48
        $this->staticContentRepository = $staticContentRepository;
49
    }
50
51
    /**
52
     * @Given the store has route :name
53
     */
54
    public function theStoreHasRoute($name)
55
    {
56
        $route = $this->routeExampleFactory->create(['name' => $name]);
57
58
        $this->routeManager->persist($route);
59
        $this->routeManager->flush();
60
61
        $this->sharedStorage->set('route', $route);
62
    }
63
64
    /**
65
     * @Given the store has routes :firstName and :secondName
66
     */
67
    public function theStoreHasRoutes(...$routesNames)
68
    {
69
        foreach ($routesNames as $routesName) {
70
            $this->theStoreHasRoute($routesName);
71
        }
72
    }
73
74
    /**
75
     * @Given the store has route :name with :contentTitle as its content
76
     */
77
    public function theStoreHasRouteWithAsItsContent($name, $contentTitle)
78
    {
79
        $content = $this->staticContentRepository->findOneBy(['title' => $contentTitle]);
80
81
        $route = $this->routeExampleFactory->create(['name' => $name, 'content' => $content]);
82
83
        $this->routeManager->persist($route);
84
        $this->routeManager->flush();
85
86
        $this->sharedStorage->set('route', $route);
87
    }
88
}
89