Completed
Push — wtf-removal ( 4585f3 )
by Kamil
18:08
created

ManagingOrdersContext   F

Complexity

Total Complexity 82

Size/Duplication

Total Lines 965
Duplicated Lines 0 %

Coupling/Cohesion

Components 4
Dependencies 11

Importance

Changes 0
Metric Value
wmc 82
lcom 4
cbo 11
dl 0
loc 965
rs 1.263
c 0
b 0
f 0

80 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A iBrowseOrders() 0 4 1
A iBrowseOrderHistory() 0 4 1
A iSeeTheOrder() 0 4 1
A iMarkThisOrderAsAPaid() 0 4 1
A iMarkThisOrderSPaymentAsRefunded() 0 4 1
A specifyItsTrackingCodeAs() 0 5 1
A iShipThisOrder() 0 4 1
A iSwitchSortingBy() 0 4 1
A iSpecifyFilterDateFromAs() 0 4 1
A iSpecifyFilterDateToAs() 0 4 1
A iChooseChannelAsAChannelFilter() 0 4 1
A iChooseCurrencyAsTheFilterCurrency() 0 4 1
A iSpecifyFilterTotalBeingGreaterThan() 0 4 1
A iSpecifyFilterTotalBeingLessThan() 0 4 1
A iFilter() 0 4 1
A iShouldSeeASingleOrderFromCustomer() 0 7 1
A itShouldBePlacedByCustomer() 0 7 1
A itShouldBeShippedTo() 0 17 2
A itShouldBeBilledTo() 0 17 2
A itShouldBeShippedViaShippingMethod() 0 7 1
A itShouldBePaidWith() 0 7 1
A itShouldHaveAmountOfItems() 0 10 1
A theProductShouldBeInTheItemsList() 0 7 1
A theOrdersItemsTotalShouldBe() 0 10 1
A theOrdersTotalShouldBe() 0 10 1
A theOrdersShippingChargesShouldBe() 0 7 1
A theOrdersShippingTotalShouldBe() 0 10 1
A theOrdersPaymentShouldBe() 0 6 1
A theOrderShouldHaveTax() 0 7 1
A theOrdersTaxTotalShouldBe() 0 10 1
A theOrdersPromotionDiscountShouldBe() 0 7 1
A theOrdersPromotionTotalShouldBe() 0 10 1
A iCheckData() 0 4 1
A itemCodeShouldBe() 0 10 1
A itemUnitPriceShouldBe() 0 10 1
A itemDiscountedUnitPriceShouldBe() 0 10 1
A itemQuantityShouldBe() 0 10 1
A itemSubtotalShouldBe() 0 10 1
A theItemShouldHaveDiscount() 0 10 1
A itemTaxShouldBe() 0 10 1
A itemTotalShouldBe() 0 10 1
A iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyCompleted() 0 6 1
A iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyRefunded() 0 6 1
A itShouldHavePaymentState() 0 7 1
A orderPaymentStateShouldBeRefunded() 0 8 1
A iShouldNotBeAbleToFinalizeItsPayment() 0 7 1
A iShouldBeNotifiedThatTheOrderHasBeenSuccessfullyShipped() 0 7 1
A iShouldNotBeAbleToShipThisOrder() 0 7 1
A iCancelThisOrder() 0 4 1
A iShouldBeNotifiedAboutItHasBeenSuccessfullyCanceled() 0 7 1
A iShouldNotBeAbleToCancelThisOrder() 0 7 1
A itsStateShouldBe() 0 8 1
A itShouldHaveState() 0 7 1
A theCustomerServiceShouldKnowAboutThisAdditionalNotes() 0 13 1
A iShouldSeeOrderWithNumber() 0 7 1
A iShouldNotSeeOrderWithNumber() 0 7 1
A iShouldNotSeeAnyOrderWithCurrency() 0 7 1
A theFirstOrderShouldHaveNumber() 0 10 1
A itShouldHaveShipmentState() 0 7 1
A thisOrderShipmentStateShouldBe() 0 7 1
A theOrderShouldHavePaymentState() 0 7 1
A theOrderShouldHaveShipmentState() 0 7 1
A theOrderShouldHaveNumberOfPayments() 0 6 1
A iShouldSeeTheOrderWithTotal() 0 7 1
A iWantToModifyACustomerSShippingAddress() 0 4 1
A iSaveMyChanges() 0 4 1
A iSpecifyTheirShippingAddressAsFor() 0 4 1
A iSpecifyTheirBillingAddressAsFor() 0 4 1
A iShouldBeNotifiedThatTheAndTheInShippingDetailsAreRequired() 0 7 1
A iShouldSeeAsProvinceInTheShippingAddress() 0 7 1
A iShouldSeeAdProvinceInTheBillingAddress() 0 7 1
A theAdministratorShouldKnowAboutIPAddressOfThisOrderMadeBy() 0 17 1
A iSpecifyTheBillingAddressAs() 0 4 1
A iSpecifyTheShippingAddressAs() 0 4 1
A iDoNotSpecifyNewInformation() 0 4 1
A theAdministratorShouldSeeThatThisOrderHasBeenPlacedIn() 0 11 1
A theAdministratorShouldSeeTheOrderWithTotalInOrderList() 0 11 1
A thereShouldBeCountChangesInTheRegistry() 0 7 1
A assertElementValidationMessage() 0 8 1

