Completed
Push — master ( 1ecbe4...2ec63c )
by Kamil
21:52
created

CurrentPageResolverSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 5
dl 0
loc 47
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_implements_current_page_resolver_interface() 0 4 1
A it_returns_current_page_based_on_matched_route() 0 14 1
A it_throws_an_exception_if_neither_create_nor_update_key_word_has_been_found() 0 14 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 spec\Sylius\Behat\Service\Resolver;
13
14
use Behat\Mink\Session;
15
use PhpSpec\ObjectBehavior;
16
use Sylius\Behat\Page\SymfonyPageInterface;
17
use Sylius\Behat\Service\Resolver\CurrentPageResolver;
18
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
19
use Symfony\Component\Routing\Matcher\UrlMatcherInterface;
20
21
/**
22
 * @mixin CurrentPageResolver
23
 *
24
 * @author Łukasz Chruściel <[email protected]>
25
 */
26
class CurrentPageResolverSpec extends ObjectBehavior
27
{
28
    function let(Session $session, UrlMatcherInterface $urlMatcher)
29
    {
30
        $this->beConstructedWith($session, $urlMatcher);
31
    }
32
33
    function it_is_initializable()
34
    {
35
        $this->shouldHaveType('Sylius\Behat\Service\Resolver\CurrentPageResolver');
36
    }
37
38
    function it_implements_current_page_resolver_interface()
39
    {
40
        $this->shouldImplement(CurrentPageResolverInterface::class);
41
    }
42
43
    function it_returns_current_page_based_on_matched_route(
44
        Session $session,
45
        SymfonyPageInterface $createPage,
46
        SymfonyPageInterface $updatePage,
47
        UrlMatcherInterface $urlMatcher
48
    ) {
49
        $session->getCurrentUrl()->willReturn('https://sylius.com/resource/new');
50
        $urlMatcher->match('/resource/new')->willReturn(['_route' => 'sylius_resource_create']);
51
52
        $createPage->getRouteName()->willReturn('sylius_resource_create');
53
        $updatePage->getRouteName()->willReturn('sylius_resource_update');
54
55
        $this->getCurrentPageWithForm([$createPage, $updatePage])->shouldReturn($createPage);
56
    }
57
58
    function it_throws_an_exception_if_neither_create_nor_update_key_word_has_been_found(
59
        Session $session,
60
        SymfonyPageInterface $createPage,
61
        SymfonyPageInterface $updatePage,
62
        UrlMatcherInterface $urlMatcher
63
    ) {
64
        $session->getCurrentUrl()->willReturn('https://sylius.com/resource/show');
65
        $urlMatcher->match('/resource/show')->willReturn(['_route' => 'sylius_resource_show']);
66
67
        $createPage->getRouteName()->willReturn('sylius_resource_create');
68
        $updatePage->getRouteName()->willReturn('sylius_resource_update');
69
70
        $this->shouldThrow(\LogicException::class)->during('getCurrentPageWithForm', [[$createPage, $updatePage]]);
71
    }
72
}
73