Completed
Push — master ( 68b7da...429264 )
by Paweł
17s
created

CheckoutContext::iShouldSeeDiscountTotal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
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
namespace Sylius\Behat\Context\Ui;
13
14
use Behat\Behat\Context\Context;
15
use Sylius\Behat\Page\Shop\Checkout\AddressingPageInterface;
16
use Sylius\Behat\Page\Shop\Checkout\PaymentPageInterface;
17
use Sylius\Behat\Page\Shop\Checkout\ShippingPageInterface;
18
use Sylius\Behat\Page\Shop\Checkout\SummaryPageInterface;
19
use Sylius\Behat\Page\Shop\Order\OrderPaymentsPageInterface;
20
use Sylius\Behat\Page\Shop\Checkout\AddressingStepInterface;
21
use Sylius\Behat\Page\Shop\Checkout\FinalizeStepInterface;
22
use Sylius\Behat\Page\Shop\Checkout\PaymentStepInterface;
23
use Sylius\Behat\Page\Shop\Checkout\SecurityStepInterface;
24
use Sylius\Behat\Page\Shop\Checkout\ShippingStepInterface;
25
use Sylius\Behat\Page\Shop\Checkout\ThankYouPageInterface;
26
use Sylius\Component\Core\Formatter\StringInflector;
27
use Sylius\Behat\Service\SecurityServiceInterface;
28
use Sylius\Component\Core\Model\AddressInterface;
29
use Sylius\Component\Core\Model\OrderInterface;
30
use Sylius\Component\Core\Model\ProductInterface;
31
use Sylius\Component\Core\Model\ShippingMethodInterface;
32
use Sylius\Component\Core\Model\UserInterface;
33
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
34
use Sylius\Component\Order\Repository\OrderRepositoryInterface;
35
use Sylius\Component\Payment\Model\PaymentInterface;
36
use Sylius\Component\Payment\Model\PaymentMethodInterface;
37
use Webmozart\Assert\Assert;
38
39
/**
40
 * @author Arkadiusz Krakowiak <[email protected]>
41
 */
