CheckoutApiTester   A
last analyzed

Complexity

Total Complexity 35

Size/Duplication

Total Lines 475
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 35
eloc 205
c 2
b 0
f 0
dl 0
loc 475
rs 9.6

32 Methods

Rating   Name   Duplication   Size   Complexity  
A assertCustomerShippingAddressInOrderShipments() 0 13 1
A havePaymentMethodWithStore() 0 21 1
A authorizeCustomerToGlue() 0 4 1
A haveProductWithStock() 0 22 1
A createCustomerTransfer() 0 3 1
A haveEmptyPersistentQuote() 0 5 1
A assertCompanyBusinessUnitBillingAddressInOrders() 0 13 1
A assertCompanyBusinessUnitShippingAddressInOrderShipments() 0 13 1
A getQuoteItemOverrideData() 0 11 1
A assertCustomerBillingAddressInOrders() 0 12 1
A haveCustomerWithPersistentAddress() 0 5 1
A haveAddressForCustomer() 0 12 1
A getSplitShipmentRequestPayloadWithCompanyBusinessUnitAddress() 0 11 1
A havePersistentQuoteWithItemsAndItemLevelShipment() 0 14 1
A buildCheckoutDataUrl() 0 6 1
A getAddressRequestPayload() 0 16 1
A getCartFacade() 0 3 1
A getCustomerRequestPayload() 0 7 1
A assertCheckoutResponseResourceHasCorrectData() 0 21 1
A assertCheckoutDataResponseResourceHasCorrectData() 0 11 1
A assertShipmentExpensesHaveCorrectPrice() 0 19 1
A mapProductConcreteTransfersToQuoteTransferItemsWithItemLevelShipment() 0 22 2
A getSplitShipmentRequestPayload() 0 11 2
A getOverrideShipmentDataFromOverrideItemData() 0 3 1
A getCustomerFacade() 0 5 1
A getShipmentRequestPayload() 0 4 1
A getStoreFacade() 0 5 1
A buildCheckoutUrl() 0 6 1
A getProductConcreteTransferFromOverrideItemData() 0 3 1
A getQuoteItemQuantityFromOverrideItemData() 0 3 1
A getPaymentRequestPayload() 0 8 1
A formatQueryInclude() 0 7 2
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace PyzTest\Glue\Checkout;
11
12
use DateTime;
13
use Generated\Shared\DataBuilder\AddressBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\AddressBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Generated\Shared\DataBuilder\CustomerBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\CustomerBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Generated\Shared\DataBuilder\ItemBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\ItemBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Generated\Shared\DataBuilder\ShipmentBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\ShipmentBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Generated\Shared\DataBuilder\StoreRelationBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\StoreRelationBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use Generated\Shared\Transfer\AddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\AddressTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use Generated\Shared\Transfer\CompanyUnitAddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...panyUnitAddressTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
use Generated\Shared\Transfer\CustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\CustomerTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use Generated\Shared\Transfer\ItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ItemTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use Generated\Shared\Transfer\MoneyValueTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\MoneyValueTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use Generated\Shared\Transfer\PaymentMethodTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PaymentMethodTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use Generated\Shared\Transfer\PriceProductTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\PriceProductTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Generated\Shared\Transfer\ProductConcreteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ProductConcreteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
use Generated\Shared\Transfer\QuoteTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\QuoteTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use Generated\Shared\Transfer\RestAddressTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestAddressTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
use Generated\Shared\Transfer\RestCheckoutDataTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestCheckoutDataTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use Generated\Shared\Transfer\RestCheckoutResponseTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...heckoutResponseTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
30
use Generated\Shared\Transfer\RestCustomerTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestCustomerTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
31
use Generated\Shared\Transfer\RestOrderDetailsAttributesTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...tailsAttributesTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
use Generated\Shared\Transfer\RestPaymentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestPaymentTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
use Generated\Shared\Transfer\RestShipmentsTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestShipmentsTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
use Generated\Shared\Transfer\RestShipmentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\RestShipmentTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
use Generated\Shared\Transfer\ShipmentMethodTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ShipmentMethodTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
use Generated\Shared\Transfer\ShipmentTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\ShipmentTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
use Generated\Shared\Transfer\StockProductTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StockProductTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
use Generated\Shared\Transfer\StoreRelationTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StoreRelationTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
use Generated\Shared\Transfer\StoreTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StoreTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
use Generated\Shared\Transfer\TotalsTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\TotalsTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
41
use Spryker\Glue\CheckoutRestApi\CheckoutRestApiConfig;
42
use Spryker\Glue\GlueApplication\Rest\RequestConstantsInterface;
43
use Spryker\Glue\OrdersRestApi\OrdersRestApiConfig;
44
use Spryker\Shared\Price\PriceConfig;
45
use Spryker\Shared\Shipment\ShipmentConfig;
46
use Spryker\Zed\Cart\Business\CartFacadeInterface;
47
use Spryker\Zed\Customer\Business\CustomerFacadeInterface;
48
use Spryker\Zed\Store\Business\StoreFacadeInterface;
49
use SprykerTest\Glue\Testify\Tester\ApiEndToEndTester;
50
51
/**
52
 * Inherited Methods
53
 *
54
 * @method void wantToTest($text)
55
 * @method void wantTo($text)
56
 * @method void execute($callable)
57
 * @method void expectTo($prediction)
58
 * @method void expect($prediction)
59
 * @method void amGoingTo($argumentation)
60
 * @method void am($role)
61
 * @method void lookForwardTo($achieveValue)
62
 * @method void comment($description)
63
 * @method \Codeception\Lib\Friend haveFriend($name, $actorClass = null)
64
 *
65
 * @SuppressWarnings(\PyzTest\Glue\Checkout\PHPMD)
66
 */