How to fix   Complexity   

Complex Class

Complex classes like ManagingOrdersContext often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ManagingOrdersContext, and based on these observations, apply Extract Interface, too.

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\Admin;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Behat\NotificationType;
16
use Sylius\Behat\Page\Admin\Order\HistoryPageInterface;
17
use Sylius\Behat\Page\Admin\Order\IndexPageInterface;
18
use Sylius\Behat\Page\Admin\Order\ShowPageInterface;
19
use Sylius\Behat\Page\Admin\Order\UpdatePageInterface;
20
use Sylius\Behat\Service\NotificationCheckerInterface;
21
use Sylius\Behat\Service\SharedSecurityServiceInterface;
22
use Sylius\Behat\Service\SharedStorageInterface;
23
use Sylius\Component\Addressing\Model\AddressInterface;
24
use Sylius\Component\Core\Model\AdminUserInterface;
25
use Sylius\Component\Core\Model\CustomerInterface;
26
use Sylius\Component\Core\Model\OrderInterface;
27
use Webmozart\Assert\Assert;
28
29
/**
30
 * @author Paweł Jędrzejewski <[email protected]>
31
 * @author Grzegorz Sadowski <[email protected]>
32
 */
33
final class ManagingOrdersContext implements Context
34
{
35
    /**
36
     * @var SharedStorageInterface
37
     */
38
    private $sharedStorage;
39
40
    /**
41
     * @var IndexPageInterface
42
     */
43
    private $indexPage;
44
45
    /**
46
     * @var ShowPageInterface
47
     */
48
    private $showPage;
49
50
    /**
51
     * @var UpdatePageInterface
52
     */
53
    private $updatePage;
54
55
    /**
56
     * @var HistoryPageInterface
57
     */
58
    private $historyPage;
59
60
    /**
61
     * @var NotificationCheckerInterface
62
     */
63
    private $notificationChecker;
64
65
    /**
66
     * @var SharedSecurityServiceInterface
67
     */
68
    private $sharedSecurityService;
69
70
    /**
71
     * @param SharedStorageInterface $sharedStorage
72
     * @param IndexPageInterface $indexPage
73
     * @param ShowPageInterface $showPage
74
     * @param UpdatePageInterface $updatePage
75
     * @param HistoryPageInterface $historyPage
76
     * @param NotificationCheckerInterface $notificationChecker
77
     * @param SharedSecurityServiceInterface $sharedSecurityService
78
     */
79
    public function __construct(
80
        SharedStorageInterface $sharedStorage,
81
        IndexPageInterface $indexPage,
82
        ShowPageInterface $showPage,
83
        UpdatePageInterface $updatePage,
84
        HistoryPageInterface $historyPage,
85
        NotificationCheckerInterface $notificationChecker,
86
        SharedSecurityServiceInterface $sharedSecurityService
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $sharedSecurityService 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...
87
    ) {
88
        $this->sharedStorage = $sharedStorage;
89
        $this->indexPage = $indexPage;
90
        $this->showPage = $showPage;
91
        $this->updatePage = $updatePage;
92
        $this->historyPage = $historyPage;
93
        $this->notificationChecker = $notificationChecker;
94
        $this->sharedSecurityService = $sharedSecurityService;
95
    }
96
97
    /**
98
     * @Given I am browsing orders
99
     * @When I browse orders
100
     */
101
    public function iBrowseOrders()
102
    {
103
        $this->indexPage->open();
104
    }
105
106
    /**
107
     * @When I browse order's :order history
108
     */
109
    public function iBrowseOrderHistory(OrderInterface $order)
110
    {
111
        $this->historyPage->open(['id' => $order->getId()]);
112
    }
113
114
    /**
115
     * @Given /^I am viewing the summary of (this order)$/
116
     * @When I view the summary of the order :order
117
     */
118
    public function iSeeTheOrder(OrderInterface $order)
119
    {
120
        $this->showPage->open(['id' => $order->getId()]);
121
    }
122
123
    /**
124
     * @When /^I mark (this order) as paid$/
125
     */
126
    public function iMarkThisOrderAsAPaid(OrderInterface $order)
127
    {
128
        $this->showPage->completeOrderLastPayment($order);
129
    }
130
131
    /**
132
     * @When /^I mark (this order)'s payment as refunded$/
133
     */
134
    public function iMarkThisOrderSPaymentAsRefunded(OrderInterface $order)
135
    {
136
        $this->showPage->refundOrderLastPayment($order);
137
    }
138
139
    /**
140
     * @When specify its tracking code as :trackingCode
141
     */
142
    public function specifyItsTrackingCodeAs($trackingCode)
143
    {
144
        $this->showPage->specifyTrackingCode($trackingCode);
145
        $this->sharedStorage->set('tracking_code', $trackingCode);
146
    }
147
148
    /**
149
     * @When /^I ship (this order)$/
150
     */
151
    public function iShipThisOrder(OrderInterface $order)
152
    {
153
        $this->showPage->shipOrder($order);
154
    }
155
156
    /**
157
     * @When I switch the way orders are sorted by :fieldName
158
     */
159
    public function iSwitchSortingBy($fieldName)
160
    {
161
        $this->indexPage->sortBy($fieldName);
162
    }
163
164
    /**
165
     * @When I specify filter date from as :dateTime
166
     */
167
    public function iSpecifyFilterDateFromAs($dateTime)
168
    {
169
        $this->indexPage->specifyFilterDateFrom(new \DateTime($dateTime));
170
    }
171
172
    /**
173
     * @When I specify filter date to as :dateTime
174
     */
175
    public function iSpecifyFilterDateToAs($dateTime)
176
    {
177
        $this->indexPage->specifyFilterDateTo(new \DateTime($dateTime));
178
    }
179
180
    /**
181
     * @When I choose :channelName as a channel filter
182
     */
183
    public function iChooseChannelAsAChannelFilter($channelName)
184
    {
185
        $this->indexPage->chooseChannelFilter($channelName);
186
    }
187
188
    /**
189
     * @When I choose :currencyName as the filter currency
190
     */
191
    public function iChooseCurrencyAsTheFilterCurrency($currencyName)
192
    {
193
        $this->indexPage->chooseCurrencyFilter($currencyName);
194
    }
195
196
    /**
197
     * @When I specify filter total being greater than :total
198
     */
199
    public function iSpecifyFilterTotalBeingGreaterThan($total)
200
    {
201
        $this->indexPage->specifyFilterTotalGreaterThan($total);
202
    }
203
204
    /**
205
     * @When I specify filter total being less than :total
206
     */
207
    public function iSpecifyFilterTotalBeingLessThan($total)
208
    {
209
        $this->indexPage->specifyFilterTotalLessThan($total);
210
    }
211
212
    /**
213
     * @When I filter
214
     */
215
    public function iFilter()
216
    {
217
        $this->indexPage->filter();
218
    }
219
220
    /**
221
     * @Then I should see a single order from customer :customer
222
     */
223
    public function iShouldSeeASingleOrderFromCustomer(CustomerInterface $customer)
224
    {
225
        Assert::true(
226
            $this->indexPage->isSingleResourceOnPage(['customer' => $customer->getEmail()]),
227
            sprintf('Cannot find order for customer "%s" in the list.', $customer->getEmail())
228
        );
229
    }
230
231
    /**
232
     * @Then it should have been placed by the customer :customerEmail
233
     */
234
    public function itShouldBePlacedByCustomer($customerEmail)
235
    {
236
        Assert::true(
237
            $this->showPage->hasCustomer($customerEmail),
238
            sprintf('Cannot find customer "%s".', $customerEmail)
239
        );
240
    }
241
242
    /**
243
     * @Then it should be shipped to :customerName, :street, :postcode, :city, :countryName
244
     * @Then /^(this order) should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/
245
     */
246
    public function itShouldBeShippedTo(
247
        OrderInterface $order = null,
248
        $customerName,
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
249
        $street,
250
        $postcode,
251
        $city,
252
        $countryName
253
    ) {
254
        if (null !== $order) {
255
            $this->iSeeTheOrder($order);
256
        }
257
258
        Assert::true(
259
            $this->showPage->hasShippingAddress($customerName, $street, $postcode, $city, $countryName),
260
            sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName)
261
        );
262
    }
