Completed
Push — master ( 84981d...080a22 )
by Kamil
05:57
created

iChooseChannelAsAChannelFilter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
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
declare(strict_types=1);
13
14
namespace Sylius\Behat\Context\Ui\Admin;
15
16
use Behat\Behat\Context\Context;
17
use Sylius\Behat\NotificationType;
18
use Sylius\Behat\Page\Admin\Order\ShowPageInterface;
19
use Sylius\Behat\Page\Admin\Shipment\IndexPageInterface;
20
use Sylius\Behat\Service\NotificationCheckerInterface;
21
use Sylius\Component\Core\Model\Channel;
22
use Sylius\Component\Core\Model\CustomerInterface;
23
use Sylius\Component\Core\Model\OrderInterface;
24
use Webmozart\Assert\Assert;
25
26
final class ManagingShipmentsContext implements Context
27
{
28
    /** @var IndexPageInterface */
29
    private $indexPage;
30
31
    /** @var ShowPageInterface */
32
    private $orderShowPage;
33
34
    /** @var NotificationCheckerInterface */
35
    private $notificationChecker;
36
37
    public function __construct(IndexPageInterface $indexPage, ShowPageInterface $orderShowPage, NotificationCheckerInterface $notificationChecker)
38
    {
39
        $this->indexPage = $indexPage;
40
        $this->orderShowPage = $orderShowPage;
41
        $this->notificationChecker = $notificationChecker;
42
    }
43
44
    /**
45
     * @When I browse shipments
46
     */
47
    public function iBrowseShipments(): void
48
    {
49
        $this->indexPage->open();
50
    }
51
52
    /**
53
     * @Then the shipment of the :orderNumber order should be :shippingState for :customer
54
     * @Then the shipment of the :orderNumber order should be :shippingState for :customer in :channel channel
55
     */
56
    public function shipmentOfOrderShouldBe(
57
        string $orderNumber,
58
        string $shippingState,
59
        CustomerInterface $customer,
60
        Channel $channel = null
61
    ): void {
62
        $parameters = [
63
            'number' => $orderNumber,
64
            'state' => $shippingState,
65
            'customer' => $customer->getEmail(),
66
        ];
67
68
        if ($channel !== null) {
69
            $parameters = ['channel' => $channel->getCode()];
70
        }
71
72
        Assert::true($this->indexPage->isSingleResourceOnPage($parameters));
73
    }
74
75
    /**
76
     * @When I choose :shipmentState as a shipment state
77
     */
78
    public function iChooseShipmentState(string $shipmentState): void
79
    {
80
        $this->indexPage->chooseStateToFilter($shipmentState);
81
    }
82
83
    /**
84
     * @When I choose :channelName as a channel filter
85
     */
86
    public function iChooseChannelAsAChannelFilter(string $channelName): void
87
    {
88
        $this->indexPage->chooseChannelFilter($channelName);
89
    }
90
91
    /**
92
     * @When I filter
93
     */
94
    public function iFilter(): void
95
    {
96
        $this->indexPage->filter();
97
    }
98
99
    /**
100
     * @Then I should see( only) :count shipment(s) in the list
101
     * @Then I should see a single shipment in the list
102
     */
103
    public function iShouldSeeCountShipmentsInList(int $count = 1): void
104
    {
105
        Assert::same($this->indexPage->countItems(), $count);
106
    }
107
108
    /**
109
     * @Then I should see a shipment of order :orderNumber
110
     */
111
    public function iShouldSeeShipmentWithOrderNumber(string $orderNumber): void
112
    {
113
        Assert::true($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
114
    }
115
116
    /**
117
     * @Then I should not see a shipment of order :orderNumber
118
     */
119
    public function iShouldNotSeeShipmentWithOrderNumber(string $orderNumber): void
120
    {
121
        Assert::false($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
122
    }
123
124
    /**
125
     * @When I ship the shipment of order :orderNumber
126
     */
127
    public function iShipShipmentOfOrder(string $orderNumber): void
128
    {
129
        $this->indexPage->shipShipmentOfOrderWithNumber($orderNumber);
130
    }
131
132
    /**
133
     * @Then I should see the shipment of order :orderNumber as :shippingState
134
     */
135
    public function iShouldSeeTheShipmentOfOrderAs(string $orderNumber, string $shippingState): void
136
    {
137
        Assert::same($shippingState, $this->indexPage->getShipmentStatusByOrderNumber($orderNumber));
138
    }
139
140
    /**
141
     * @Then I should be notified that the shipment has been successfully shipped
142
     */
143
    public function iShouldBeNotifiedThatTheShipmentHasBeenSuccessfullyShipped(): void
144
    {
145
        $this->notificationChecker->checkNotification('Shipment has been successfully shipped.', NotificationType::success());
146
    }
147
148
    /**
149
     * @When I move to the details of first shipment's order
150
     */
151
    public function iMoveToDetailsOfFirstShipment(): void
152
    {
153
        $this->indexPage->showOrderPageForNthShipment(1);
154
    }
155
156
    /**
157
     * @Then I should see order page with details of order :order
158
     */
159
    public function iShouldSeeOrderPageWithDetailsOfOrder(OrderInterface $order): void
160
    {
161
        Assert::true($this->orderShowPage->isOpen(['id' => $order->getId()]));
162
    }
163
164
    /**
165
     * @Then /^I should see shipment for (the "[^"]+" order) as (\d+)(?:|st|nd|rd|th) in the list$/
166
     */
167
    public function iShouldSeeShipmentForTheOrderInTheList(string $orderNumber, int $position): void
168
    {
169
        Assert::true($this->indexPage->isShipmentWithOrderNumberInPosition($orderNumber, $position));
170
    }
171
}
172