Completed
Push — master ( b716f1...2f9340 )
by Kamil
18:43
created

SymfonyPage::getUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Behat\SymfonyPageObjectExtension\PageObject;
13
14
use Behat\Mink\Session;
15
use SensioLabs\Behat\PageObjectExtension\PageObject\Factory;
16
use Sylius\Behat\PageObjectExtension\PageObject\Page;
17
use Symfony\Component\Routing\RouterInterface;
18
19
/**
20
 * @author Arkadiusz Krakowiak <[email protected]>
21
 */
22
abstract class SymfonyPage extends Page
23
{
24
    /**
25
     * @var RouterInterface
26
     */
27
    protected $router;
28
29
    /**
30
     * @param Session $session
31
     * @param Factory $factory
32
     * @param array $parameters
33
     * @param RouterInterface $router
34
     */
35
    public function __construct(Session $session, Factory $factory, array $parameters = [], RouterInterface $router)
36
    {
37
        parent::__construct($session, $factory, $parameters);
38
39
        $this->router = $router;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function getUrl(array $urlParameters = [])
46
    {
47
        if (null === $this->getRouteName()) {
48
            throw new \RuntimeException('You need to provide route name, null given');
49
        }
50
51
        return $this->router->generate($this->getRouteName(), $urlParameters, true);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     *
57
     * Not used by Symfony page.
58
     */
59
    protected function getPath()
60
    {
61
    }
62
63
    abstract protected function getRouteName();
64
}
65