Completed
Push — master ( b716f1...2f9340 )
by Kamil
18:43
created

CheckoutContext::iAddProductToTheCart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
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\Checkout\CheckoutAddressingStep;
16
use Sylius\Behat\Page\Checkout\CheckoutFinalizeStep;
17
use Sylius\Behat\Page\Checkout\CheckoutPaymentStep;
18
use Sylius\Behat\Page\Checkout\CheckoutShippingStep;
19
use Sylius\Behat\Page\Checkout\CheckoutThankYouPage;
20
use Sylius\Component\Core\Model\UserInterface;
21
use Sylius\Component\Core\Test\Services\SharedStorageInterface;
22
23
/**
24
 * @author Arkadiusz Krakowiak <[email protected]>
25
 */
26
final class CheckoutContext implements Context
27
{
28
    /**
29
     * @var SharedStorageInterface
30
     */
31
    private $sharedStorage;
32
33
    /**
34
     * @var CheckoutAddressingStep
35
     */
36
    private $checkoutAddressingStep;
37
38
    /**
39
     * @var CheckoutShippingStep
40
     */
41
    private $checkoutShippingStep;
42
43
    /**
44
     * @var CheckoutPaymentStep
45
     */
46
    private $checkoutPaymentStep;
47
48
    /**
49
     * @var CheckoutFinalizeStep
50
     */
51
    private $checkoutFinalizeStep;
52
53
    /**
54
     * @var CheckoutThankYouPage
55
     */
56
    private $checkoutThankYouPage;
57
58
    /**
59
     * @param SharedStorageInterface $sharedStorage
60
     * @param CheckoutAddressingStep $checkoutAddressingStep
61
     * @param CheckoutShippingStep $checkoutShippingStep
62
     * @param CheckoutPaymentStep $checkoutPaymentStep
63
     * @param CheckoutFinalizeStep $checkoutFinalizeStep
64
     * @param CheckoutThankYouPage $checkoutThankYouPage
65
     */
66
    public function __construct(
67
        SharedStorageInterface $sharedStorage,
68
        CheckoutAddressingStep $checkoutAddressingStep,
69
        CheckoutShippingStep $checkoutShippingStep,
70
        CheckoutPaymentStep $checkoutPaymentStep,
71
        CheckoutFinalizeStep $checkoutFinalizeStep,
72
        CheckoutThankYouPage $checkoutThankYouPage
73
    ) {
74
        $this->sharedStorage = $sharedStorage;
75
        $this->checkoutAddressingStep = $checkoutAddressingStep;
76
        $this->checkoutShippingStep = $checkoutShippingStep;
77
        $this->checkoutPaymentStep = $checkoutPaymentStep;
78
        $this->checkoutFinalizeStep = $checkoutFinalizeStep;
79
        $this->checkoutThankYouPage = $checkoutThankYouPage;
80
    }
81
82
    /**
83
     * @When I proceed selecting :paymentMethodName payment method
84
     */
85
    public function iProceedSelectingOfflinePaymentMethod($paymentMethodName)
86
    {
87
        $this->checkoutAddressingStep->open();
88
        $this->checkoutAddressingStep->fillAddressingDetails([
89
            'firstName' => 'John',
90
            'lastName' => 'Doe',
91
            'country' => 'France',
92
            'street' => '0635 Myron Hollow Apt. 711',
93
            'city' => 'North Bridget',
94
            'postcode' => '93-554',
95
            'phoneNumber' => '321123456',
96
        ]);
97
        $this->checkoutAddressingStep->continueCheckout();
98
99
        $this->checkoutShippingStep->selectShippingMethod('Free');
100
        $this->checkoutShippingStep->continueCheckout();
101
102
        $this->checkoutPaymentStep->selectPaymentMethod($paymentMethodName);
103
        $this->checkoutPaymentStep->continueCheckout();
104
    }
105
106
    /**
107
     * @When /^I proceed selecting "([^"]+)" shipping method$/
108
     * @Given /^I chose "([^"]*)" shipping method$/
109
     */
110
    public function iProceedSelectingShippingMethod($shippingMethodName)
111
    {
112
        $this->checkoutAddressingStep->open();
113
        $this->checkoutAddressingStep->fillAddressingDetails([
114
            'firstName' => 'John',
115
            'lastName' => 'Doe',
116
            'country' => 'France',
117
            'street' => '0635 Myron Hollow Apt. 711',
118
            'city' => 'North Bridget',
119
            'postcode' => '93-554',
120
            'phoneNumber' => '321123456',
121
        ]);
122
        $this->checkoutAddressingStep->continueCheckout();
123
124
        $this->checkoutShippingStep->selectShippingMethod($shippingMethodName);
125
        $this->checkoutShippingStep->continueCheckout();
126
    }
127
128
    /**
129
     * @When /^I change shipping method to "([^"]*)"$/
130
     */
131
    public function iChangeShippingMethod($shippingMethodName)
132
    {
133
        $this->checkoutShippingStep->open();
134
        $this->checkoutShippingStep->selectShippingMethod($shippingMethodName);
135
        $this->checkoutShippingStep->continueCheckout();
136
    }
137
138
    /**
139
     * @When I confirm my order
140
     */
141
    public function iConfirmMyOrder()
142
    {
143
        $this->checkoutFinalizeStep->confirmOrder();
144
    }
145
146
    /**
147
     * @Then I should see the thank you page
148
     */
149
    public function iShouldSeeTheThankYouPage()
150
    {
151
        /** @var UserInterface $user */
152
        $user = $this->sharedStorage->getCurrentResource('user');
153
        $customer = $user->getCustomer();
154
155
        expect($this->checkoutThankYouPage->hasThankYouMessageFor($customer->getFullName()))->toBe(true);
156
    }
157
}
158