263
264
    /**
265
     * @Then it should be billed to :customerName, :street, :postcode, :city, :countryName
266
     * @Then the order should be billed to :customerName, :street, :postcode, :city, :countryName
267
     * @Then /^(this order) bill should (?:|still )be shipped to "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)"$/
268
     */
269
    public function itShouldBeBilledTo(
270
        OrderInterface $order = null,
271
        $customerName,
0 ignored issues
show
Coding Style introduced by
Parameters which have default values should be placed at the end.

If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway:

// $a must always be passed; it's default value is never used.
function someFunction($a = 5, $b) { }
Loading history...
272
        $street,
273
        $postcode,
274
        $city,
275
        $countryName
276
    ) {
277
        if (null !== $order) {
278
            $this->iSeeTheOrder($order);
279
        }
280
281
        Assert::true(
282
            $this->showPage->hasBillingAddress($customerName, $street, $postcode, $city, $countryName),
283
            sprintf('Cannot find shipping address "%s, %s %s, %s".', $street, $postcode, $city, $countryName)
284
        );
285
    }
286
287
    /**
288
     * @Then it should be shipped via the :shippingMethodName shipping method
289
     */
290
    public function itShouldBeShippedViaShippingMethod($shippingMethodName)
291
    {
292
        Assert::true(
293
            $this->showPage->hasShipment($shippingMethodName),
294
            sprintf('Cannot find shipment "%s".', $shippingMethodName)
295
        );
296
    }