67
class CheckoutApiTester extends ApiEndToEndTester
68
{
69
    use _generated\CheckoutApiTesterActions;
0 ignored issues
show
Bug introduced by
The type PyzTest\Glue\Checkout\_g...heckoutApiTesterActions was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
70
71
    protected const REQUEST_PARAM_PAYMENT_METHOD_NAME_INVOICE = 'Invoice';
72
73
    protected const REQUEST_PARAM_PAYMENT_PROVIDER_NAME_DUMMY_PAYMENT = 'DummyPayment';
74
75
    protected const QUOTE_ITEM_OVERRIDE_DATA_PRODUCT = 'product';
76
77
    protected const QUOTE_ITEM_OVERRIDE_DATA_SHIPMENT = 'shipment';
78
79
    protected const QUOTE_ITEM_OVERRIDE_DATA_QUANTITY = 'quantity';
80
81
    protected const DEFAULT_QUOTE_ITEM_QUANTITY = 10;
82
83
    public function assertCheckoutResponseResourceHasCorrectData(): void
84
    {
85
        $this->amSure('The returned resource id should be null')
86
            ->whenI()
87
            ->seeSingleResourceIdEqualTo('');
0 ignored issues
show
Bug introduced by
It seems like seeSingleResourceIdEqualTo() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

87
            ->/** @scrutinizer ignore-call */ seeSingleResourceIdEqualTo('');
Loading history...
88
89
        $attributes = $this->getDataFromResponseByJsonPath('$.data.attributes');
90
91
        $this->assertNotEmpty(
92
            $attributes[RestCheckoutResponseTransfer::ORDER_REFERENCE],
93
            'The returned resource attributes order reference should not be empty',
94
        );
95
        $this->assertArrayHasKey(
96
            RestCheckoutResponseTransfer::IS_EXTERNAL_REDIRECT,
97
            $attributes,
98
            'The returned resource attributes should have an external redirect key',
99
        );
100
        $this->assertArrayHasKey(
101
            RestCheckoutResponseTransfer::REDIRECT_URL,
102
            $attributes,
103
            'The returned resource attributes should have a redirect URL key',
104
        );
105
    }
106
107
    public function assertCheckoutDataResponseResourceHasCorrectData(): void
108
    {
109
        $this->amSure('The returned resource id should be null')
110
            ->whenI()
111
            ->seeSingleResourceIdEqualTo('');
112
113
        $attributes = $this->getDataFromResponseByJsonPath('$.data.attributes');
114
115
        $this->assertEmpty(
116
            $attributes[RestCheckoutDataTransfer::ADDRESSES],
117
            'The returned resource attributes addresses should be an empty array',
118
        );
119
    }
120
121
    public function assertShipmentExpensesHaveCorrectPrice(int $price): void
122
    {
123
        $this->amSure('The returned resource should have included orders resource')
124
            ->whenI()
125
            ->seeIncludesContainResourceOfType(OrdersRestApiConfig::RESOURCE_ORDERS);
0 ignored issues
show
Bug introduced by
It seems like seeIncludesContainResourceOfType() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

125
            ->/** @scrutinizer ignore-call */ seeIncludesContainResourceOfType(OrdersRestApiConfig::RESOURCE_ORDERS);
Loading history...
126
127
        $ordersAttributes = $this->getDataFromResponseByJsonPath(
128
            sprintf('$.included[?(@.type == %1$s)].attributes', json_encode(OrdersRestApiConfig::RESOURCE_ORDERS)),
129
        );
130
131
        $this->assertNotNull($ordersAttributes);
132
        $this->assertCount(1, $ordersAttributes);
133
        $restOrdersDetailsAttributesTransfer = (new RestOrderDetailsAttributesTransfer())->fromArray($ordersAttributes[0], true);
134
        $this->assertCount(1, $restOrdersDetailsAttributesTransfer->getExpenses());
135
136
        /** @var \Generated\Shared\Transfer\RestOrderExpensesAttributesTransfer $restOrderExpensesAttributesTransfer */
137
        $restOrderExpensesAttributesTransfer = $restOrdersDetailsAttributesTransfer->getExpenses()->getIterator()->current();
138
        $this->assertSame(ShipmentConfig::SHIPMENT_EXPENSE_TYPE, $restOrderExpensesAttributesTransfer->getType());
139
        $this->assertSame($price, $restOrderExpensesAttributesTransfer->getSumPrice());
140
    }
141
142
    /**
143
     * @param array<string> $includes
144
     */
145
    public function buildCheckoutUrl(array $includes = []): string
146
    {
147
        return $this->formatFullUrl(
148
            '{resourceCheckout}' . $this->formatQueryInclude($includes),
149
            [
150
                'resourceCheckout' => CheckoutRestApiConfig::RESOURCE_CHECKOUT,
151
            ],
152
        );
153
    }
154
155
    /**
156
     * @param array<string> $includes
157
     */
158
    public function buildCheckoutDataUrl(array $includes = []): string
159
    {
160
        return $this->formatFullUrl(
161
            '{resourceCheckoutData}' . $this->formatQueryInclude($includes),
162
            [
163
                'resourceCheckoutData' => CheckoutRestApiConfig::RESOURCE_CHECKOUT_DATA,
164
            ],
165
        );
166
    }
167
168
    public function getStoreFacade(): StoreFacadeInterface
169
    {
170
        return $this->getLocator()
171
            ->store()
172
            ->facade();
173
    }
174
175
    public function getCustomerFacade(): CustomerFacadeInterface
176
    {
177
        return $this->getLocator()
178
            ->customer()
179
            ->facade();
180
    }
181
182
    public function getCartFacade(): CartFacadeInterface
183
    {
184
        return $this->getLocator()->cart()->facade();
185
    }
186
187
    /**
188
     * @param \Generated\Shared\Transfer\AddressTransfer $addressTransfer
189
     *
190
     * @return array<string, mixed>
191
     */
192
    public function getAddressRequestPayload(AddressTransfer $addressTransfer): array
193
    {
194
        return [
195
            RestAddressTransfer::SALUTATION => $addressTransfer->getSalutation(),
196
            RestAddressTransfer::FIRST_NAME => $addressTransfer->getFirstName(),
197
            RestAddressTransfer::LAST_NAME => $addressTransfer->getLastName(),
198
            RestAddressTransfer::ADDRESS1 => $addressTransfer->getAddress1(),
199
            RestAddressTransfer::ADDRESS2 => $addressTransfer->getAddress2(),
200
            RestAddressTransfer::ADDRESS3 => $addressTransfer->getAddress3(),
201
            RestAddressTransfer::ZIP_CODE => $addressTransfer->getZipCode(),
202
            RestAddressTransfer::CITY => $addressTransfer->getCity(),
203
            RestAddressTransfer::ISO2_CODE => $addressTransfer->getIso2Code(),
204
            RestAddressTransfer::PHONE => $addressTransfer->getPhone(),
205
            RestCustomerTransfer::EMAIL => $addressTransfer->getEmail(),
206
            RestAddressTransfer::IS_DEFAULT_BILLING => $addressTransfer->getIsDefaultBilling(),
207
            RestAddressTransfer::IS_DEFAULT_SHIPPING => $addressTransfer->getIsDefaultShipping(),
208
        ];
209
    }
210
211
    /**
212
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
213
     *
214
     * @return array<string, mixed>
215
     */
216
    public function getCustomerRequestPayload(CustomerTransfer $customerTransfer): array
217
    {
218
        return [
219
            RestCustomerTransfer::SALUTATION => $customerTransfer->getSalutation(),
220
            RestCustomerTransfer::FIRST_NAME => $customerTransfer->getFirstName(),
221
            RestCustomerTransfer::LAST_NAME => $customerTransfer->getLastName(),
222
            RestCustomerTransfer::EMAIL => $customerTransfer->getEmail(),
223
        ];
224
    }
225
226
    /**
227
     * @param string $paymentMethodName
228
     * @param string $paymentProviderName
229
     *
230
     * @return array<array<string, string>>
231
     */
232
    public function getPaymentRequestPayload(
233
        string $paymentMethodName = self::REQUEST_PARAM_PAYMENT_METHOD_NAME_INVOICE,
234
        string $paymentProviderName = self::REQUEST_PARAM_PAYMENT_PROVIDER_NAME_DUMMY_PAYMENT,
235
    ): array {
236
        return [
237
            [
238
                RestPaymentTransfer::PAYMENT_METHOD_NAME => $paymentMethodName,
239
                RestPaymentTransfer::PAYMENT_PROVIDER_NAME => $paymentProviderName,
240
            ],
241
        ];
242
    }
243
244
    /**
245
     * @param int $idShipmentMethod
246
     *
247
     * @return array<string, int>
248
     */
249
    public function getShipmentRequestPayload(int $idShipmentMethod): array
250
    {
251
        return [
252
            RestShipmentTransfer::ID_SHIPMENT_METHOD => $idShipmentMethod,
253
        ];
254
    }
255
256
    /**
257
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
258
     * @param \Generated\Shared\Transfer\AddressTransfer|null $addressTransfer
259
     *
260
     * @return array<string, mixed>
261
     */
262
    public function getSplitShipmentRequestPayload(ItemTransfer $itemTransfer, ?AddressTransfer $addressTransfer = null): array
263
    {
264
        $shippingAddressPayload = $addressTransfer
265
            ? [RestAddressTransfer::ID => $addressTransfer->getUuidOrFail()]
266
            : $this->getAddressRequestPayload($itemTransfer->getShipmentOrFail()->getShippingAddressOrFail());
267
268
        return [
269
            RestShipmentsTransfer::ID_SHIPMENT_METHOD => $itemTransfer->getShipmentOrFail()->getMethodOrFail()->getIdShipmentMethodOrFail(),
270
            RestShipmentsTransfer::ITEMS => [$itemTransfer->getGroupKeyOrFail()],
271
            RestShipmentsTransfer::SHIPPING_ADDRESS => $shippingAddressPayload,
272
            RestShipmentsTransfer::REQUESTED_DELIVERY_DATE => (new DateTime('tomorrow'))->format('Y-m-d'),
273
        ];
274
    }
275
276
    /**
277
     * @param \Generated\Shared\Transfer\ProductConcreteTransfer $productConcreteTransfer
278
     * @param \Generated\Shared\Transfer\ShipmentMethodTransfer $shipmentMethodTransfer
279
     * @param int $quantity
280
     *
281
     * @return array<string, mixed>
282
     */
283
    public function getQuoteItemOverrideData(
284
        ProductConcreteTransfer $productConcreteTransfer,
285
        ShipmentMethodTransfer $shipmentMethodTransfer,
286
        int $quantity = self::DEFAULT_QUOTE_ITEM_QUANTITY,
287
    ): array {
288
        return [
289
            static::QUOTE_ITEM_OVERRIDE_DATA_PRODUCT => $productConcreteTransfer,
290
            static::QUOTE_ITEM_OVERRIDE_DATA_SHIPMENT => [
291
                ShipmentTransfer::METHOD => $shipmentMethodTransfer,
292
            ],
293
            static::QUOTE_ITEM_OVERRIDE_DATA_QUANTITY => $quantity,
294
        ];
295
    }
296
297
    public function authorizeCustomerToGlue(CustomerTransfer $customerTransfer): void
298
    {
299
        $oauthResponseTransfer = $this->haveAuthorizationToGlue($customerTransfer);
300
        $this->amBearerAuthenticated($oauthResponseTransfer->getAccessToken());
301
    }
302
303
    public function havePersistentQuoteWithItemsAndItemLevelShipment(
304
        CustomerTransfer $customerTransfer,
305
        array $overrideItems = [],
306
        string $priceMode = PriceConfig::PRICE_MODE_GROSS,
307
    ): QuoteTransfer {
308
        return $this->havePersistentQuote([
309
            QuoteTransfer::CUSTOMER => $customerTransfer,
310
            QuoteTransfer::TOTALS => (new TotalsTransfer())
311
                ->setSubtotal(random_int(1000, 10000))
312
                ->setPriceToPay(random_int(1000, 10000)),
313
            QuoteTransfer::ITEMS => $this->mapProductConcreteTransfersToQuoteTransferItemsWithItemLevelShipment($overrideItems),
314
            QuoteTransfer::STORE => [StoreTransfer::NAME => 'DE'],
315
            QuoteTransfer::PRICE_MODE => $priceMode,
316
            QuoteTransfer::BILLING_ADDRESS => (new AddressBuilder())->build(),
317
        ]);
318
    }
319
320
    public function haveEmptyPersistentQuote(array $overrideCustomer = []): QuoteTransfer
321
    {
322
        return $this->havePersistentQuote([
323
            QuoteTransfer::CUSTOMER => (new CustomerBuilder($overrideCustomer))->build(),
324
            QuoteTransfer::BILLING_ADDRESS => (new AddressBuilder())->build(),
325
        ]);
326
    }
327
328
    public function haveProductWithStock(): ProductConcreteTransfer
329
    {
330
        $productConcreteTransfer = $this->haveFullProduct();
331
332
        $this->haveProductInStockForStore($this->getStoreFacade()->getCurrentStore(), [
333
            StockProductTransfer::SKU => $productConcreteTransfer->getSku(),
334
            StockProductTransfer::IS_NEVER_OUT_OF_STOCK => 1,
335
        ]);
336
337
        $priceProductOverride = [
338
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
339
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(),
340
            PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(),
341
            PriceProductTransfer::PRICE_TYPE_NAME => 'DEFAULT',
342
            PriceProductTransfer::MONEY_VALUE => [
343
                MoneyValueTransfer::NET_AMOUNT => 770,
344
                MoneyValueTransfer::GROSS_AMOUNT => 880,
345
            ],
346
        ];
347
        $this->havePriceProduct($priceProductOverride);
348
349
        return $productConcreteTransfer;
350
    }
351
352
    public function createCustomerTransfer(array $override = []): CustomerTransfer
353
    {
354
        return (new CustomerBuilder($override))->build();
355
    }
356
357
    public function haveCustomerWithPersistentAddress(array $override = []): CustomerTransfer
358
    {
359
        $customerTransfer = $this->haveCustomer($override);
360
361
        return $this->haveAddressForCustomer($customerTransfer);
362
    }
363
364
    public function havePaymentMethodWithStore(
365
        array $paymentMethodOverrideData = [],
366
        array $storeOverrideData = [
367
            StoreTransfer::NAME => 'DE',
368
            StoreTransfer::DEFAULT_CURRENCY_ISO_CODE => 'EUR',
369
            StoreTransfer::AVAILABLE_CURRENCY_ISO_CODES => ['EUR'],
370
        ],
371
    ): PaymentMethodTransfer {
372
        $storeTransfer = $this->haveStore($storeOverrideData);
373
        $storeRelationTransfer = (new StoreRelationBuilder())->seed([
374
            StoreRelationTransfer::ID_STORES => [
375
                $storeTransfer->getIdStore(),
376
            ],
377
            StoreRelationTransfer::STORES => [
378
                $storeTransfer,
379
            ],
380
        ])->build();
381
382
        $paymentMethodOverrideData = array_merge($paymentMethodOverrideData, [PaymentMethodTransfer::STORE_RELATION => $storeRelationTransfer]);
383
384
        return $this->havePaymentMethod($paymentMethodOverrideData);
385
    }
386
387
    /**
388
     * @param \Generated\Shared\Transfer\ItemTransfer $itemTransfer
389
     * @param \Generated\Shared\Transfer\CompanyUnitAddressTransfer $companyUnitAddressTransfer
390
     *
391
     * @return array<string, mixed>
392
     */
393
    public function getSplitShipmentRequestPayloadWithCompanyBusinessUnitAddress(
394
        ItemTransfer $itemTransfer,
395
        CompanyUnitAddressTransfer $companyUnitAddressTransfer,
396
    ): array {
397
        return [
398
            RestShipmentsTransfer::ID_SHIPMENT_METHOD => $itemTransfer->getShipmentOrFail()->getMethodOrFail()->getIdShipmentMethodOrFail(),
399
            RestShipmentsTransfer::ITEMS => [$itemTransfer->getGroupKeyOrFail()],
400
            RestShipmentsTransfer::SHIPPING_ADDRESS => [
401
                RestAddressTransfer::ID_COMPANY_BUSINESS_UNIT_ADDRESS => $companyUnitAddressTransfer->getUuidOrFail(),
402
            ],
403
            RestShipmentsTransfer::REQUESTED_DELIVERY_DATE => (new DateTime('tomorrow'))->format('Y-m-d'),
404
        ];
405
    }
406
407
    public function assertCustomerBillingAddressInOrders(AddressTransfer $addressTransfer): void
408
    {
409
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'orders');
410
        $billingAddress = $this->getDataFromResponseByJsonPath($jsonPath)[0]['attributes']['billingAddress'];
411
412
        $this->assertSame($addressTransfer->getAddress1(), $billingAddress['address1']);
413
        $this->assertSame($addressTransfer->getAddress2(), $billingAddress['address2']);
414
        $this->assertSame($addressTransfer->getAddress3(), $billingAddress['address3']);
415
        $this->assertSame($addressTransfer->getCompany(), $billingAddress['company']);
416
        $this->assertSame($addressTransfer->getCity(), $billingAddress['city']);
417
        $this->assertSame($addressTransfer->getZipCode(), $billingAddress['zipCode']);
418
        $this->assertSame($addressTransfer->getIso2Code(), $billingAddress['iso2Code']);
419
    }
