Completed
Push — master ( 133b57...4c004c )
by Kamil
20:32
created

ManagingCountriesContextSpec   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_is_context() 0 4 1
A it_opens_country_creation_page() 0 6 1
A it_chooses_name_in_creation_form() 0 6 1
A it_adds_a_country() 0 6 1
A it_asserts_that_successful_message_appears() 0 7 1
A it_throws_not_equal_exception_if_message_is_not_successful() 0 7 1
A it_throws_not_equal_exception_if_successful_message_does_not_appear() 0 7 1
A it_asserts_that_country_appears_in_the_store() 0 7 1
A it_throws_not_equal_exception_if_country_does_not_appear_in_the_store() 0 9 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\Context\Ui\Admin;
13
14
use Behat\Behat\Context\Context;
15
use PhpSpec\Exception\Example\NotEqualException;
16
use PhpSpec\ObjectBehavior;
17
use Sylius\Behat\Page\Admin\Country\CreatePageInterface;
18
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
19
use Sylius\Component\Addressing\Model\CountryInterface;
20
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
21
22
/**
23
 * @author Arkadiusz Krakowiak <[email protected]>
24
 */
25
class ManagingCountriesContextSpec extends ObjectBehavior
26
{
27
    function let(IndexPageInterface $countryIndexPage, CreatePageInterface $countryCreatePage)
28
    {
29
        $this->beConstructedWith($countryIndexPage, $countryCreatePage);
30
    }
31
32
    function it_is_initializable()
33
    {
34
        $this->shouldHaveType('Sylius\Behat\Context\Ui\Admin\ManagingCountriesContext');
35
    }
36
37
    function it_is_context()
38
    {
39
        $this->shouldImplement(Context::class);
40
    }
41
42
    function it_opens_country_creation_page(CreatePageInterface $countryCreatePage)
43
    {
44
        $countryCreatePage->open()->shouldBeCalled();
45
46
        $this->iWantToCreateNewCountry();
47
    }
48
49
    function it_chooses_name_in_creation_form(CreatePageInterface $countryCreatePage)
50
    {
51
        $countryCreatePage->chooseName('France')->shouldBeCalled();
52
53
        $this->iChoose('France');
54
    }
55
56
    function it_adds_a_country(CreatePageInterface $countryCreatePage)
57
    {
58
        $countryCreatePage->create()->shouldBeCalled();
59
60
        $this->iAddIt();
61
    }
62
63
    function it_asserts_that_successful_message_appears(IndexPageInterface $countryIndexPage)
64
    {
65
        $countryIndexPage->hasSuccessMessage()->willReturn(true);
66
        $countryIndexPage->isSuccessfullyCreated()->willReturn(true);
67
68
        $this->iShouldBeNotifiedAboutSuccess();
69
    }
70
71
    function it_throws_not_equal_exception_if_message_is_not_successful(IndexPageInterface $countryIndexPage)
72
    {
73
        $countryIndexPage->hasSuccessMessage()->willReturn(false);
74
        $countryIndexPage->isSuccessfullyCreated()->willReturn(true);
75
76
        $this->shouldThrow(NotEqualException::class)->during('iShouldBeNotifiedAboutSuccess');
77
    }
78
79
    function it_throws_not_equal_exception_if_successful_message_does_not_appear(IndexPageInterface $countryIndexPage)
80
    {
81
        $countryIndexPage->hasSuccessMessage()->willReturn(true);
82
        $countryIndexPage->isSuccessfullyCreated()->willReturn(false);
83
84
        $this->shouldThrow(NotEqualException::class)->during('iShouldBeNotifiedAboutSuccess');
85
    }
86
87
    function it_asserts_that_country_appears_in_the_store(IndexPageInterface $countryIndexPage, CountryInterface $country)
88
    {
89
        $country->getCode()->willReturn('FR');
90
        $countryIndexPage->isResourceOnPage(['code' => 'FR'])->willReturn(true);
91
92
        $this->countryWithNameShouldAppearInTheStore($country);
93
    }
94
95
    function it_throws_not_equal_exception_if_country_does_not_appear_in_the_store(
96
        IndexPageInterface $countryIndexPage,
97
        CountryInterface $country
98
    ) {
99
        $country->getCode()->willReturn('FR');
100
        $countryIndexPage->isResourceOnPage(['code' => 'FR'])->willReturn(false);
101
102
        $this->shouldThrow(NotEqualException::class)->during('countryWithNameShouldAppearInTheStore', [$country]);
103
    }
104
}
105