297
298
    /**
299
     * @Then it should be paid with :paymentMethodName
300
     */
301
    public function itShouldBePaidWith($paymentMethodName)
302
    {
303
        Assert::true(
304
            $this->showPage->hasPayment($paymentMethodName),
305
            sprintf('Cannot find payment "%s".', $paymentMethodName)
306
        );
307
    }
308
309
    /**
310
     * @Then /^it should have (\d+) items$/
311
     * @Then I should see :amount orders in the list
312
     * @Then I should see a single order in the list
313
     */
314
    public function itShouldHaveAmountOfItems($amount = 1)
315
    {
316
        $itemsCount = $this->showPage->countItems();
317
318
        Assert::same(
319
            (int)$amount,
320
            $itemsCount,
321
            sprintf('There should be %d items, but get %d.', $amount, $itemsCount)
322
        );
323
    }
324
325
    /**
326
     * @Then the product named :productName should be in the items list
327
     */
328
    public function theProductShouldBeInTheItemsList($productName)
329
    {
330
        Assert::true(
331
            $this->showPage->isProductInTheList($productName),
332
            sprintf('Product %s is not in the item list.', $productName)
333
        );
334
    }
335
336
    /**
337
     * @Then the order's items total should be :itemsTotal
338
     */
339
    public function theOrdersItemsTotalShouldBe($itemsTotal)
340
    {
341
        $itemsTotalOnPage = $this->showPage->getItemsTotal();
342
343
        Assert::eq(
344
            $itemsTotalOnPage,
345
            $itemsTotal,
346
            'Items total is %s, but should be %s.'
347
        );
348
    }
349
350
    /**
351
     * @Then /^the order's total should(?:| still) be "([^"]+)"$/
352
     */
353
    public function theOrdersTotalShouldBe($total)
354
    {
355
        $totalOnPage = $this->showPage->getTotal();
356
357
        Assert::eq(
358
            $totalOnPage,
359
            $total,
360
            'Total is %s, but should be %s.'
361
        );
362
    }
363
364
    /**
365
     * @Then there should be a shipping charge :shippingCharge
366
     */
367
    public function theOrdersShippingChargesShouldBe($shippingCharge)
368
    {
369
        Assert::true(
370
            $this->showPage->hasShippingCharge($shippingCharge),
371
            sprintf('Shipping charges is not "%s".', $shippingCharge)
372
        );
373
    }
374
375
    /**
376
     * @Then the order's shipping total should be :shippingTotal
377
     */
378
    public function theOrdersShippingTotalShouldBe($shippingTotal)
379
    {
380
        $shippingTotalOnPage = $this->showPage->getShippingTotal();
381
382
        Assert::eq(
383
            $shippingTotal,
384
            $shippingTotalOnPage,
385
            sprintf('Shipping total is "%s", but should be "%s".', $shippingTotalOnPage, $shippingTotal)
386
        );
387
    }
388
389
    /**
390
     * @Then the order's payment should (also) be :paymentAmount
391
     */
392
    public function theOrdersPaymentShouldBe($paymentAmount)
393
    {
394
        $actualPaymentAmount = $this->showPage->getPaymentAmount();
395
396
        Assert::eq($paymentAmount, $actualPaymentAmount);
397
    }
398
399
    /**
400
     * @Then the order should have tax :tax
401
     */
402
    public function theOrderShouldHaveTax($tax)
403
    {
404
        Assert::true(
405
            $this->showPage->hasTax($tax),
406
            sprintf('Order should have tax "%s", but it does not.', $tax)
407
        );
408
    }
409
410
    /**
411
     * @Then /^the order's tax total should(?:| still) be "([^"]+)"$/
412
     */
413
    public function theOrdersTaxTotalShouldBe($taxTotal)
414
    {
415
        $taxTotalOnPage = $this->showPage->getTaxTotal();
416
417
        Assert::eq(
418
            $taxTotal,
419
            $taxTotalOnPage,
420
            sprintf('Tax total is "%s", but should be "%s".', $taxTotalOnPage, $taxTotal)
421
        );
422
    }
423
424
    /**
425
     * @Then the order's promotion discount should be :promotionDiscount
426
     */
427
    public function theOrdersPromotionDiscountShouldBe($promotionDiscount)
