Completed
Push — allow-no-default-tax-zone-in-c... ( 67cea0 )
by Kamil
06:23
created

shipmentOfOrderShouldBe()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 4
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->getName()];
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 filter
85
     */
86
    public function iFilter(): void
87
    {
88
        $this->indexPage->filter();
89
    }
90
91
    /**
92
     * @Then I should see( only) :count shipment(s) in the list
93
     * @Then I should see a single shipment in the list
94
     */
95
    public function iShouldSeeCountShipmentsInList(int $count = 1): void
96
    {
97
        Assert::same($count, $this->indexPage->countItems());
98
    }
99
100
    /**
101
     * @Then I should see a shipment of order :orderNumber
102
     */
103
    public function iShouldSeeShipmentWithOrderNumber(string $orderNumber): void
104
    {
105
        Assert::true($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
106
    }
107
108
    /**
109
     * @Then I should not see a shipment of order :orderNumber
110
     */
111
    public function iShouldNotSeeShipmentWithOrderNumber(string $orderNumber): void
112
    {
113
        Assert::false($this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]));
114
    }
115
116
    /**
117
     * @When I ship the shipment of order :orderNumber
118
     */
119
    public function iShipShipmentOfOrder(string $orderNumber): void
120
    {
121
        $this->indexPage->shipShipmentOfOrderWithNumber($orderNumber);
122
    }
123
124
    /**
125
     * @Then I should see the shipment of order :orderNumber as :shippingState
126
     */
127
    public function iShouldSeeTheShipmentOfOrderAs(string $orderNumber, string $shippingState): void
128
    {
129
        Assert::same($shippingState, $this->indexPage->getShipmentStatusByOrderNumber($orderNumber));
130
    }
131
132
    /**
133
     * @Then I should be notified that the shipment has been successfully shipped
134
     */
135
    public function iShouldBeNotifiedThatTheShipmentHasBeenSuccessfullyShipped(): void
136
    {
137
        $this->notificationChecker->checkNotification('Shipment has been successfully shipped.', NotificationType::success());
138
    }
139
140
    /**
141
     * @When I move to the details of first shipment's order
142
     */
143
    public function iMoveToDetailsOfFirstShipment(): void
144
    {
145
        $this->indexPage->showOrderPageForNthShipment(1);
146
    }
147
148
    /**
149
     * @Then I should see order page with details of order :order
150
     */
151
    public function iShouldSeeOrderPageWithDetailsOfOrder(OrderInterface $order): void
152
    {
153
        Assert::true($this->orderShowPage->isOpen(['id' => $order->getId()]));
154
    }
155
}
156