420
421
    public function assertCustomerShippingAddressInOrderShipments(
422
        AddressTransfer $addressTransfer,
423
    ): void {
424
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'order-shipments');
425
        $shippingAddress = $this->getDataFromResponseByJsonPath($jsonPath)[0]['attributes']['shippingAddress'];
426
427
        $this->assertSame($addressTransfer->getAddress1(), $shippingAddress['address1']);
428
        $this->assertSame($addressTransfer->getAddress2(), $shippingAddress['address2']);
429
        $this->assertSame($addressTransfer->getAddress3(), $shippingAddress['address3']);
430
        $this->assertSame($addressTransfer->getCompany(), $shippingAddress['company']);
431
        $this->assertSame($addressTransfer->getCity(), $shippingAddress['city']);
432
        $this->assertSame($addressTransfer->getZipCode(), $shippingAddress['zipCode']);
433
        $this->assertSame($addressTransfer->getIso2Code(), $shippingAddress['iso2Code']);
434
    }
435
436
    public function assertCompanyBusinessUnitBillingAddressInOrders(
437
        CompanyUnitAddressTransfer $companyUnitAddressTransfer,
438
    ): void {
439
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'orders');
440
        $billingAddress = $this->getDataFromResponseByJsonPath($jsonPath)[0]['attributes']['billingAddress'];
