CartReorderApiTester::authorizeCustomerToGlue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 2
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
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\CartReorder;
11
12
use Generated\Shared\DataBuilder\QuoteBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBuilder\QuoteBuilder 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...
13
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...
14
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...
15
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...
16
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...
17
use Generated\Shared\Transfer\ProductMeasurementBaseUnitTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...urementBaseUnitTransfer 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\ProductMeasurementSalesUnitTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...rementSalesUnitTransfer 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\ProductMeasurementUnitTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...MeasurementUnitTransfer 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\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...
21
use Generated\Shared\Transfer\RestCartItemsSalesUnitAttributesTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...sUnitAttributesTransfer 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\RestCartsAttributesTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...CartsAttributesTransfer 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\RestItemProductOptionsTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...mProductOptionsTransfer 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\RestItemsAttributesTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...ItemsAttributesTransfer 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\SaveOrderTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\SaveOrderTransfer 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\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...
27
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...
28
use Spryker\DecimalObject\Decimal;
29
use Spryker\Glue\CartReorderRestApi\CartReorderRestApiConfig;
30
use Spryker\Glue\CartsRestApi\CartsRestApiConfig;
31
use SprykerTest\Glue\Testify\Tester\ApiEndToEndTester;
32
33
/**
34
 * Inherited Methods
35
 *
36
 * @method void wantTo($text)
37
 * @method void wantToTest($text)
38
 * @method void execute($callable)
39
 * @method void expectTo($prediction)
40
 * @method void expect($prediction)
41
 * @method void amGoingTo($argumentation)
42
 * @method void am($role)
43
 * @method void lookForwardTo($achieveValue)
44
 * @method void comment($description)
45
 * @method void pause($vars = [])
46
 *
47
 * @SuppressWarnings(PHPMD)
48
 */
49
class CartReorderApiTester extends ApiEndToEndTester
50
{
51
    use _generated\CartReorderApiTesterActions;
0 ignored issues
show
Bug introduced by
The type PyzTest\Glue\CartReorder...ReorderApiTesterActions 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...
52
53
    /**
54
     * @uses \Spryker\Glue\CartsRestApi\CartsRestApiConfig::RESOURCE_CART_ITEMS
55
     *
56
     * @var string
57
     */
58
    public const RESOURCE_CARTS = 'carts';
59
60
    /**
61
     * @uses \Spryker\Glue\CartsRestApi\CartsRestApiConfig::RESOURCE_CART_ITEMS
62
     *
63
     * @var string
64
     */
65
    public const RESOURCE_CART_ITEMS = 'items';
66
67
    /**
68
     * @uses \Spryker\Glue\ProductBundleCartsRestApi\ProductBundleCartsRestApiConfig::RESOURCE_BUNDLE_ITEMS
69
     *
70
     * @var string
71
     */
72
    public const RESOURCE_BUNDLE_ITEMS = 'bundle-items';
73
74
    /**
75
     * @uses \Spryker\Shared\PriceProduct\PriceProductConfig::PRICE_TYPE_DEFAULT
76
     *
77
     * @var string
78
     */
79
    public const PRICE_TYPE = 'DEFAULT';
80
81
    /**
82
     * @var string
83
     */
84
    protected const PRICE_MODE = 'GROSS_MODE';
85
86
    /**
87
     * @var string
88
     */
89
    protected const STATE_MACHINE_NAME = 'DummyPayment01';
90
91
    /**
92
     * @var string
93
     */
94
    protected const TEST_CUSTOMER_PASSWORD = 'change123';
95
96
    /**
97
     * @return void
98
     */
99
    public function configureStateMachine(): void
100
    {
101
        $this->configureTestStateMachine([static::STATE_MACHINE_NAME]);
102
    }
103
104
    /**
105
     * @return \Generated\Shared\Transfer\StoreTransfer
106
     */
107
    public function getCurrentStore(): StoreTransfer
108
    {
109
        return $this->getLocator()->store()->facade()->getCurrentStore();
110
    }
111
112
    /**
113
     * @param string $customerName
114
     *
115
     * @return \Generated\Shared\Transfer\CustomerTransfer
116
     */
117
    public function createCustomer(string $customerName): CustomerTransfer
118
    {
119
        $customerTransfer = $this->haveCustomer([
120
            CustomerTransfer::USERNAME => $customerName,
121
            CustomerTransfer::PASSWORD => static::TEST_CUSTOMER_PASSWORD,
122
            CustomerTransfer::NEW_PASSWORD => static::TEST_CUSTOMER_PASSWORD,
123
        ]);
124
125
        return $this->confirmCustomer($customerTransfer);
126
    }
127
128
    /**
129
     * @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer
130
     *
131
     * @return \Generated\Shared\Transfer\ProductConcreteTransfer
132
     */
133
    public function createProductWithPriceAndStock(StoreTransfer $storeTransfer): ProductConcreteTransfer
134
    {
135
        $productConcreteTransfer = $this->haveFullProduct();
136
137
        $this->haveProductInStockForStore($storeTransfer, [
138
            StockProductTransfer::SKU => $productConcreteTransfer->getSku(),
139
            StockProductTransfer::IS_NEVER_OUT_OF_STOCK => 1,
140
        ]);
141
142
        $this->havePriceProduct([
143
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSkuOrFail(),
144
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSkuOrFail(),
145
            PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcreteOrFail(),
146
            PriceProductTransfer::PRICE_TYPE_NAME => static::PRICE_TYPE,
147
            PriceProductTransfer::MONEY_VALUE => [
148
                MoneyValueTransfer::NET_AMOUNT => 777,
149
                MoneyValueTransfer::GROSS_AMOUNT => 888,
150
            ],
151
        ]);
152
153
        return $productConcreteTransfer;
154
    }
155
156
    /**
157
     * @param \Generated\Shared\Transfer\ProductConcreteTransfer $productConcreteTransfer
158
     *
159
     * @return \Generated\Shared\Transfer\ProductMeasurementSalesUnitTransfer
160
     */
161
    public function createProductMeasurementSalesUnit(ProductConcreteTransfer $productConcreteTransfer): ProductMeasurementSalesUnitTransfer
162
    {
163
        $productMeasurementUnitEntityTransfer = $this->haveProductMeasurementUnit();
164
        $productMeasurementUnitTransfer = (new ProductMeasurementUnitTransfer())->fromArray(
165
            $productMeasurementUnitEntityTransfer->toArray(),
166
            true,
167
        );
168
169
        $productMeasurementBaseUnitEntityTransfer = $this->haveProductMeasurementBaseUnit(
170
            $productConcreteTransfer->getFkProductAbstractOrFail(),
171
            $productMeasurementUnitEntityTransfer->getIdProductMeasurementUnitOrFail(),
172
        );
173
        $productMeasurementBaseUnitTransfer = (new ProductMeasurementBaseUnitTransfer())->fromArray(
174
            $productMeasurementBaseUnitEntityTransfer->toArray(),
175
            true,
176
        )->setProductMeasurementUnit($productMeasurementUnitTransfer);
177
178
        $productMeasurementSalesUnitEntityTransfer = $this->haveProductMeasurementSalesUnit(
179
            $productConcreteTransfer->getIdProductConcreteOrFail(),
180
            $productMeasurementUnitEntityTransfer->getIdProductMeasurementUnitOrFail(),
181
            $productMeasurementBaseUnitEntityTransfer->getIdProductMeasurementBaseUnitOrFail(),
182
        );
183
184
        return (new ProductMeasurementSalesUnitTransfer())
185
            ->fromArray($productMeasurementSalesUnitEntityTransfer->toArray(), true)
186
            ->setProductMeasurementUnit($productMeasurementUnitTransfer)
187
            ->setProductMeasurementBaseUnit($productMeasurementBaseUnitTransfer);
188
    }
189
190
    /**
191
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
192
     * @param array<string, mixed> $seedData
193
     * @param list<\Spryker\Zed\CheckoutExtension\Dependency\Plugin\CheckoutDoSaveOrderInterface> $checkoutDoSaveOrderPlugins
0 ignored issues
show
Bug introduced by
The type PyzTest\Glue\CartReorder\list 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...
194
     *
195
     * @return \Generated\Shared\Transfer\SaveOrderTransfer
196
     */
197
    public function createOrder(
198
        CustomerTransfer $customerTransfer,
199
        array $seedData,
200
        array $checkoutDoSaveOrderPlugins = [],
201
    ): SaveOrderTransfer {
202
        $quoteTransfer = $this->createQuoteTransfer($customerTransfer, $seedData);
203
        $quoteTransfer->setPriceMode(static::PRICE_MODE);
204
205
        return $this->haveOrderFromQuote(
206
            $quoteTransfer,
207
            static::STATE_MACHINE_NAME,
208
            $checkoutDoSaveOrderPlugins,
209
        );
210
    }
211
212
    /**
213
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
214
     *
215
     * @return void
216
     */
217
    public function authorizeCustomerToGlue(CustomerTransfer $customerTransfer): void
218
    {
219
        $oauthResponseTransfer = $this->haveAuthorizationToGlue($customerTransfer);
220
        $this->amBearerAuthenticated($oauthResponseTransfer->getAccessToken());
221
    }
222
223
    /**
224
     * @return string
225
     */
226
    public function getCartReorderUrl(): string
227
    {
228
        $url = sprintf('{cartReorderResource}?include=%s,%s', static::RESOURCE_CART_ITEMS, static::RESOURCE_BUNDLE_ITEMS);
229
230
        return $this->formatUrl($url, [
231
            'cartReorderResource' => CartReorderRestApiConfig::RESOURCE_CART_REORDER,
232
        ]);
233
    }
234
235
    /**
236
     * @param string $quoteName
237
     *
238
     * @return void
239
     */
240
    public function assertResponseContainsCorrectCartName(string $quoteName): void
241
    {
242
        $attributes = $this->getDataFromResponseByJsonPath('$.data.attributes');
243
244
        $this->assertArrayHasKey(RestCartsAttributesTransfer::NAME, $attributes);
245
        $this->assertSame($quoteName, $attributes[RestCartsAttributesTransfer::NAME]);
246
    }
247
248
    /**
249
     * @param string $sku
250
     *
251
     * @return void
252
     */
253
    public function assertResponseContainsItemBySku(string $sku): void
254
    {
255
        $this->assertNotNull($this->findIncludedItemsResourceBySku($sku));
256
    }
257
258
    /**
259
     * @param string $sku
260
     *
261
     * @return void
262
     */
263
    public function assertResponseDoesNotContainItemBySku(string $sku): void
264
    {
265
        $this->assertNull($this->findIncludedItemsResourceBySku($sku));
266
    }
267
268
    /**
269
     * @param string $sku
270
     *
271
     * @return void
272
     */
273
    public function assertResponseContainsBundleItemBySku(string $sku): void
274
    {
275
        $this->assertNotNull($this->findIncludedBundleItemsResourceBySku($sku));
276
    }
277
278
    /**
279
     * @param string $sku
280
     * @param int $quantity
281
     *
282
     * @return void
283
     */
284
    public function assertItemHasCorrectQuantity(string $sku, int $quantity): void
285
    {
286
        $itemsResourceAttributes = $this->findIncludedItemsResourceBySku($sku)['attributes'];
287
288
        $this->assertArrayHasKey(RestItemsAttributesTransfer::QUANTITY, $itemsResourceAttributes);
289
        $this->assertSame($quantity, $itemsResourceAttributes[RestItemsAttributesTransfer::QUANTITY]);
290
    }
291
292
    /**
293
     * @param string $sku
294
     * @param int $quantity
295
     *
296
     * @return void
297
     */
298
    public function assertBundleItemHasCorrectQuantity(string $sku, int $quantity): void
299
    {
300
        $bundleItemsResourceAttributes = $this->findIncludedBundleItemsResourceBySku($sku)['attributes'];
301
302
        $this->assertArrayHasKey(RestItemsAttributesTransfer::QUANTITY, $bundleItemsResourceAttributes);
303
        $this->assertSame($quantity, $bundleItemsResourceAttributes[RestItemsAttributesTransfer::QUANTITY]);
304
    }
305
306
    /**
307
     * @param string $sku
308
     * @param int $idSalesUnit
309
     *
310
     * @return void
311
     */
312
    public function assertItemHasIdSalesUnit(string $sku, int $idSalesUnit): void
313
    {
314
        $itemsResourceAttributes = $this->findIncludedItemsResourceBySku($sku)['attributes'];
315
316
        $this->assertArrayHasKey(RestItemsAttributesTransfer::SALES_UNIT, $itemsResourceAttributes);
317
        $itemSalesUnitData = $itemsResourceAttributes[RestItemsAttributesTransfer::SALES_UNIT];
318
        $this->assertArrayHasKey(RestCartItemsSalesUnitAttributesTransfer::ID, $itemSalesUnitData);
319
        $this->assertSame($idSalesUnit, $itemSalesUnitData[RestCartItemsSalesUnitAttributesTransfer::ID]);
320
    }
321
322
    /**
323
     * @param string $sku
324
     * @param \Spryker\DecimalObject\Decimal $amount
325
     *
326
     * @return void
327
     */
328
    public function assertItemHasSalesUnitAmount(string $sku, Decimal $amount): void
329
    {
330
        $itemsResourceAttributes = $this->findIncludedItemsResourceBySku($sku)['attributes'];
331
332
        $this->assertArrayHasKey(RestItemsAttributesTransfer::SALES_UNIT, $itemsResourceAttributes);
333
        $itemSalesUnitData = $itemsResourceAttributes[RestItemsAttributesTransfer::SALES_UNIT];
334
        $this->assertArrayHasKey(RestCartItemsSalesUnitAttributesTransfer::AMOUNT, $itemSalesUnitData);
335
        $this->assertTrue($amount->equals($itemSalesUnitData[RestCartItemsSalesUnitAttributesTransfer::AMOUNT]));
336
    }
337
338
    /**
339
     * @param string $productConcreteSku
340
     * @param string $productOptionSku
341
     *
342
     * @return void
343
     */
344
    public function assertItemHasProductOption(string $productConcreteSku, string $productOptionSku): void
345
    {
346
        $itemsResourceAttributes = $this->findIncludedItemsResourceBySku($productConcreteSku)['attributes'];
347
348
        $this->assertArrayHasKey(RestItemsAttributesTransfer::SELECTED_PRODUCT_OPTIONS, $itemsResourceAttributes);
349
        $this->assertCount(1, $itemsResourceAttributes[RestItemsAttributesTransfer::SELECTED_PRODUCT_OPTIONS]);
350
351
        $productOption = $itemsResourceAttributes[RestItemsAttributesTransfer::SELECTED_PRODUCT_OPTIONS][0];
352
353
        $this->assertArrayHasKey(RestItemProductOptionsTransfer::SKU, $productOption);
354
        $this->assertSame($productOptionSku, $productOption[RestItemProductOptionsTransfer::SKU]);
355
    }
356
357
    /**
358
     * @param string $cartUuid
359
     *
360
     * @return string
361
     */
362
    public function buildCartsUrl(string $cartUuid): string
363
    {
364
        return $this->formatFullUrl(
365
            '{resourceCarts}/{cartUuid}',
366
            [
367
                'resourceCarts' => CartsRestApiConfig::RESOURCE_CARTS,
368
                'cartUuid' => $cartUuid,
369
            ],
370
        );
371
    }
372
373
    /**
374
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
375
     * @param array<string, mixed> $seedData
376
     *
377
     * @return \Generated\Shared\Transfer\QuoteTransfer
378
     */
379
    protected function createQuoteTransfer(CustomerTransfer $customerTransfer, array $seedData): QuoteTransfer
380
    {
381
        return (new QuoteBuilder($seedData))
382
            ->withCustomer([CustomerTransfer::CUSTOMER_REFERENCE => $customerTransfer->getCustomerReference()])
383
            ->withTotals()
384
            ->withShippingAddress()
385
            ->withBillingAddress()
386
            ->withCurrency()
387
            ->withPayment()
388
            ->build();
389
    }
390
391
    /**
392
     * @param string $sku
393
     *
394
     * @return array<string, mixed>|null
395
     */
396
    protected function findIncludedItemsResourceBySku(string $sku): ?array
397
    {
398
        $jsonPath = sprintf(
399
            '$..included[?(@.type == \'%s\')]',
400
            static::RESOURCE_CART_ITEMS,
401
        );
402
403
        $itemsResources = $this->getDataFromResponseByJsonPath($jsonPath);
404
        foreach ($itemsResources as $itemsResource) {
405
            if ($itemsResource['attributes']['sku'] === $sku) {
406
                return $itemsResource;
407
            }
408
        }
409
410
        return null;
411
    }
412
413
    /**
414
     * @param string $sku
415
     *
416
     * @return array<string, mixed>|null
417
     */
418
    protected function findIncludedBundleItemsResourceBySku(string $sku): ?array
419
    {
420
        $jsonPath = sprintf(
421
            '$..included[?(@.type == \'%s\')]',
422
            static::RESOURCE_BUNDLE_ITEMS,
423
        );
424
425
        $bundleItemsResources = $this->getDataFromResponseByJsonPath($jsonPath);
426
        foreach ($bundleItemsResources as $bundleItemsResource) {
427
            if ($bundleItemsResource['attributes']['sku'] === $sku) {
428
                return $bundleItemsResource;
429
            }
430
        }
431
432
        return null;
433
    }
434
}
435