428
    {
429
        Assert::true(
430
            $this->showPage->hasPromotionDiscount($promotionDiscount),
431
            sprintf('Promotion discount is not "%s".', $promotionDiscount)
432
        );
433
    }
434
435
    /**
436
     * @Then /^the order's promotion total should(?:| still) be "([^"]+)"$/
437
     */
438
    public function theOrdersPromotionTotalShouldBe($promotionTotal)
439
    {
440
        $promotionTotalOnPage = $this->showPage->getPromotionTotal();
441
442
        Assert::eq(
443
            $promotionTotalOnPage,
444
            $promotionTotal,
445
            'Promotion total is %s, but should be %s.'
446
        );
447
    }
448
449
    /**
450
     * @When I check :itemName data
451
     */
452
    public function iCheckData($itemName)
453
    {
454
        $this->sharedStorage->set('item', $itemName);
455
    }
456
457
    /**
458
     * @Then /^(its) code should be "([^"]+)"$/
459
     */
460
    public function itemCodeShouldBe($itemName, $code)
461
    {
462
        $itemCodeOnPage = $this->showPage->getItemCode($itemName);
463
464
        Assert::same(
465
            $itemCodeOnPage,
466
            $code,
467
            'Item code is %s, but should be %s.'
468
        );
469
    }
470
471
    /**
472
     * @Then /^(its) unit price should be ([^"]+)$/
473
     */
474
    public function itemUnitPriceShouldBe($itemName, $unitPrice)
475
    {
476
        $itemUnitPriceOnPage = $this->showPage->getItemUnitPrice($itemName);
477
478
        Assert::eq(
479
            $itemUnitPriceOnPage,
480
            $unitPrice,
481
            'Item unit price is %s, but should be %s.'
482
        );
483
    }
484
485
    /**
486
     * @Then /^(its) discounted unit price should be ([^"]+)$/
487
     */
488
    public function itemDiscountedUnitPriceShouldBe($itemName, $discountedUnitPrice)
489
    {
490
        $itemUnitPriceOnPage = $this->showPage->getItemDiscountedUnitPrice($itemName);
491
492
        Assert::eq(
493
            $itemUnitPriceOnPage,
494
            $discountedUnitPrice,
495
            'Item discounted unit price is %s, but should be %s.'
496
        );
497
    }
498
499
    /**
500
     * @Then /^(its) quantity should be ([^"]+)$/
501
     */
502
    public function itemQuantityShouldBe($itemName, $quantity)
503
    {
504
        $itemQuantityOnPage = $this->showPage->getItemQuantity($itemName);
505
506
        Assert::eq(
507
            $itemQuantityOnPage,
508
            $quantity,
509
            'Item quantity is %s, but should be %s.'
510
        );
511
    }
512
513
    /**
514
     * @Then /^(its) subtotal should be ([^"]+)$/
515
     */
516
    public function itemSubtotalShouldBe($itemName, $subtotal)
517
    {
518
        $itemSubtotalOnPage = $this->showPage->getItemSubtotal($itemName);
519
520
        Assert::eq(
521
            $itemSubtotalOnPage,
522
            $subtotal,
523
            'Item subtotal is %s, but should be %s.'
524
        );
525
    }
526
527
    /**
528
     * @Then /^(its) discount should be ([^"]+)$/
529
     */
530
    public function theItemShouldHaveDiscount($itemName, $discount)
531
    {
532
        $itemDiscountOnPage = $this->showPage->getItemDiscount($itemName);
533
534
        Assert::eq(
535
            $itemDiscountOnPage,
536
            $discount,
537
            'Item discount is %s, but should be %s.'
538
        );
539
    }
540
541
    /**
542
     * @Then /^(its) tax should be ([^"]+)$/
543
     */
544
    public function itemTaxShouldBe($itemName, $tax)
545
    {
546
        $itemTaxOnPage = $this->showPage->getItemTax($itemName);
547
548
        Assert::eq(
549
            $itemTaxOnPage,
550
            $tax,
551
            'Item tax is %s, but should be %s.'
552
        );
553
    }
554
555
    /**
556
     * @Then /^(its) total should be ([^"]+)$/
557
     */
558
    public function itemTotalShouldBe($itemName, $total)
559
    {
560
        $itemTotalOnPage = $this->showPage->getItemTotal($itemName);
561
562
        Assert::eq(
563
            $itemTotalOnPage,
564
            $total,
565
            'Item total is %s, but should be %s.'
566
        );
567
    }
568
569
    /**
570
     * @Then I should be notified that the order's payment has been successfully completed
571
     */
572
    public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyCompleted()
573
    {
574
        $this
575
            ->notificationChecker
576
            ->checkNotification('Payment has been successfully updated.', NotificationType::success());
577
    }
578
579
    /**
580
     * @Then I should be notified that the order's payment has been successfully refunded
581
     */
582
    public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyRefunded()
583
    {
584
        $this
585
            ->notificationChecker
586
            ->checkNotification('Payment has been successfully refunded.', NotificationType::success());
587
    }
588
589
    /**
590
     * @Then it should have payment state :paymentState
591
     * @Then it should have payment with state :paymentState
592
     */
593
    public function itShouldHavePaymentState($paymentState)
594
    {
595
        Assert::true(
596
            $this->showPage->hasPayment($paymentState),
597
            sprintf('It should have payment with %s state', $paymentState)
598
        );
599
    }
600
601
    /**
602
     * @Then it's payment state should be refunded
603
     */
604
    public function orderPaymentStateShouldBeRefunded()
605
    {
606
        Assert::same(
607
            $this->showPage->getPaymentState(),
608
            'Refunded',
609
            'Order payment state should be refunded, but it is not.'
610
        );
611
    }
612
613
    /**
614
     * @Then /^I should not be able to mark (this order) as paid again$/
615
     */
616
    public function iShouldNotBeAbleToFinalizeItsPayment(OrderInterface $order)
617
    {
618
        Assert::false(
619
            $this->showPage->canCompleteOrderLastPayment($order),
620
            'It should not have complete payment button.'
621
        );
622
    }
623
624
    /**
625
     * @Then I should be notified that the order has been successfully shipped
626
     */
627
    public function iShouldBeNotifiedThatTheOrderHasBeenSuccessfullyShipped()
628
    {
629
        $this->notificationChecker->checkNotification(
630
            'Shipment has been successfully updated.',
631
            NotificationType::success()
632
        );
633
    }
634
635
    /**
636
     * @Then /^I should not be able to ship (this order)$/
637
     */
638
    public function iShouldNotBeAbleToShipThisOrder(OrderInterface $order)
639
    {
640
        Assert::false(
641
            $this->showPage->canShipOrder($order),
642
            'It should not have ship shipment button.'
643
        );
644
    }
645
646
    /**
647
     * @When I cancel this order
648
     */
649
    public function iCancelThisOrder()
650
    {
651
        $this->showPage->cancelOrder();
652
    }
653
654
    /**
655
     * @Then I should be notified that it has been successfully updated
656
     */
657
    public function iShouldBeNotifiedAboutItHasBeenSuccessfullyCanceled()
658
    {
659
        $this->notificationChecker->checkNotification(
660
            'Order has been successfully updated.',
661
            NotificationType::success()
662
        );
663
    }
664
665
    /**
666
     * @Then I should not be able to cancel this order
667
     */
668
    public function iShouldNotBeAbleToCancelThisOrder()
669
    {
670
        Assert::false(
671
            $this->showPage->hasCancelButton(),
672
            'There should not be a cancel button, but it is.'
673
        );
674
    }
675
676
    /**
677
     * @Then this order should have state :state
678
     * @Then its state should be :state
679
     */
680
    public function itsStateShouldBe($state)
681
    {
682
        Assert::same(
683
            $this->showPage->getOrderState(),
684
            $state,
685
            'The order state should be %2$s, but it is %s.'
686
        );
687
    }
688
689
    /**
690
     * @Then it should( still) have a :state state
691
     */
692
    public function itShouldHaveState($state)
693
    {
694
        Assert::true(
695
            $this->indexPage->isSingleResourceOnPage(['state' => $state]),
696
            sprintf('Cannot find order with "%s" state in the list.', $state)
697
        );
698
    }
699
700
    /**
701
     * @Then /^(the administrator) should know about (this additional note) for (this order made by "[^"]+")$/
702
     */
703
    public function theCustomerServiceShouldKnowAboutThisAdditionalNotes(
704
        AdminUserInterface $user,
705
        $note,
706
        OrderInterface $order
707
    ) {
708
        $this->sharedSecurityService->performActionAsAdminUser(
709
            $user,
710
            function () use ($note, $order) {
711
                $this->showPage->open(['id' => $order->getId()]);
712
                Assert::true($this->showPage->hasNote($note), sprintf('I should see %s note, but I do not see', $note));
713
            }
714
        );
715
    }
716
717
    /**
718
     * @Then I should see an order with :orderNumber number
719
     */
720
    public function iShouldSeeOrderWithNumber($orderNumber)
721
    {
722
        Assert::true(
723
            $this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]),
724
            sprintf('Cannot find order with "%s" number in the list.', $orderNumber)
725
        );
726
    }
727
728
    /**
729
     * @Then I should not see an order with :orderNumber number
730
     */
731
    public function iShouldNotSeeOrderWithNumber($orderNumber)
732
    {
733
        Assert::false(
734
            $this->indexPage->isSingleResourceOnPage(['number' => $orderNumber]),
735
            sprintf('Order with "%s" number should not be in the list.', $orderNumber)
736
        );
737
    }
738
739
    /**
740
     * @Then I should not see any orders with currency :currencyCode
741
     */
742
    public function iShouldNotSeeAnyOrderWithCurrency($currencyCode)
743
    {
744
        Assert::false(
745
            $this->indexPage->isSingleResourceOnPage(['currencyCode' => $currencyCode]),
746
            sprintf('Order with currency "%s" should not be on the list.', $currencyCode)
747
        );
748
    }
749
750
    /**
751
     * @Then the first order should have number :number
752
     */
753
    public function theFirstOrderShouldHaveNumber($number)
754
    {
755
        $actualNumber = $this->indexPage->getColumnFields('number')[0];
756
757
        Assert::eq(
758
            $actualNumber,
759
            $number,
760
            sprintf('Expected first order\'s number to be %s, but it is %s.', $number, $actualNumber)
761
        );
762
    }
763
764
    /**
765
     * @Then it should have shipment in state :shipmentState
766
     */
767
    public function itShouldHaveShipmentState($shipmentState)
768
    {
769
        Assert::true(
770
            $this->showPage->hasShipment($shipmentState),
771
            sprintf('It should have shipment with %s state', $shipmentState)
772
        );
773
    }
774
775
    /**
776
     * @Then order :orderNumber should have shipment state :shippingState
777
     */
778
    public function thisOrderShipmentStateShouldBe($shippingState)
779
    {
780
        Assert::true(
781
            $this->indexPage->isSingleResourceOnPage(['shippingState' => $shippingState]),
782
            sprintf('Order should have %s shipping state', $shippingState)
783
        );
784
    }
785
786
    /**
787
     * @Then the order :order should have order payment state :orderPaymentState
788
     * @Then /^(this order) should have order payment state "([^"]+)"$/
789
     */
790
    public function theOrderShouldHavePaymentState(OrderInterface $order, $orderPaymentState)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
791
    {
792
        Assert::true(
793
            $this->indexPage->isSingleResourceOnPage(['paymentState' => $orderPaymentState]),
794
            sprintf('Cannot find order with "%s" order payment state in the list.', $orderPaymentState)
795
        );
796
    }
797
798
    /**
799
     * @Then /^(this order) should have order shipping state "([^"]+)"$/
800
     */
801
    public function theOrderShouldHaveShipmentState(OrderInterface $order, $orderShipmentState)
0 ignored issues
show
Unused Code introduced by
The parameter $order is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
802
    {
803
        Assert::true(
804
            $this->indexPage->isSingleResourceOnPage(['shippingState' => $orderShipmentState]),
805
            sprintf('Cannot find order with "%s" order shipping state on the list.', $orderShipmentState)
806
        );
807
    }
808
809
    /**
810
     * @Then /^there should be(?:| only) (\d+) payments?$/
811
     */
812
    public function theOrderShouldHaveNumberOfPayments($number)
813
    {
814
        $actualNumberOfPayments = $this->showPage->getPaymentsCount();
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $actualNumberOfPayments 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...
815
816
        Assert::same((int)$number, $actualNumberOfPayments);
817
    }
818
819
    /**
820
     * @Then I should see the order :orderNumber with total :total
821
     */
822
    public function iShouldSeeTheOrderWithTotal($orderNumber, $total)
823
    {
824
        Assert::true(
825
            $this->indexPage->isSingleResourceOnPage(['total' => $total]),
826
            sprintf('The total of order "%s" is not "%s".', $orderNumber, $total)
827
        );
828
    }
829
830
    /**
831
     * @When /^I want to modify a customer's (?:billing|shipping) address of (this order)$/
832
     */
833
    public function iWantToModifyACustomerSShippingAddress(OrderInterface $order)
834
    {
835
        $this->updatePage->open(['id' => $order->getId()]);
836
    }
837
838
    /**
839
     * @When I save my changes
840
     * @When I try to save my changes
841
     */
842
    public function iSaveMyChanges()
843
    {
844
        $this->updatePage->saveChanges();
845
    }
846
847
    /**
848
     * @When /^I specify their (?:|new )shipping (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
849
     */
850
    public function iSpecifyTheirShippingAddressAsFor(AddressInterface $address)
851
    {
852
        $this->updatePage->specifyShippingAddress($address);
853
    }
854
855
    /**
856
     * @When /^I specify their (?:|new )billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
857
     */
858
    public function iSpecifyTheirBillingAddressAsFor(AddressInterface $address)
859
    {
860
        $this->updatePage->specifyBillingAddress($address);
861
    }
862
863
    /**
864
     * @Then /^I should be notified that the "([^"]+)", the "([^"]+)", the "([^"]+)" and the "([^"]+)" in (shipping|billing) details are required$/
865
     */
866
    public function iShouldBeNotifiedThatTheAndTheInShippingDetailsAreRequired($firstElement, $secondElement, $thirdElement, $fourthElement, $type)