441
442
        $this->assertSame($companyUnitAddressTransfer->getAddress1(), $billingAddress['address1']);
443
        $this->assertSame($companyUnitAddressTransfer->getAddress2(), $billingAddress['address2']);
444
        $this->assertSame($companyUnitAddressTransfer->getAddress3(), $billingAddress['address3']);
445
        $this->assertSame($companyUnitAddressTransfer->getCompany()->getName(), $billingAddress['company']);
446
        $this->assertSame($companyUnitAddressTransfer->getCity(), $billingAddress['city']);
447
        $this->assertSame($companyUnitAddressTransfer->getZipCode(), $billingAddress['zipCode']);
448
        $this->assertSame($companyUnitAddressTransfer->getIso2Code(), $billingAddress['iso2Code']);
449
    }
450
451
    public function assertCompanyBusinessUnitShippingAddressInOrderShipments(
452
        CompanyUnitAddressTransfer $companyUnitAddressTransfer,
453
    ): void {
454
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'order-shipments');
455
        $shippingAddress = $this->getDataFromResponseByJsonPath($jsonPath)[0]['attributes']['shippingAddress'];
456
457
        $this->assertSame($companyUnitAddressTransfer->getAddress1(), $shippingAddress['address1']);
458
        $this->assertSame($companyUnitAddressTransfer->getAddress2(), $shippingAddress['address2']);
459
        $this->assertSame($companyUnitAddressTransfer->getAddress3(), $shippingAddress['address3']);
460
        $this->assertSame($companyUnitAddressTransfer->getCompany()->getName(), $shippingAddress['company']);
461
        $this->assertSame($companyUnitAddressTransfer->getCity(), $shippingAddress['city']);
462
        $this->assertSame($companyUnitAddressTransfer->getZipCode(), $shippingAddress['zipCode']);
463
        $this->assertSame($companyUnitAddressTransfer->getIso2Code(), $shippingAddress['iso2Code']);
464
    }
465
466
    protected function haveAddressForCustomer(CustomerTransfer $customerTransfer): CustomerTransfer
467
    {
468
        $addressTransfer = (new AddressBuilder([
469
            AddressTransfer::EMAIL => $customerTransfer->getEmail(),
470
            AddressTransfer::FK_CUSTOMER => $customerTransfer->getIdCustomer(),
471
            AddressTransfer::FIRST_NAME => $customerTransfer->getFirstName(),
472
            AddressTransfer::LAST_NAME => $customerTransfer->getLastName(),
473
        ]))->build();
474
        $customerFacade = $this->getCustomerFacade();
475
        $customerFacade->createAddress($addressTransfer);
476
477
        return $customerFacade->getCustomer($customerTransfer);
478
    }
479
480
    /**
481
     * @param array<string, mixed> $overrideItems
482
     *
483
     * @return array<array<string, mixed>>
484
     */
485
    protected function mapProductConcreteTransfersToQuoteTransferItemsWithItemLevelShipment(array $overrideItems = []): array
486
    {
487
        $quoteTransferItems = [];
488
489
        foreach ($overrideItems as $overrideItem) {
490
            $productConcreteTransfer = $this->getProductConcreteTransferFromOverrideItemData($overrideItem);
491
            $overrideShipment = $this->getOverrideShipmentDataFromOverrideItemData($overrideItem);
492
493
            $quoteTransferItems[] = (new ItemBuilder([
494
                ItemTransfer::SKU => $productConcreteTransfer->getSku(),
495
                ItemTransfer::GROUP_KEY => $productConcreteTransfer->getSku(),
496
                ItemTransfer::ABSTRACT_SKU => $productConcreteTransfer->getAbstractSku(),
497
                ItemTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstract(),
498
                ItemTransfer::QUANTITY => $this->getQuoteItemQuantityFromOverrideItemData($overrideItem),
499
            ]))->withShipment((new ShipmentBuilder($overrideShipment))
500
                ->withMethod()
501
                ->withShippingAddress())
502
                ->build()
503
                ->modifiedToArray();
504
        }
505
506
        return $quoteTransferItems;
507
    }
