Completed
Push — master ( 6d05bc...71ecc8 )
by Kamil
25:05
created

AddressBookContext   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 5

Importance

Changes 0
Metric Value
wmc 12
lcom 3
cbo 5
dl 0
loc 133
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A iBrowseMyAddresses() 0 4 1
A iDeleteTheAddress() 0 4 1
A iShouldBeNotifiedAboutSuccessfulDelete() 0 4 1
A iShouldSeeASingleAddressInTheList() 0 7 1
A thisAddressShouldHavePersonFirstNameAndLastName() 0 7 1
A thereShouldBeNoAddresses() 0 7 1
A iShouldNotSeeAddressOf() 0 7 1
A iWantToAddANewAddressToMyAddressBook() 0 4 1
A iSpecifyItsDataAs() 0 4 1
A iShouldBeNotifiedThatAddressHasBeenSuccessfullyAdded() 0 4 1
A iAddIt() 0 4 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\Context\Ui\Shop;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Behat\NotificationType;
16
use Sylius\Behat\Page\Shop\Account\AddressBook\CreatePageInterface;
17
use Sylius\Behat\Page\Shop\Account\AddressBook\IndexPageInterface;
18
use Sylius\Behat\Service\NotificationCheckerInterface;
19
use Sylius\Component\Core\Model\AddressInterface;
20
use Webmozart\Assert\Assert;
21
22
/**
23
 * @author Anna Walasek <[email protected]>
24
 * @author Jan Góralski <[email protected]>
25
 */
26
final class AddressBookContext implements Context
27
{
28
    /**
29
     * @var IndexPageInterface
30
     */
31
    private $addressBookIndexPage;
32
33
    /**
34
     * @var CreatePageInterface
35
     */
36
    private $addressBookCreatePage;
37
38
    /**
39
     * @var NotificationCheckerInterface
40
     */
41
    private $notificationChecker;
42
43
    /**
44
     * @param IndexPageInterface $addressBookIndexPage
45
     * @param CreatePageInterface $addressBookCreatePage
46
     * @param NotificationCheckerInterface $notificationChecker
47
     */
48
    public function __construct(
49
        IndexPageInterface $addressBookIndexPage,
50
        CreatePageInterface $addressBookCreatePage,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $addressBookCreatePage exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
51
        NotificationCheckerInterface $notificationChecker
52
    ) {
53
        $this->addressBookIndexPage = $addressBookIndexPage;
54
        $this->addressBookCreatePage = $addressBookCreatePage;
55
        $this->notificationChecker = $notificationChecker;
56
    }
57
58
    /**
59
     * @When I browse my address book
60
     */
61
    public function iBrowseMyAddresses()
62
    {
63
        $this->addressBookIndexPage->open();
64
    }
65
66
    /**
67
     * @When I delete the :fullName address
68
     */
69
    public function iDeleteTheAddress($fullname)
70
    {
71
        $this->addressBookIndexPage->deleteAddress($fullname);
72
    }
73
74
    /**
75
     * @Then I should be notified that it has been successfully deleted
76
     */
77
    public function iShouldBeNotifiedAboutSuccessfulDelete()
78
    {
79
        $this->notificationChecker->checkNotification('Address has been successfully deleted.', NotificationType::success());
80
    }
81
82
    /**
83
     * @Then I should see a single address in my book
84
     */
85
    public function iShouldSeeASingleAddressInTheList()
86
    {
87
        Assert::true(
88
            $this->addressBookIndexPage->isSingleAddressOnList(),
89
            'There should be one address on the list, but it does not.'
90
        );
91
    }
92
93
    /**
94
     * @Then this address should be assigned to :fullName
95
     * @Then the address assigned to :fullName should appear in my book
96
     */
97
    public function thisAddressShouldHavePersonFirstNameAndLastName($fullName)
98
    {
99
        Assert::true(
100
            $this->addressBookIndexPage->hasAddressFullName($fullName),
101
            sprintf('An address of "%s" should be on the list.', $fullName)
102
        );
103
    }
104
105
    /**
106
     * @Then there should be no addresses
107
     */
108
    public function thereShouldBeNoAddresses()
109
    {
110
        Assert::true(
111
            $this->addressBookIndexPage->hasNoAddresses(),
112
            'There should be no addresses on the list.'
113
        );
114
    }
115
116
    /**
117
     * @Then I should not see the address assigned to :fullName
118
     */
119
    public function iShouldNotSeeAddressOf($fullName)
120
    {
121
        Assert::false(
122
            $this->addressBookIndexPage->hasAddressFullName($fullName),
123
            sprintf('The address of "%s" should not be on the list.', $fullName)
124
        );
125
    }
126
127
    /**
128
     * @Given I want to add a new address to my address book
129
     */
130
    public function iWantToAddANewAddressToMyAddressBook()
131
    {
132
        $this->addressBookCreatePage->open();
133
    }
134
135
    /**
136
     * @When /^I specify the (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)")$/
137
     */
138
    public function iSpecifyItsDataAs(AddressInterface $address)
139
    {
140
        $this->addressBookCreatePage->fillAddressData($address);
141
    }
142
143
    /**
144
     * @Then I should be notified that it has been successfully added
145
     */
146
    public function iShouldBeNotifiedThatAddressHasBeenSuccessfullyAdded()
147
    {
148
        $this->notificationChecker->checkNotification('has been successfully added.', NotificationType::success());
149
    }
150
151
    /**
152
     * @When I add it
153
     */
154
    public function iAddIt()
155
    {
156
        $this->addressBookCreatePage->saveAddress();
157
    }
158
}
159