8
8
9
9
namespace Magento \WebapiAsync \Model ;
10
10
11
- use Magento \Catalog \Api \Data \ProductInterface as Product ;
12
- use Magento \TestFramework \MessageQueue \PreconditionFailedException ;
13
- use Magento \TestFramework \MessageQueue \PublisherConsumerController ;
14
- use Magento \TestFramework \MessageQueue \EnvironmentPreconditionException ;
15
- use Magento \TestFramework \TestCase \WebapiAbstract ;
16
- use Magento \TestFramework \Helper \Bootstrap ;
11
+ use Magento \Catalog \Api \Data \ProductInterface ;
12
+ use Magento \Catalog \Api \ProductRepositoryInterface ;
17
13
use Magento \Catalog \Model \ResourceModel \Product \Collection ;
14
+ use Magento \Framework \ObjectManagerInterface ;
18
15
use Magento \Framework \Phrase ;
19
16
use Magento \Framework \Registry ;
20
17
use Magento \Framework \Webapi \Exception ;
21
- use Magento \Catalog \Api \ProductRepositoryInterface ;
22
- use Magento \Framework \ObjectManagerInterface ;
23
- use Magento \Store \Model \Store ;
24
18
use Magento \Framework \Webapi \Rest \Request ;
19
+ use Magento \Store \Model \Store ;
20
+ use Magento \TestFramework \Helper \Bootstrap ;
21
+ use Magento \TestFramework \MessageQueue \EnvironmentPreconditionException ;
22
+ use Magento \TestFramework \MessageQueue \PreconditionFailedException ;
23
+ use Magento \TestFramework \MessageQueue \PublisherConsumerController ;
24
+ use Magento \TestFramework \TestCase \WebapiAbstract ;
25
25
26
26
/**
27
27
* Check async request for multistore product creation service, scheduling bulk
@@ -86,27 +86,29 @@ class AsyncScheduleMultiStoreTest extends WebapiAbstract
86
86
*/
87
87
private $ registry ;
88
88
89
+ /**
90
+ * @inheritDoc
91
+ */
89
92
protected function setUp (): void
90
93
{
94
+ $ logFilePath = TESTS_TEMP_DIR . "/MessageQueueTestLog.txt " ;
91
95
$ this ->objectManager = Bootstrap::getObjectManager ();
92
- $ this ->logFilePath = TESTS_TEMP_DIR . "/MessageQueueTestLog.txt " ;
93
96
$ this ->registry = $ this ->objectManager ->get (Registry::class);
94
97
95
98
$ params = array_merge_recursive (
96
99
Bootstrap::getInstance ()->getAppInitParams (),
97
100
['MAGE_DIRS ' => ['cache ' => ['path ' => TESTS_TEMP_DIR . '/cache ' ]]]
98
101
);
99
102
100
- /** @var PublisherConsumerController publisherConsumerController */
101
103
$ this ->publisherConsumerController = $ this ->objectManager ->create (
102
104
PublisherConsumerController::class,
103
105
[
104
106
'consumers ' => $ this ->consumers ,
105
- 'logFilePath ' => $ this -> logFilePath ,
107
+ 'logFilePath ' => $ logFilePath ,
106
108
'appInitParams ' => $ params ,
107
109
]
108
110
);
109
- $ this ->productRepository = $ this ->objectManager ->create (ProductRepositoryInterface::class);
111
+ $ this ->productRepository = $ this ->objectManager ->get (ProductRepositoryInterface::class);
110
112
111
113
try {
112
114
$ this ->publisherConsumerController ->initialize ();
@@ -124,16 +126,11 @@ protected function setUp(): void
124
126
/**
125
127
* @dataProvider storeProvider
126
128
* @magentoApiDataFixture Magento/Store/_files/core_fixturestore.php
129
+ * @param string|null $storeCode
130
+ * @return void
127
131
*/
128
- public function testAsyncScheduleBulkMultistore ($ storeCode )
132
+ public function testAsyncScheduleBulkMultistore ($ storeCode ): void
129
133
{
130
- if ($ storeCode === self ::STORE_CODE_FROM_FIXTURE ) {
131
- /** @var \Magento\Config\Model\Config $config */
132
- $ config = Bootstrap::getObjectManager ()->get (\Magento \Config \Model \Config::class);
133
- if (strpos ($ config ->getConfigDataValue ('catalog/search/engine ' ), 'elasticsearch ' ) !== false ) {
134
- $ this ->markTestSkipped ('MC-20452 ' );
135
- }
136
- }
137
134
$ product = $ this ->getProductData ();
138
135
$ this ->_markTestAsRestOnly ();
139
136
@@ -147,9 +144,9 @@ public function testAsyncScheduleBulkMultistore($storeCode)
147
144
);
148
145
149
146
try {
150
- /** @var Product $productModel */
147
+ /** @var ProductInterface $productModel */
151
148
$ productModel = $ this ->objectManager ->create (
152
- Product ::class,
149
+ ProductInterface ::class,
153
150
['data ' => $ product ['product ' ]]
154
151
);
155
152
$ this ->productRepository ->save ($ productModel );
@@ -161,16 +158,21 @@ public function testAsyncScheduleBulkMultistore($storeCode)
161
158
$ this ->clearProducts ();
162
159
}
163
160
164
- private function asyncScheduleAndTest ($ product , $ storeCode = null )
161
+ /**
162
+ * @param array $product
163
+ * @param string|null $storeCode
164
+ * @return void
165
+ */
166
+ private function asyncScheduleAndTest (array $ product , $ storeCode = null ): void
165
167
{
166
- $ sku = $ product ['product ' ][Product ::SKU ];
167
- $ productName = $ product ['product ' ][Product ::NAME ];
168
- $ newProductName = $ product ['product ' ][Product ::NAME ] . $ storeCode ;
168
+ $ sku = $ product ['product ' ][ProductInterface ::SKU ];
169
+ $ productName = $ product ['product ' ][ProductInterface ::NAME ];
170
+ $ newProductName = $ product ['product ' ][ProductInterface ::NAME ] . $ storeCode ;
169
171
170
172
$ this ->skus [] = $ sku ;
171
173
172
- $ product ['product ' ][Product ::NAME ] = $ newProductName ;
173
- $ product ['product ' ][Product ::TYPE_ID ] = 'virtual ' ;
174
+ $ product ['product ' ][ProductInterface ::NAME ] = $ newProductName ;
175
+ $ product ['product ' ][ProductInterface ::TYPE_ID ] = 'virtual ' ;
174
176
175
177
$ response = $ this ->updateProductAsync ($ product , $ sku , $ storeCode );
176
178
@@ -197,14 +199,14 @@ private function asyncScheduleAndTest($product, $storeCode = null)
197
199
$ serviceInfo = [
198
200
'rest ' => [
199
201
'resourcePath ' => self ::REST_RESOURCE_PATH . '/ ' . $ sku ,
200
- 'httpMethod ' => Request::HTTP_METHOD_GET
202
+ 'httpMethod ' => Request::HTTP_METHOD_GET ,
201
203
]
202
204
];
203
205
$ storeResponse = $ this ->_webApiCall ($ serviceInfo , $ requestData , null , $ checkingStore );
204
206
if ($ checkingStore == $ storeCode || $ storeCode == self ::STORE_CODE_ALL ) {
205
207
$ this ->assertEquals (
206
208
$ newProductName ,
207
- $ storeResponse [Product ::NAME ],
209
+ $ storeResponse [ProductInterface ::NAME ],
208
210
sprintf (
209
211
'Product name in %s store is invalid after updating in store %s. ' ,
210
212
$ checkingStore ,
@@ -214,7 +216,7 @@ private function asyncScheduleAndTest($product, $storeCode = null)
214
216
} else {
215
217
$ this ->assertEquals (
216
218
$ productName ,
217
- $ storeResponse [Product ::NAME ],
219
+ $ storeResponse [ProductInterface ::NAME ],
218
220
sprintf (
219
221
'Product name in %s store is invalid after updating in store %s. ' ,
220
222
$ checkingStore ,
@@ -225,14 +227,20 @@ private function asyncScheduleAndTest($product, $storeCode = null)
225
227
}
226
228
}
227
229
230
+ /**
231
+ * @inheritDoc
232
+ */
228
233
protected function tearDown (): void
229
234
{
230
235
$ this ->clearProducts ();
231
236
$ this ->publisherConsumerController ->stopConsumers ();
232
237
parent ::tearDown ();
233
238
}
234
239
235
- private function clearProducts ()
240
+ /**
241
+ * @return void
242
+ */
243
+ private function clearProducts (): void
236
244
{
237
245
$ size = $ this ->objectManager ->create (Collection::class)
238
246
->addAttributeToFilter ('sku ' , ['in ' => $ this ->skus ])
@@ -270,7 +278,7 @@ private function clearProducts()
270
278
/**
271
279
* @return array
272
280
*/
273
- public function getProductData ()
281
+ public function getProductData (): array
274
282
{
275
283
$ productBuilder = function ($ data ) {
276
284
return array_replace_recursive (
@@ -280,23 +288,26 @@ public function getProductData()
280
288
};
281
289
282
290
return [
283
- 'product ' =>
284
- $ productBuilder (
285
- [
286
- Product::TYPE_ID => 'simple ' ,
287
- Product::SKU => 'multistore-sku-test-1 ' ,
288
- Product::NAME => 'Test Name ' ,
289
- ]
290
- ),
291
+ 'product ' => $ productBuilder (
292
+ [
293
+ ProductInterface::TYPE_ID => 'simple ' ,
294
+ ProductInterface::SKU => 'multistore-sku-test-1 ' ,
295
+ ProductInterface::NAME => 'Test Name ' ,
296
+ ]
297
+ ),
291
298
];
292
299
}
293
300
294
- public function storeProvider ()
301
+ /**
302
+ * @return array
303
+ */
304
+ public function storeProvider (): array
295
305
{
296
306
$ dataSets = [];
297
307
foreach ($ this ->stores as $ store ) {
298
308
$ dataSets [$ store ] = [$ store ];
299
309
}
310
+
300
311
return $ dataSets ;
301
312
}
302
313
@@ -306,28 +317,28 @@ public function storeProvider()
306
317
* @param array $productData
307
318
* @return array
308
319
*/
309
- private function getSimpleProductData ($ productData = [])
320
+ private function getSimpleProductData ($ productData = []): array
310
321
{
311
322
return [
312
- Product::SKU => isset ($ productData [Product::SKU ])
313
- ? $ productData [Product::SKU ] : uniqid ('sku- ' , true ),
314
- Product::NAME => isset ($ productData [Product::NAME ])
315
- ? $ productData [Product::NAME ] : uniqid ('sku- ' , true ),
316
- Product::VISIBILITY => 4 ,
317
- Product::TYPE_ID => 'simple ' ,
318
- Product::PRICE => 3.62 ,
319
- Product::STATUS => 1 ,
320
- Product::TYPE_ID => 'simple ' ,
321
- Product::ATTRIBUTE_SET_ID => 4 ,
323
+ ProductInterface::SKU => isset ($ productData [ProductInterface::SKU ])
324
+ ? $ productData [ProductInterface::SKU ] : uniqid ('sku- ' , true ),
325
+ ProductInterface::NAME => isset ($ productData [ProductInterface::NAME ])
326
+ ? $ productData [ProductInterface::NAME ] : uniqid ('sku- ' , true ),
327
+ ProductInterface::VISIBILITY => 4 ,
328
+ ProductInterface::TYPE_ID => 'simple ' ,
329
+ ProductInterface::PRICE => 3.62 ,
330
+ ProductInterface::STATUS => 1 ,
331
+ ProductInterface::ATTRIBUTE_SET_ID => 4 ,
322
332
];
323
333
}
324
334
325
335
/**
326
- * @param $requestData
336
+ * @param array $requestData
337
+ * @param string $sku
327
338
* @param string|null $storeCode
328
339
* @return mixed
329
340
*/
330
- private function updateProductAsync ($ requestData , $ sku , $ storeCode = null )
341
+ private function updateProductAsync (array $ requestData , string $ sku , $ storeCode = null )
331
342
{
332
343
$ serviceInfo = [
333
344
'rest ' => [
@@ -339,40 +350,19 @@ private function updateProductAsync($requestData, $sku, $storeCode = null)
339
350
return $ this ->_webApiCall ($ serviceInfo , $ requestData , null , $ storeCode );
340
351
}
341
352
342
- public function assertProductCreation ($ product )
353
+ /**
354
+ * @param array $product
355
+ * @return bool
356
+ */
357
+ public function assertProductCreation (array $ product ): bool
343
358
{
344
- $ sku = $ product ['product ' ][Product ::SKU ];
359
+ $ sku = $ product ['product ' ][ProductInterface ::SKU ];
345
360
$ collection = $ this ->objectManager ->create (Collection::class)
346
- ->addAttributeToFilter (Product ::SKU , ['eq ' => $ sku ])
347
- ->addAttributeToFilter (Product ::TYPE_ID , ['eq ' => 'virtual ' ])
361
+ ->addAttributeToFilter (ProductInterface ::SKU , ['eq ' => $ sku ])
362
+ ->addAttributeToFilter (ProductInterface ::TYPE_ID , ['eq ' => 'virtual ' ])
348
363
->load ();
349
364
$ size = $ collection ->getSize ();
350
365
351
366
return $ size > 0 ;
352
367
}
353
-
354
- /**
355
- * Remove test store
356
- * //phpcs:disable
357
- */
358
- public static function tearDownAfterClass (): void
359
- {
360
- parent ::tearDownAfterClass ();
361
- //phpcs:enable
362
- /** @var Registry $registry */
363
- $ registry = Bootstrap::getObjectManager ()->get (Registry::class);
364
-
365
- $ registry ->unregister ('isSecureArea ' );
366
- $ registry ->register ('isSecureArea ' , true );
367
-
368
- /** @var Store $store*/
369
- $ store = Bootstrap::getObjectManager ()->create (Store::class);
370
- $ store ->load ('fixturestore ' );
371
- if ($ store ->getId ()) {
372
- $ store ->delete ();
373
- }
374
-
375
- $ registry ->unregister ('isSecureArea ' );
376
- $ registry ->register ('isSecureArea ' , false );
377
- }
378
368
}
0 commit comments