Skip to content

Commit f2ad426

Browse files
committed
MC-24262: Async multistore webapi test fails with elasticsearch on CI
1 parent ad29452 commit f2ad426

File tree

1 file changed

+75
-85
lines changed

1 file changed

+75
-85
lines changed

dev/tests/api-functional/testsuite/Magento/WebapiAsync/Model/AsyncScheduleMultiStoreTest.php

Lines changed: 75 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@
88

99
namespace Magento\WebapiAsync\Model;
1010

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;
1713
use Magento\Catalog\Model\ResourceModel\Product\Collection;
14+
use Magento\Framework\ObjectManagerInterface;
1815
use Magento\Framework\Phrase;
1916
use Magento\Framework\Registry;
2017
use Magento\Framework\Webapi\Exception;
21-
use Magento\Catalog\Api\ProductRepositoryInterface;
22-
use Magento\Framework\ObjectManagerInterface;
23-
use Magento\Store\Model\Store;
2418
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;
2525

2626
/**
2727
* Check async request for multistore product creation service, scheduling bulk
@@ -86,27 +86,29 @@ class AsyncScheduleMultiStoreTest extends WebapiAbstract
8686
*/
8787
private $registry;
8888

89+
/**
90+
* @inheritDoc
91+
*/
8992
protected function setUp(): void
9093
{
94+
$logFilePath = TESTS_TEMP_DIR . "/MessageQueueTestLog.txt";
9195
$this->objectManager = Bootstrap::getObjectManager();
92-
$this->logFilePath = TESTS_TEMP_DIR . "/MessageQueueTestLog.txt";
9396
$this->registry = $this->objectManager->get(Registry::class);
9497

9598
$params = array_merge_recursive(
9699
Bootstrap::getInstance()->getAppInitParams(),
97100
['MAGE_DIRS' => ['cache' => ['path' => TESTS_TEMP_DIR . '/cache']]]
98101
);
99102

100-
/** @var PublisherConsumerController publisherConsumerController */
101103
$this->publisherConsumerController = $this->objectManager->create(
102104
PublisherConsumerController::class,
103105
[
104106
'consumers' => $this->consumers,
105-
'logFilePath' => $this->logFilePath,
107+
'logFilePath' => $logFilePath,
106108
'appInitParams' => $params,
107109
]
108110
);
109-
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
111+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
110112

111113
try {
112114
$this->publisherConsumerController->initialize();
@@ -124,16 +126,11 @@ protected function setUp(): void
124126
/**
125127
* @dataProvider storeProvider
126128
* @magentoApiDataFixture Magento/Store/_files/core_fixturestore.php
129+
* @param string|null $storeCode
130+
* @return void
127131
*/
128-
public function testAsyncScheduleBulkMultistore($storeCode)
132+
public function testAsyncScheduleBulkMultistore($storeCode): void
129133
{
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-
}
137134
$product = $this->getProductData();
138135
$this->_markTestAsRestOnly();
139136

@@ -147,9 +144,9 @@ public function testAsyncScheduleBulkMultistore($storeCode)
147144
);
148145

149146
try {
150-
/** @var Product $productModel */
147+
/** @var ProductInterface $productModel */
151148
$productModel = $this->objectManager->create(
152-
Product::class,
149+
ProductInterface::class,
153150
['data' => $product['product']]
154151
);
155152
$this->productRepository->save($productModel);
@@ -161,16 +158,21 @@ public function testAsyncScheduleBulkMultistore($storeCode)
161158
$this->clearProducts();
162159
}
163160

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
165167
{
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;
169171

170172
$this->skus[] = $sku;
171173

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';
174176

175177
$response = $this->updateProductAsync($product, $sku, $storeCode);
176178

@@ -197,14 +199,14 @@ private function asyncScheduleAndTest($product, $storeCode = null)
197199
$serviceInfo = [
198200
'rest' => [
199201
'resourcePath' => self::REST_RESOURCE_PATH . '/' . $sku,
200-
'httpMethod' => Request::HTTP_METHOD_GET
202+
'httpMethod' => Request::HTTP_METHOD_GET,
201203
]
202204
];
203205
$storeResponse = $this->_webApiCall($serviceInfo, $requestData, null, $checkingStore);
204206
if ($checkingStore == $storeCode || $storeCode == self::STORE_CODE_ALL) {
205207
$this->assertEquals(
206208
$newProductName,
207-
$storeResponse[Product::NAME],
209+
$storeResponse[ProductInterface::NAME],
208210
sprintf(
209211
'Product name in %s store is invalid after updating in store %s.',
210212
$checkingStore,
@@ -214,7 +216,7 @@ private function asyncScheduleAndTest($product, $storeCode = null)
214216
} else {
215217
$this->assertEquals(
216218
$productName,
217-
$storeResponse[Product::NAME],
219+
$storeResponse[ProductInterface::NAME],
218220
sprintf(
219221
'Product name in %s store is invalid after updating in store %s.',
220222
$checkingStore,
@@ -225,14 +227,20 @@ private function asyncScheduleAndTest($product, $storeCode = null)
225227
}
226228
}
227229

230+
/**
231+
* @inheritDoc
232+
*/
228233
protected function tearDown(): void
229234
{
230235
$this->clearProducts();
231236
$this->publisherConsumerController->stopConsumers();
232237
parent::tearDown();
233238
}
234239

235-
private function clearProducts()
240+
/**
241+
* @return void
242+
*/
243+
private function clearProducts(): void
236244
{
237245
$size = $this->objectManager->create(Collection::class)
238246
->addAttributeToFilter('sku', ['in' => $this->skus])
@@ -270,7 +278,7 @@ private function clearProducts()
270278
/**
271279
* @return array
272280
*/
273-
public function getProductData()
281+
public function getProductData(): array
274282
{
275283
$productBuilder = function ($data) {
276284
return array_replace_recursive(
@@ -280,23 +288,26 @@ public function getProductData()
280288
};
281289

282290
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+
),
291298
];
292299
}
293300

294-
public function storeProvider()
301+
/**
302+
* @return array
303+
*/
304+
public function storeProvider(): array
295305
{
296306
$dataSets = [];
297307
foreach ($this->stores as $store) {
298308
$dataSets[$store] = [$store];
299309
}
310+
300311
return $dataSets;
301312
}
302313

@@ -306,28 +317,28 @@ public function storeProvider()
306317
* @param array $productData
307318
* @return array
308319
*/
309-
private function getSimpleProductData($productData = [])
320+
private function getSimpleProductData($productData = []): array
310321
{
311322
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,
322332
];
323333
}
324334

325335
/**
326-
* @param $requestData
336+
* @param array $requestData
337+
* @param string $sku
327338
* @param string|null $storeCode
328339
* @return mixed
329340
*/
330-
private function updateProductAsync($requestData, $sku, $storeCode = null)
341+
private function updateProductAsync(array $requestData, string $sku, $storeCode = null)
331342
{
332343
$serviceInfo = [
333344
'rest' => [
@@ -339,40 +350,19 @@ private function updateProductAsync($requestData, $sku, $storeCode = null)
339350
return $this->_webApiCall($serviceInfo, $requestData, null, $storeCode);
340351
}
341352

342-
public function assertProductCreation($product)
353+
/**
354+
* @param array $product
355+
* @return bool
356+
*/
357+
public function assertProductCreation(array $product): bool
343358
{
344-
$sku = $product['product'][Product::SKU];
359+
$sku = $product['product'][ProductInterface::SKU];
345360
$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'])
348363
->load();
349364
$size = $collection->getSize();
350365

351366
return $size > 0;
352367
}
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-
}
378368
}

0 commit comments

Comments
 (0)