42
final class CheckoutContext implements Context
43
{
44
    /**
45
     * @var SharedStorageInterface
46
     */
47
    private $sharedStorage;
48
49
    /**
50
     * @var SecurityStepInterface
51
     */
52
    private $checkoutSecurityStep;
53
54
    /**
55
     * @var AddressingStepInterface
56
     */
57
    private $checkoutAddressingStep;
58
59
    /**
60
     * @var AddressingPageInterface
61
     */
62
    private $addressingPage;
63
64
    /**
65
     * @var ShippingStepInterface
66
     */
67
    private $checkoutShippingStep;
68
69
    /**
70
     * @var PaymentStepInterface
71
     */
72
    private $checkoutPaymentStep;
73
74
    /**
75
     * @var PaymentPageInterface
76
     */
77
    private $paymentPage;
78
79
    /**
80
     * @var FinalizeStepInterface
81
     */
82
    private $checkoutFinalizeStep;
83
84
    /**
85
     * @var ThankYouPageInterface
86
     */
87
    private $checkoutThankYouPage;
88
89
    /**
90
     * @var OrderPaymentsPageInterface
91
     */
92
    private $orderPaymentsPage;
93
94
    /**
95
     * @var ShippingPageInterface
96
     */
97
    private $shippingPage;
98
99
    /**
100
     * @var SummaryPageInterface
101
     */
102
    private $summaryPage;
103
104
    /**
105
     * @var OrderRepositoryInterface
106
     */
107
    private $orderRepository;
108
109
    /**
110
     * @var SecurityServiceInterface
111
     */
112
    private $securityService;
113
114
    /**
115
     * @param SharedStorageInterface $sharedStorage
116
     * @param SecurityStepInterface $checkoutSecurityStep
117
     * @param AddressingStepInterface $checkoutAddressingStep
118
     * @param AddressingPageInterface $addressingPage
119
     * @param ShippingStepInterface $checkoutShippingStep
120
     * @param ShippingPageInterface $shippingPage
121
     * @param PaymentStepInterface $checkoutPaymentStep
122
     * @param PaymentPageInterface $paymentPage
123
     * @param SummaryPageInterface $summaryPage
124
     * @param FinalizeStepInterface $checkoutFinalizeStep
125
     * @param ThankYouPageInterface $checkoutThankYouPage
126
     * @param OrderPaymentsPageInterface $orderPaymentsPage
127
     * @param OrderRepositoryInterface $orderRepository
128
     * @param SecurityServiceInterface $securityService
129
     */
130
    public function __construct(
131
        SharedStorageInterface $sharedStorage,
132
        SecurityStepInterface $checkoutSecurityStep,
133
        AddressingStepInterface $checkoutAddressingStep,
134
        AddressingPageInterface $addressingPage,
135
        ShippingStepInterface $checkoutShippingStep,
136
        ShippingPageInterface $shippingPage,
137
        PaymentStepInterface $checkoutPaymentStep,
138
        PaymentPageInterface $paymentPage,
139
        SummaryPageInterface $summaryPage,
140
        FinalizeStepInterface $checkoutFinalizeStep,
141
        ThankYouPageInterface $checkoutThankYouPage,
142
        OrderPaymentsPageInterface $orderPaymentsPage,
143
        OrderRepositoryInterface $orderRepository,
144
        SecurityServiceInterface $securityService
145
    ) {
146
        $this->sharedStorage = $sharedStorage;
147
        $this->checkoutSecurityStep = $checkoutSecurityStep;
148
        $this->checkoutAddressingStep = $checkoutAddressingStep;
149
        $this->addressingPage = $addressingPage;
150
        $this->checkoutShippingStep = $checkoutShippingStep;
151
        $this->shippingPage = $shippingPage;
152
        $this->checkoutPaymentStep = $checkoutPaymentStep;
153
        $this->paymentPage = $paymentPage;
154
        $this->summaryPage = $summaryPage;
155
        $this->checkoutFinalizeStep = $checkoutFinalizeStep;
156
        $this->checkoutThankYouPage = $checkoutThankYouPage;
157
        $this->orderPaymentsPage = $orderPaymentsPage;
158
        $this->orderRepository = $orderRepository;
159
        $this->securityService = $securityService;
160
    }
161
162
    /**
163
     * @Given /^I proceed without selecting shipping address$/
164
     */
165
    public function iProceedWithoutSelectingShippingAddress()
166
    {
167
        $this->checkoutAddressingStep->open();
168
        $this->checkoutAddressingStep->continueCheckout();
169
    }
170
171
    /**
172
     * @Given I am at the checkout addressing step
173
     */
174
    public function iAmAtTheCheckoutAddressingStep()
175
    {
176
        $this->addressingPage->open();
177
    }
178
179
    /**
180
     * @Given /^(this user) bought this product$/
181
     */
182
    public function thisUserBought(UserInterface $user)
183
    {
184
        $this->securityService->performActionAs($user, function () {
185
            $this->iProceedSelectingOfflinePaymentMethod();
186
            $this->iConfirmMyOrder();
187
        });
188
    }
189
190
    /**
191
     * @When /^I specify the shipping (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
192
     * @When /^I (do not specify any shipping address) information$/
193
     */
194
    public function iSpecifyTheShippingAddressAs(AddressInterface $address)
195
    {
196
        $key = sprintf(
197
            'shipping_address_%s_%s',
198
            strtolower($address->getFirstName()),
199
            strtolower($address->getLastName())
200
        );
201
        $this->sharedStorage->set($key, $address);
202
203
        $this->addressingPage->specifyShippingAddress($address);
204
    }
205
206
    /**
207
     * @When /^I specify the billing (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
208
     * @When /^I (do not specify any billing address) information$/
209
     */
210
    public function iSpecifyTheBillingAddressAs(AddressInterface $address)
211
    {
212
        $this->iChooseTheDifferentBillingAddress();
213
        $key = sprintf(
214
            'billing_address_%s_%s',
215
            strtolower($address->getFirstName()),
216
            strtolower($address->getLastName())
217
        );
218
        $this->sharedStorage->set($key, $address);
219
220
        $this->addressingPage->specifyBillingAddress($address);
221
    }
222
223
    /**
224
     * @When /^I specified the shipping (address as "([^"]+)", "([^"]+)", "([^"]+)", "([^"]+)" for "([^"]+)")$/
225
     */
226
    public function iSpecifiedTheShippingAddress(AddressInterface $address)
227
    {
228
        $this->addressingPage->open();
229
        $this->iSpecifyTheShippingAddressAs($address);
230
231
        $key = sprintf('billing_address_%s_%s', strtolower($address->getFirstName()), strtolower($address->getLastName()));
232
        $this->sharedStorage->set($key, $address);
233
234
        $this->iCompleteTheAddressingStep();
235
    }
236
237
    /**
238
     * @When I choose the different billing address
239
     */
240
    public function iChooseTheDifferentBillingAddress()
241
    {
242
        $this->addressingPage->chooseDifferentBillingAddress();
243
    }
244
245
    /**
246
     * @When I specify the email as :email
247
     * @When I do not specify the email
248
     */
249
    public function iSpecifyTheEmail($email = null)
250
    {
251
        $this->addressingPage->specifyEmail($email);
252
    }
253
254
    /**
255
     * @When I select :shippingMethod shipping method
256
     */
257
    public function iSelectShippingMethod($shippingMethod)
258
    {
259
        $this->shippingPage->selectShippingMethod($shippingMethod);
260
    }
261
262
    /**
263
     * @Then I should not be able to select :shippingMethod shipping method
264
     */
265
    public function iShouldNotBeAbleToSelectShippingMethod($shippingMethod)
266
    {
267
        Assert::false(
268
            $this->shippingPage->hasShippingMethod($shippingMethod),
269
            sprintf('Shipping method "%s" should not be available but it does.', $shippingMethod)
270
        );
271
    }
272
273
    /**
274
     * @When I complete the addressing step
275
     * @When I try to complete the addressing step
276
     */
277
    public function iCompleteTheAddressingStep()
278
    {
279
        $this->addressingPage->nextStep();
280
    }
281
282
    /**
283
     * @When I complete the shipping step
284
     */
285
    public function iCompleteTheShippingStep()
286
    {
287
        $this->shippingPage->nextStep();
288
    }
289
290
    /**
291
     * @When /^I proceed selecting "([^"]*)" as shipping country$/
292
     */
293
    public function iProceedSelectingShippingCountry($shippingCountry)
294
    {
295
        $this->checkoutAddressingStep->open();
296
        $this->checkoutAddressingStep->fillAddressingDetails([
297
            'firstName' => 'John',
298
            'lastName' => 'Doe',
299
            'country' => $shippingCountry ?: 'France',
300
            'street' => '0635 Myron Hollow Apt. 711',
301
            'city' => 'North Bridget',
302
            'postcode' => '93-554',
303
            'phoneNumber' => '321123456',
304
        ]);
305
        $this->checkoutAddressingStep->continueCheckout();
306
    }
307
308
    /**
309
     * @When /^I proceed selecting "([^"]*)" as shipping country with "([^"]*)" method$/
310
     */
311
    public function iProceedSelectingShippingCountryAndShippingMethod($shippingCountry, $shippingMethodName)
312
    {
313
        $this->iProceedSelectingShippingCountry($shippingCountry);
314
315
        $this->checkoutShippingStep->selectShippingMethod($shippingMethodName ?: 'Free');
316
        $this->checkoutShippingStep->continueCheckout();
317
    }
318
319
    /**
320
     * @When /^I proceed selecting "([^"]+)" shipping method$/
321
     * @Given /^I chose "([^"]*)" shipping method$/
322
     */
323
    public function iProceedSelectingShippingMethod($shippingMethodName)
324
    {
325
        $this->iProceedSelectingShippingCountryAndShippingMethod(null, $shippingMethodName);
326
    }
327
328
    /**
329
     * @When /^I choose "([^"]*)" payment method$/
330
     */
331
    public function iChoosePaymentMethod($paymentMethodName)
332
    {
333
        $this->checkoutPaymentStep->verify([]);
334
        $this->checkoutPaymentStep->selectPaymentMethod($paymentMethodName ?: 'Offline');
335
        $this->checkoutPaymentStep->continueCheckout();
336
    }
337
338
    /**
339
     * @When /^I proceed selecting "([^"]*)" as shipping country with "([^"]*)" payment method$/
340
     */
341
    public function iProceedSelectingShippingCountryAndPaymentMethod($shippingCountry, $paymentMethodName)
342
    {
343
        $this->iProceedSelectingShippingCountryAndShippingMethod($shippingCountry, null);
344
345
        $this->iChoosePaymentMethod($paymentMethodName);
346
    }
347
348
    /**
349
     * @When I proceed selecting :paymentMethodName payment method
350
     */
351
    public function iProceedSelectingOfflinePaymentMethod($paymentMethodName = 'Offline')
352
    {
353
        $this->iProceedSelectingShippingCountryAndPaymentMethod(null, $paymentMethodName);
354
    }
355
356
    /**
357
     * @When /^I change shipping method to "([^"]*)"$/
358
     */
359
    public function iChangeShippingMethod($shippingMethodName)
360
    {
361
        $this->checkoutShippingStep->open();
362
        $this->checkoutShippingStep->selectShippingMethod($shippingMethodName);
363
        $this->checkoutShippingStep->continueCheckout();
364
    }
365
366
    /**
367
     * @Given /^I proceed logging as "([^"]*)" with "([^"]*)" password$/
368
     */
369
    public function iProceedLoggingAs($login, $password)
370
    {
371
        $this->checkoutSecurityStep->open();
372
        $this->checkoutSecurityStep->logInAsExistingUser($login, $password);
373
374
        $this->checkoutAddressingStep->continueCheckout();
375
    }
376
377
    /**
378
     * @When /^I proceed as guest "([^"]*)" with "([^"]*)" as shipping country$/
379
     */
380
    public function iProceedLoggingAsGuestWithAsShippingCountry($email, $shippingCountry)
381
    {
382
        $this->checkoutSecurityStep->open();
383
        $this->checkoutSecurityStep->proceedAsGuest($email);
384
385
        $this->iProceedSelectingShippingCountry($shippingCountry);
386
    }
387
388
    /**
389
     * @When I confirm my order
390
     */
391
    public function iConfirmMyOrder()
392
    {
393
        $this->checkoutFinalizeStep->confirmOrder();
394
    }
395
396
    /**
397
     * @When I specify the password as :password
398
     */
399
    public function iSpecifyThePasswordAs($password)
400
    {
401
        $this->addressingPage->specifyPassword($password);
402
    }
403
404
    /**
405
     * @When I sign in
406
     */
407
    public function iSignIn()
408
    {
409
        $this->addressingPage->signIn();
410
    }
411
412
    /**
413
     * @Then I should see the thank you page
414
     */
415
    public function iShouldSeeTheThankYouPage()
416
    {
417
        /** @var UserInterface $user */
418
        $user = $this->sharedStorage->get('user');
419
        $customer = $user->getCustomer();
420
421
        expect($this->checkoutThankYouPage->hasThankYouMessageFor($customer->getFullName()))->toBe(true);
422
    }
423
424
    /**
425
     * @Then I should be redirected back to the thank you page
426
     */
427
    public function iShouldBeRedirectedBackToTheThankYouPage()
428
    {
429
        $this->checkoutThankYouPage->waitForResponse(5);
430
431
        expect($this->checkoutThankYouPage->isOpen())->toBe(true);
432
    }
433
434
    /**
435
     * @Then I should be redirected back to the order payment page
436
     */
437
    public function iShouldBeRedirectedBackToTheOrderPaymentPage()
438
    {
439
        $this->orderPaymentsPage->waitForResponse(5, ['number' => $this->getLastOrder()->getNumber()]);
440
441
        expect($this->orderPaymentsPage->isOpen(['number' => $this->getLastOrder()->getNumber()]))->toBe(true);
442
    }
443
444
    /**
445
     * @Then I should be on the checkout shipping step
446
     */
447
    public function iShouldBeOnTheCheckoutShippingStep()
448
    {
449
        Assert::true(
450
            $this->shippingPage->isOpen(),
451
            'Checkout shipping page should be opened, but it is not.'
452
        );
453
    }
454
455
    /**
456
     * @Then I should be on the checkout summary step
457
     */
458
    public function iShouldBeOnTheCheckoutSummaryStep()
459
    {
460
        Assert::true(
461
            $this->summaryPage->isOpen(),
462
            'Checkout summary page should be opened, but it is not.'
463
        );
464
    }
465
466
    /**
467
     * @Then I should see two cancelled payments and new one ready to be paid
468
     */
469
    public function iShouldSeeTwoCancelledPaymentsAndNewOneReadyToBePaid()
470
    {
471
        expect($this->orderPaymentsPage->countPaymentWithSpecificState(PaymentInterface::STATE_CANCELLED))->toBe(2);
472
        expect($this->orderPaymentsPage->countPaymentWithSpecificState(PaymentInterface::STATE_NEW))->toBe(1);
473
    }
474
475
    /**
476
     * @Then /^I should(?:| also) be notified that the "([^"]+)" and the "([^"]+)" in (shipping|billing) details are required$/
477
     */
478
    public function iShouldBeNotifiedThatTheAndTheInShippingDetailsAreRequired($firstElement, $secondElement, $type)
479
    {
480
        $this->assertElementValidationMessage($type, $firstElement, sprintf('Please enter %s.', $firstElement));
481
        $this->assertElementValidationMessage($type, $secondElement, sprintf('Please enter %s.', $secondElement));
482
    }
483
484
    /**
485
     * @Then I should be informed that my order cannot be shipped to this address
486
     */
487
    public function iShouldBeInformedThatMyOrderCannotBeShippedToThisAddress()
488
    {
489
        Assert::true(
490
            $this->shippingPage->hasNoShippingMethodsMessage(),
491
            'Shipping page should have no shipping methods message but it does not.'
492
        );
493
    }
494
495
    /**
496
     * @Then I should be able to log in
497
     */
498
    public function iShouldBeAbleToLogIn()
499
    {
500
        Assert::true(
501
            $this->addressingPage->canSignIn(),
502
            'I should be able to login, but I am not.'
503
        );
504
    }
505
506
    /**
507
     * @Then the login form should no longer be accessible
508
     */
509
    public function theLoginFormShouldNoLongerBeAccessible()
510
    {
511
        Assert::false(
512
            $this->addressingPage->canSignIn(),
513
            'I should not be able to login, but I am.'
514
        );
515
    }
516
517
    /**
518
     * @Then I should be notified about bad credentials
519
     */
520
    public function iShouldBeNotifiedAboutBadCredentials()
521
    {
522
        Assert::true(
523
            $this->addressingPage->checkInvalidCredentialsValidation(),
524
            'I should see validation error, but I do not.'
525
        );
526
    }
527
528
    /**
529
     * @Then my order's shipping address should be to :fullName
530
     */
531
    public function iShouldSeeThisShippingAddressAsShippingAddress($fullName)
532
    {
533
        $address = $this->sharedStorage->get('shipping_address_'.StringInflector::nameToLowercaseCode($fullName));
534
        Assert::true(
535
            $this->summaryPage->hasShippingAddress($address),
536
            'Shipping address is improper.'
537
        );
538
    }
539
540
    /**
541
     * @Then my order's billing address should be to :fullName
542
     */
543
    public function iShouldSeeThisBillingAddressAsBillingAddress($fullName)
544
    {
545
        $address = $this->sharedStorage->get('billing_address_'.StringInflector::nameToLowercaseCode($fullName));
546
        Assert::true(
547
            $this->summaryPage->hasBillingAddress($address),
548
            'Billing address is improper.'
549
        );
550
    }
551
552
    /**
553
     * @Then address to :fullName should be used for both shipping and billing of my order`
554
     */
555
    public function iShouldSeeThisShippingAddressAsShippingAndBillingAddress($fullName)
556
    {
557
        $this->iShouldSeeThisShippingAddressAsShippingAddress($fullName);
558
        $this->iShouldSeeThisBillingAddressAsBillingAddress($fullName);
559
    }
560
561
    /**
562
     * @Given I am at the checkout payment step
563
     */
564
    public function iAmAtTheCheckoutPaymentStep()
565
    {
566
        $this->paymentPage->open();
567
    }
568
569
    /**
570
     * @When I complete the payment step
571
     */
572
    public function iCompleteThePaymentStep()
573
    {
574
        $this->paymentPage->nextStep();
575
    }
576
577
    /**
578
     * @When I select :paymentMethodName payment method
579
     */
580
    public function iSelectPaymentMethod($paymentMethodName)
581
    {
582
        $this->paymentPage->selectPaymentMethod($paymentMethodName);
583
    }
584
585
    /**
586
     * @Then I should not be able to select :paymentMethodName payment method
587
     */
588
    public function iShouldNotBeAbleToSelectPaymentMethod($paymentMethodName)
589
    {
590
        Assert::false(
591
            $this->paymentPage->hasPaymentMethod($paymentMethodName),
592
            sprintf('Payment method "%s" should not be available but it does.', $paymentMethodName)
593
        );
594
    }
595
596
    /**
597
     * @When I proceed order with :shippingMethod shipping method and :paymentMethod payment
598
     */
599
    public function iProceedOrderWithShippingMethodAndPayment($shippingMethod, $paymentMethod)
600
    {
601
        $this->iSelectShippingMethod($shippingMethod);
602
        $this->iCompleteTheShippingStep();
603
        $this->iSelectPaymentMethod($paymentMethod);
604
        $this->iCompleteThePaymentStep();
605
    }
606
607
    /**
608
     * @Given I should have :quantity :productName products in the cart
609
     */
610
    public function iShouldHaveProductsInTheCart($quantity, $productName)
611
    {
612
        Assert::true(
613
            $this->summaryPage->hasItemWithProductAndQuantity($productName, $quantity),
614
            sprintf('There is no "%s" with quantity %s on order summary page, but it should.', $productName, $quantity)
615
        );
616
    }
617
618
    /**
619
     * @Given I should see the shipping total with price :price
620
     */
621
    public function iShouldSeeTheShippingTotalWithPrice($price)
622
    {
623
        Assert::true(
624
            $this->summaryPage->hasShippingTotal($price),
625
            sprintf('The shipping total should be %s, but it is not.',$price)
626
        );
627
    }
628
629
    /**
630
     * @Then /^the ("[^"]+" product) should have unit price discounted by ("\$\d+")$/
631
     */
632
    public function theShouldHaveUnitPriceDiscountedFor(ProductInterface $product, $amount)
633
    {
634
        Assert::true(
635
            $this->summaryPage->hasProductDiscountedUnitPriceBy($product, $amount),
636
            sprintf('Product %s should have discounted price by %s, but it does not have.', $product->getName(), $amount)
637
        );
638
    }
639
640
    /**
641
     * @Then /^my order total should be ("\$\d+")$/
642
     */
643
    public function myOrderTotalShouldBe($total)
644
    {
645
        Assert::true(
646
            $this->summaryPage->hasOrderTotal($total),
647
            sprintf('Order total should have %s total, but it does not have.', $total)
648
        );
649
    }
650
651
    /**
652
     * @Given I should see promotion total :promotionTotal
653
     */
654
    public function iShouldSeeDiscountTotal($promotionTotal)
655
    {
656
        Assert::true(
657
            $this->summaryPage->hasPromotionTotal($promotionTotal),
658
            sprintf('The total discount should be %s, but it does not.', $promotionTotal)
659
        );
660
    }
661
662
    /**
663
     * @Given I should see promotion :promotionName
664
     */
665
    public function iShouldSeePromotion($promotionName)
666
    {
667
        Assert::true(
668
            $this->summaryPage->hasPromotion($promotionName),
669
            sprintf('The promotion %s should appear on the page, but it does not.', $promotionName)
670
        );
671
    }
672
673
    /**
674
     * @Given my tax total should be :taxTotal
675
     */
676
    public function myTaxTotalShouldBe($taxTotal)
677
    {
678
        Assert::true(
679
            $this->summaryPage->hasTaxTotal($taxTotal),
680
            sprintf('The tax total should be %s, but it does not.', $taxTotal)
681
        );
682
    }
683
684
    /**
685
     * @Then I should see :shippingMethod shipping method
686
     */
687
    public function iShouldSeeThisShippingMethod(ShippingMethodInterface $shippingMethod)
688
    {
689
        Assert::true(
690
            $this->summaryPage->hasShippingMethod($shippingMethod),
691
            sprintf('I should see %s shipping method, but I do not.', $shippingMethod->getName())
692
        );
693
    }
694
695
    /**
696
     * @Then I should see :paymentMethod payment method
697
     */
698
    public function iShouldSeeThisPaymentMethod(PaymentMethodInterface $paymentMethod)
699
    {
700
        Assert::true(
701
            $this->summaryPage->hasPaymentMethod($paymentMethod),
702
            sprintf('I should see %s payment method, but i do not.', $paymentMethod->getName())
703
        );
704
    }
705
706
    /**
707
     * @param string $type
708
     * @param string $element
709
     * @param string $expectedMessage
710
     *
711
     * @throws \InvalidArgumentException
712
     */
713
    private function assertElementValidationMessage($type, $element, $expectedMessage)
714
    {
715
        $element = sprintf('%s_%s', $type, implode('_', explode(' ', $element)));
716
        Assert::true(
717
            $this->addressingPage->checkValidationMessageFor($element, $expectedMessage),
718
            sprintf('The %s should be required.', $element)
719
        );
720
    }
721
722
    /**
723
     * @return OrderInterface
724
     *
725
     * @throws \RuntimeException
726
     */
727
    private function getLastOrder()
728
    {
729
        $customer = $this->sharedStorage->get('user')->getCustomer();
730
        $orders = $this->orderRepository->findByCustomer($customer);
0 ignored issues
show
Bug introduced by
The method findByCustomer() does not exist on Sylius\Component\Order\R...rderRepositoryInterface. Did you maybe mean findBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
731
        $lastOrder = end($orders);
732
733
        if (false === $lastOrder) {
734
            throw new \RuntimeException(sprintf('There is no last order for %s', $customer->getFullName()));
735
        }
736
737
        return $lastOrder;
738
    }
739
}
740