Completed
Push — master ( 8b479a...c1c0ed )
by Kamil
18:11
created

SymfonyPage   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 60
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A pressRadio() 0 10 2
A assertRoute() 0 4 1
A getUrl() 0 8 2
getRouteName() 0 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\PageObjectExtension\Page;
13
14
use Behat\Mink\Session;
15
use SensioLabs\Behat\PageObjectExtension\PageObject\Exception\ElementNotFoundException;
16
use SensioLabs\Behat\PageObjectExtension\PageObject\Factory;
17
use SensioLabs\Behat\PageObjectExtension\PageObject\Page;
18
use Symfony\Component\Routing\RouterInterface;
19
20
/**
21
 * @author Arkadiusz Krakowiak <[email protected]>
22
 */
23
abstract class SymfonyPage extends Page
24
{
25
    /**
26
     * @var RouterInterface
27
     */
28
    protected $router;
29
30
    /**
31
     * @param Session $session
32
     * @param Factory $factory
33
     * @param array $parameters
34
     * @param RouterInterface $router
35
     */
36
    public function __construct(Session $session, Factory $factory, array $parameters = [], RouterInterface $router)
37
    {
38
        parent::__construct($session, $factory, $parameters);
39
40
        $this->router = $router;
41
    }
42
43
    /**
44
     * @param string $locator
45
     *
46
     * @throws ElementNotFoundException
47
     */
48
    public function pressRadio($locator)
49
    {
50
        $radio = $this->findField($locator);
51
52
        if (null === $radio) {
53
            throw new ElementNotFoundException(sprintf('"%s" element is not present on the page', $locator));
54
        }
55
56
        $this->fillField($radio->getAttribute('name'), $radio->getAttribute('value'));
57
    }
58
59
    /**
60
     * @param array $urlParameters
61
     */
62
    public function assertRoute(array $urlParameters = array())
63
    {
64
        $this->verify($urlParameters);
65
    }
66
67
    /**
68
     * @param array $urlParameters
69
     *
70
     * @return string
71
     */
72
    protected function getUrl(array $urlParameters = array())
73
    {
74
        if (null === $this->getRouteName()) {
75
            throw new \RuntimeException('You need to provide route name, null given');
76
        }
77
78
        return $this->router->generate($this->getRouteName(), $urlParameters, true);
79
    }
80
81
    abstract public function getRouteName();
82
}
83