867
    {
868
        $this->assertElementValidationMessage($type, $firstElement, sprintf('Please enter %s.', $firstElement));
869
        $this->assertElementValidationMessage($type, $secondElement, sprintf('Please enter %s.', $secondElement));
870
        $this->assertElementValidationMessage($type, $thirdElement, sprintf('Please enter %s.', $thirdElement));
871
        $this->assertElementValidationMessage($type, $fourthElement, sprintf('Please enter %s.', $fourthElement));
872
    }
873
874
    /**
875
     * @Then I should see :provinceName as province in the shipping address
876
     */
877
    public function iShouldSeeAsProvinceInTheShippingAddress($provinceName)
878
    {
879
        Assert::true(
880
            $this->showPage->hasShippingProvinceName($provinceName),
881
            sprintf('Cannot find shipping address with province %s', $provinceName)
882
        );
883
    }
884
885
    /**
886
     * @Then I should see :provinceName ad province in the billing address
887
     */
888
    public function iShouldSeeAdProvinceInTheBillingAddress($provinceName)
889
    {
890
        Assert::true(
891
            $this->showPage->hasBillingProvinceName($provinceName),
892
            sprintf('Cannot find shipping address with province %s', $provinceName)
893
        );
894
    }
895
896
    /**
897
     * @Then /^(the administrator) should know about IP address of (this order made by "[^"]+")$/
898
     */
899
    public function theAdministratorShouldKnowAboutIPAddressOfThisOrderMadeBy(
900
        AdminUserInterface $user,
901
        OrderInterface $order
902
    ) {
903
        $this->sharedSecurityService->performActionAsAdminUser(
904
            $user,
905
            function () use ($order) {
906
                $this->showPage->open(['id' => $order->getId()]);
907
908
                Assert::notSame(
909
                    $this->showPage->getIpAddressAssigned(),
910
                    '',
911
                    'There should be IP address assigned to order, but there is not.'
912
                );
913
            }
914
        );
915
    }
916
917
    /**
918
     * @When /^I (clear old billing address) information$/
919
     */
920
    public function iSpecifyTheBillingAddressAs(AddressInterface $address)
921
    {
922
        $this->updatePage->specifyBillingAddress($address);
923
    }
924
925
    /**
926
     * @When /^I (clear old shipping address) information$/
927
     */
928
    public function iSpecifyTheShippingAddressAs(AddressInterface $address)
929
    {
930
        $this->updatePage->specifyShippingAddress($address);
931
    }
932
933
    /**
934
     * @When /^I do not specify new information$/
935
     */
936
    public function iDoNotSpecifyNewInformation()
937
    {
938
        // Intentionally left blank to fulfill context expectation
939
    }
940
941
    /**
942
     * @Then /^(the administrator) should see that (order placed by "[^"]+") has "([^"]+)" currency$/
943
     */
944
    public function theAdministratorShouldSeeThatThisOrderHasBeenPlacedIn(AdminUserInterface $user, OrderInterface $order, $currency)
945
    {
946
        $this->sharedSecurityService->performActionAsAdminUser($user, function () use ($order, $currency) {
947
            $this->showPage->open(['id' => $order->getId()]);
948
            Assert::same(
949
                $this->showPage->getOrderCurrency(),
950
                $currency,
951
                'The order has been placed in %s, but it was expected to be placed in %s'
952
            );
953
        });
954
    }
955
956
    /**
957
     * @Then /^(the administrator) should see the order with total "([^"]+)" in order list$/
958
     */
959
    public function theAdministratorShouldSeeTheOrderWithTotalInOrderList(AdminUserInterface $user, $total)
960
    {
961
        $this->sharedSecurityService->performActionAsAdminUser($user, function () use ($total) {
962
            $this->indexPage->open();
963
964
            Assert::true(
965
                $this->indexPage->isSingleResourceOnPage(['total' => $total]),
966
                sprintf('The order with total "%s" has not been found.', $total)
967
            );
968
        });
969
    }
970
971
    /**
972
     * @Then there should be :count changes in the registry
973
     */
974
    public function thereShouldBeCountChangesInTheRegistry($count)
975
    {
976
        Assert::same(
977
            (int) $count,
978
            $this->historyPage->countShippingAddressChanges()
979
        );
980
    }
981
982
    /**
983
     * @param string $type
984
     * @param string $element
985
     * @param string $expectedMessage
986
     *
987
     * @throws \InvalidArgumentException
988
     */
989
    private function assertElementValidationMessage($type, $element, $expectedMessage)
990
    {
991
        $element = sprintf('%s_%s', $type, implode('_', explode(' ', $element)));
992
        Assert::true(
993
            $this->updatePage->checkValidationMessageFor($element, $expectedMessage),
994
            sprintf('The %s should be required.', $element)
995
        );
996
    }
997
}
998