508
509
    protected function getProductConcreteTransferFromOverrideItemData(array $overrideItem): ProductConcreteTransfer
510
    {
511
        return $overrideItem[static::QUOTE_ITEM_OVERRIDE_DATA_PRODUCT];
512
    }
513
514
    /**
515
     * @param array<string, mixed> $overrideItem
516
     *
517
     * @return array<string, mixed>
518
     */
519
    protected function getOverrideShipmentDataFromOverrideItemData(array $overrideItem): array
520
    {
521
        return $overrideItem[static::QUOTE_ITEM_OVERRIDE_DATA_SHIPMENT];
522
    }
523
524
    /**
525
     * @param array<string, mixed> $overrideItem
526
     */
527
    protected function getQuoteItemQuantityFromOverrideItemData(array $overrideItem): int
528
    {
529
        return $overrideItem[static::QUOTE_ITEM_OVERRIDE_DATA_QUANTITY] ?? static::DEFAULT_QUOTE_ITEM_QUANTITY;
530
    }
531
532
    /**
533
     * @param array<string> $includes
534
     */
535
    protected function formatQueryInclude(array $includes = []): string
536
    {
537
        if (!$includes) {
538
            return '';
539
        }
540
541
        return sprintf('?%s=%s', RequestConstantsInterface::QUERY_INCLUDE, implode(',', $includes));
542
    }
543
}
544