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; |
|
|
|
|
13
|
|
|
use Generated\Shared\Transfer\CustomerTransfer; |
|
|
|
|
14
|
|
|
use Generated\Shared\Transfer\MoneyValueTransfer; |
|
|
|
|
15
|
|
|
use Generated\Shared\Transfer\PriceProductTransfer; |
|
|
|
|
16
|
|
|
use Generated\Shared\Transfer\ProductConcreteTransfer; |
|
|
|
|
17
|
|
|
use Generated\Shared\Transfer\QuoteTransfer; |
|
|
|
|
18
|
|
|
use Generated\Shared\Transfer\RestItemProductOptionsTransfer; |
|
|
|
|
19
|
|
|
use Generated\Shared\Transfer\RestItemsAttributesTransfer; |
|
|
|
|
20
|
|
|
use Generated\Shared\Transfer\SaveOrderTransfer; |
|
|
|
|
21
|
|
|
use Generated\Shared\Transfer\StockProductTransfer; |
|
|
|
|
22
|
|
|
use Generated\Shared\Transfer\StoreTransfer; |
|
|
|
|
23
|
|
|
use Spryker\Glue\CartReorderRestApi\CartReorderRestApiConfig; |
24
|
|
|
use Spryker\Glue\CartsRestApi\CartsRestApiConfig; |
25
|
|
|
use SprykerTest\Glue\Testify\Tester\ApiEndToEndTester; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Inherited Methods |
29
|
|
|
* |
30
|
|
|
* @method void wantTo($text) |
31
|
|
|
* @method void wantToTest($text) |
32
|
|
|
* @method void execute($callable) |
33
|
|
|
* @method void expectTo($prediction) |
34
|
|
|
* @method void expect($prediction) |
35
|
|
|
* @method void amGoingTo($argumentation) |
36
|
|
|
* @method void am($role) |
37
|
|
|
* @method void lookForwardTo($achieveValue) |
38
|
|
|
* @method void comment($description) |
39
|
|
|
* @method void pause($vars = []) |
40
|
|
|
* |
41
|
|
|
* @SuppressWarnings(PHPMD) |
42
|
|
|
*/ |
43
|
|
|
class CartReorderApiTester extends ApiEndToEndTester |
44
|
|
|
{ |
45
|
|
|
use _generated\CartReorderApiTesterActions; |
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @uses \Spryker\Glue\CartsRestApi\CartsRestApiConfig::RESOURCE_CART_ITEMS |
49
|
|
|
* |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
public const RESOURCE_CARTS = 'carts'; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @uses \Spryker\Glue\CartsRestApi\CartsRestApiConfig::RESOURCE_CART_ITEMS |
56
|
|
|
* |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
public const RESOURCE_CART_ITEMS = 'items'; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @uses \Spryker\Glue\ProductBundleCartsRestApi\ProductBundleCartsRestApiConfig::RESOURCE_BUNDLE_ITEMS |
63
|
|
|
* |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
public const RESOURCE_BUNDLE_ITEMS = 'bundle-items'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @uses \Spryker\Shared\PriceProduct\PriceProductConfig::PRICE_TYPE_DEFAULT |
70
|
|
|
* |
71
|
|
|
* @var string |
72
|
|
|
*/ |
73
|
|
|
public const PRICE_TYPE = 'DEFAULT'; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var string |
77
|
|
|
*/ |
78
|
|
|
protected const PRICE_MODE = 'GROSS_MODE'; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var string |
82
|
|
|
*/ |
83
|
|
|
protected const STATE_MACHINE_NAME = 'DummyPayment01'; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var string |
87
|
|
|
*/ |
88
|
|
|
protected const TEST_CUSTOMER_PASSWORD = 'change123'; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return void |
92
|
|
|
*/ |
93
|
|
|
public function configureStateMachine(): void |
94
|
|
|
{ |
95
|
|
|
$this->configureTestStateMachine([static::STATE_MACHINE_NAME]); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return \Generated\Shared\Transfer\StoreTransfer |
100
|
|
|
*/ |
101
|
|
|
public function getCurrentStore(): StoreTransfer |
102
|
|
|
{ |
103
|
|
|
return $this->getLocator()->store()->facade()->getCurrentStore(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param string $customerName |
108
|
|
|
* |
109
|
|
|
* @return \Generated\Shared\Transfer\CustomerTransfer |
110
|
|
|
*/ |
111
|
|
|
public function createCustomer(string $customerName): CustomerTransfer |
112
|
|
|
{ |
113
|
|
|
$customerTransfer = $this->haveCustomer([ |
114
|
|
|
CustomerTransfer::USERNAME => $customerName, |
115
|
|
|
CustomerTransfer::PASSWORD => static::TEST_CUSTOMER_PASSWORD, |
116
|
|
|
CustomerTransfer::NEW_PASSWORD => static::TEST_CUSTOMER_PASSWORD, |
117
|
|
|
]); |
118
|
|
|
|
119
|
|
|
return $this->confirmCustomer($customerTransfer); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer |
124
|
|
|
* |
125
|
|
|
* @return \Generated\Shared\Transfer\ProductConcreteTransfer |
126
|
|
|
*/ |
127
|
|
|
public function createProductWithPriceAndStock(StoreTransfer $storeTransfer): ProductConcreteTransfer |
128
|
|
|
{ |
129
|
|
|
$productConcreteTransfer = $this->haveFullProduct(); |
130
|
|
|
|
131
|
|
|
$this->haveProductInStockForStore($storeTransfer, [ |
132
|
|
|
StockProductTransfer::SKU => $productConcreteTransfer->getSku(), |
133
|
|
|
StockProductTransfer::IS_NEVER_OUT_OF_STOCK => 1, |
134
|
|
|
]); |
135
|
|
|
|
136
|
|
|
$this->havePriceProduct([ |
137
|
|
|
PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSkuOrFail(), |
138
|
|
|
PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSkuOrFail(), |
139
|
|
|
PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcreteOrFail(), |
140
|
|
|
PriceProductTransfer::PRICE_TYPE_NAME => static::PRICE_TYPE, |
141
|
|
|
PriceProductTransfer::MONEY_VALUE => [ |
142
|
|
|
MoneyValueTransfer::NET_AMOUNT => 777, |
143
|
|
|
MoneyValueTransfer::GROSS_AMOUNT => 888, |
144
|
|
|
], |
145
|
|
|
]); |
146
|
|
|
|
147
|
|
|
return $productConcreteTransfer; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer |
152
|
|
|
* @param array<string, mixed> $seedData |
153
|
|
|
* @param list<\Spryker\Zed\CheckoutExtension\Dependency\Plugin\CheckoutDoSaveOrderInterface> $checkoutDoSaveOrderPlugins |
|
|
|
|
154
|
|
|
* |
155
|
|
|
* @return \Generated\Shared\Transfer\SaveOrderTransfer |
156
|
|
|
*/ |
157
|
|
|
public function createOrder( |
158
|
|
|
CustomerTransfer $customerTransfer, |
159
|
|
|
array $seedData, |
160
|
|
|
array $checkoutDoSaveOrderPlugins = [], |
161
|
|
|
): SaveOrderTransfer { |
162
|
|
|
$quoteTransfer = $this->createQuoteTransfer($customerTransfer, $seedData); |
163
|
|
|
$quoteTransfer->setPriceMode(static::PRICE_MODE); |
164
|
|
|
|
165
|
|
|
return $this->haveOrderFromQuote( |
166
|
|
|
$quoteTransfer, |
167
|
|
|
static::STATE_MACHINE_NAME, |
168
|
|
|
$checkoutDoSaveOrderPlugins, |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer |
174
|
|
|
* |
175
|
|
|
* @return void |
176
|
|
|
*/ |
177
|
|
|
public function authorizeCustomerToGlue(CustomerTransfer $customerTransfer): void |
178
|
|
|
{ |
179
|
|
|
$oauthResponseTransfer = $this->haveAuthorizationToGlue($customerTransfer); |
180
|
|
|
$this->amBearerAuthenticated($oauthResponseTransfer->getAccessToken()); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return string |
185
|
|
|
*/ |
186
|
|
|
public function getCartReorderUrl(): string |
187
|
|
|
{ |
188
|
|
|
$url = sprintf('{cartReorderResource}?include=%s,%s', static::RESOURCE_CART_ITEMS, static::RESOURCE_BUNDLE_ITEMS); |
189
|
|
|
|
190
|
|
|
return $this->formatUrl($url, [ |
191
|
|
|
'cartReorderResource' => CartReorderRestApiConfig::RESOURCE_CART_REORDER, |
192
|
|
|
]); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* @param string $sku |
197
|
|
|
* |
198
|
|
|
* @return void |
199
|
|
|
*/ |
200
|
|
|
public function assertResponseContainsItemBySku(string $sku): void |
201
|
|
|
{ |
202
|
|
|
$this->assertNotNull($this->findIncludedItemsResourceBySku($sku)); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param string $sku |
207
|
|
|
* |
208
|
|
|
* @return void |
209
|
|
|
*/ |
210
|
|
|
public function assertResponseDoesNotContainItemBySku(string $sku): void |
211
|
|
|
{ |
212
|
|
|
$this->assertNull($this->findIncludedItemsResourceBySku($sku)); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param string $sku |
217
|
|
|
* |
218
|
|
|
* @return void |
219
|
|
|
*/ |
220
|
|
|
public function assertResponseContainsBundleItemBySku(string $sku): void |
221
|
|
|
{ |
222
|
|
|
$this->assertNotNull($this->findIncludedBundleItemsResourceBySku($sku)); |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @param string $sku |
227
|
|
|
* @param int $quantity |
228
|
|
|
* |
229
|
|
|
* @return void |
230
|
|
|
*/ |
231
|
|
|
public function assertItemHasCorrectQuantity(string $sku, int $quantity): void |
232
|
|
|
{ |
233
|
|
|
$itemsResourceAttributes = $this->findIncludedItemsResourceBySku($sku)['attributes']; |
234
|
|
|
|
235
|
|
|
$this->assertArrayHasKey(RestItemsAttributesTransfer::QUANTITY, $itemsResourceAttributes); |
236
|
|
|
$this->assertSame($quantity, $itemsResourceAttributes[RestItemsAttributesTransfer::QUANTITY]); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @param string $sku |
241
|
|
|
* @param int $quantity |
242
|
|
|
* |
243
|
|
|
* @return void |
244
|
|
|
*/ |
245
|
|
|
public function assertBundleItemHasCorrectQuantity(string $sku, int $quantity): void |
246
|
|
|
{ |
247
|
|
|
$bundleItemsResourceAttributes = $this->findIncludedBundleItemsResourceBySku($sku)['attributes']; |
248
|
|
|
|
249
|
|
|
$this->assertArrayHasKey(RestItemsAttributesTransfer::QUANTITY, $bundleItemsResourceAttributes); |
250
|
|
|
$this->assertSame($quantity, $bundleItemsResourceAttributes[RestItemsAttributesTransfer::QUANTITY]); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* @param string $productConcreteSku |
255
|
|
|
* @param string $productOptionSku |
256
|
|
|
* |
257
|
|
|
* @return void |
258
|
|
|
*/ |
259
|
|
|
public function assertItemHasProductOption(string $productConcreteSku, string $productOptionSku): void |
260
|
|
|
{ |
261
|
|
|
$itemsResourceAttributes = $this->findIncludedItemsResourceBySku($productConcreteSku)['attributes']; |
262
|
|
|
|
263
|
|
|
$this->assertArrayHasKey(RestItemsAttributesTransfer::SELECTED_PRODUCT_OPTIONS, $itemsResourceAttributes); |
264
|
|
|
$this->assertCount(1, $itemsResourceAttributes[RestItemsAttributesTransfer::SELECTED_PRODUCT_OPTIONS]); |
265
|
|
|
|
266
|
|
|
$productOption = $itemsResourceAttributes[RestItemsAttributesTransfer::SELECTED_PRODUCT_OPTIONS][0]; |
267
|
|
|
|
268
|
|
|
$this->assertArrayHasKey(RestItemProductOptionsTransfer::SKU, $productOption); |
269
|
|
|
$this->assertSame($productOptionSku, $productOption[RestItemProductOptionsTransfer::SKU]); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* @param string $cartUuid |
274
|
|
|
* |
275
|
|
|
* @return string |
276
|
|
|
*/ |
277
|
|
|
public function buildCartsUrl(string $cartUuid): string |
278
|
|
|
{ |
279
|
|
|
return $this->formatFullUrl( |
280
|
|
|
'{resourceCarts}/{cartUuid}', |
281
|
|
|
[ |
282
|
|
|
'resourceCarts' => CartsRestApiConfig::RESOURCE_CARTS, |
283
|
|
|
'cartUuid' => $cartUuid, |
284
|
|
|
], |
285
|
|
|
); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer |
290
|
|
|
* @param array<string, mixed> $seedData |
291
|
|
|
* |
292
|
|
|
* @return \Generated\Shared\Transfer\QuoteTransfer |
293
|
|
|
*/ |
294
|
|
|
protected function createQuoteTransfer(CustomerTransfer $customerTransfer, array $seedData): QuoteTransfer |
295
|
|
|
{ |
296
|
|
|
return (new QuoteBuilder($seedData)) |
297
|
|
|
->withCustomer([CustomerTransfer::CUSTOMER_REFERENCE => $customerTransfer->getCustomerReference()]) |
298
|
|
|
->withTotals() |
299
|
|
|
->withShippingAddress() |
300
|
|
|
->withBillingAddress() |
301
|
|
|
->withCurrency() |
302
|
|
|
->withPayment() |
303
|
|
|
->build(); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @param string $sku |
308
|
|
|
* |
309
|
|
|
* @return array<string, mixed>|null |
310
|
|
|
*/ |
311
|
|
|
protected function findIncludedItemsResourceBySku(string $sku): ?array |
312
|
|
|
{ |
313
|
|
|
$jsonPath = sprintf( |
314
|
|
|
'$..included[?(@.type == \'%s\')]', |
315
|
|
|
static::RESOURCE_CART_ITEMS, |
316
|
|
|
); |
317
|
|
|
|
318
|
|
|
$itemsResources = $this->getDataFromResponseByJsonPath($jsonPath); |
319
|
|
|
foreach ($itemsResources as $itemsResource) { |
320
|
|
|
if ($itemsResource['attributes']['sku'] === $sku) { |
321
|
|
|
return $itemsResource; |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
return null; |
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* @param string $sku |
330
|
|
|
* |
331
|
|
|
* @return array<string, mixed>|null |
332
|
|
|
*/ |
333
|
|
|
protected function findIncludedBundleItemsResourceBySku(string $sku): ?array |
334
|
|
|
{ |
335
|
|
|
$jsonPath = sprintf( |
336
|
|
|
'$..included[?(@.type == \'%s\')]', |
337
|
|
|
static::RESOURCE_BUNDLE_ITEMS, |
338
|
|
|
); |
339
|
|
|
|
340
|
|
|
$bundleItemsResources = $this->getDataFromResponseByJsonPath($jsonPath); |
341
|
|
|
foreach ($bundleItemsResources as $bundleItemsResource) { |
342
|
|
|
if ($bundleItemsResource['attributes']['sku'] === $sku) { |
343
|
|
|
return $bundleItemsResource; |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
return null; |
348
|
|
|
} |
349
|
|
|
} |
350
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths