Skip to content

Commit 72e57bd

Browse files
committed
Merge remote-tracking branch 'origin/MC-24262' into 2.4-develop-pr119
2 parents 10c97b7 + 405f5bb commit 72e57bd

File tree

2 files changed

+96
-106
lines changed

2 files changed

+96
-106
lines changed

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

Lines changed: 77 additions & 92 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,24 @@ 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

95-
$params = array_merge_recursive(
96-
Bootstrap::getInstance()->getAppInitParams(),
97-
['MAGE_DIRS' => ['cache' => ['path' => TESTS_TEMP_DIR . '/cache']]]
98-
);
99-
100-
/** @var PublisherConsumerController publisherConsumerController */
10198
$this->publisherConsumerController = $this->objectManager->create(
10299
PublisherConsumerController::class,
103100
[
104101
'consumers' => $this->consumers,
105-
'logFilePath' => $this->logFilePath,
106-
'appInitParams' => $params,
102+
'logFilePath' => $logFilePath,
103+
'appInitParams' => Bootstrap::getInstance()->getAppInitParams(),
107104
]
108105
);
109-
$this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
106+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
110107

111108
try {
112109
$this->publisherConsumerController->initialize();
@@ -124,21 +121,16 @@ protected function setUp(): void
124121
/**
125122
* @dataProvider storeProvider
126123
* @magentoApiDataFixture Magento/Store/_files/core_fixturestore.php
124+
* @param string|null $storeCode
125+
* @return void
127126
*/
128-
public function testAsyncScheduleBulkMultistore($storeCode)
127+
public function testAsyncScheduleBulkMultistore(?string $storeCode): void
129128
{
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-
}
137129
$product = $this->getProductData();
138130
$this->_markTestAsRestOnly();
139131

140132
/** @var Store $store */
141-
$store = $this->objectManager->create(Store::class);
133+
$store = $this->objectManager->get(Store::class);
142134
$store->load(self::STORE_CODE_FROM_FIXTURE);
143135
$this->assertEquals(
144136
self::STORE_NAME_FROM_FIXTURE,
@@ -147,9 +139,9 @@ public function testAsyncScheduleBulkMultistore($storeCode)
147139
);
148140

149141
try {
150-
/** @var Product $productModel */
142+
/** @var ProductInterface $productModel */
151143
$productModel = $this->objectManager->create(
152-
Product::class,
144+
ProductInterface::class,
153145
['data' => $product['product']]
154146
);
155147
$this->productRepository->save($productModel);
@@ -161,16 +153,21 @@ public function testAsyncScheduleBulkMultistore($storeCode)
161153
$this->clearProducts();
162154
}
163155

164-
private function asyncScheduleAndTest($product, $storeCode = null)
156+
/**
157+
* @param array $product
158+
* @param string|null $storeCode
159+
* @return void
160+
*/
161+
private function asyncScheduleAndTest(array $product, $storeCode = null): void
165162
{
166-
$sku = $product['product'][Product::SKU];
167-
$productName = $product['product'][Product::NAME];
168-
$newProductName = $product['product'][Product::NAME] . $storeCode;
163+
$sku = $product['product'][ProductInterface::SKU];
164+
$productName = $product['product'][ProductInterface::NAME];
165+
$newProductName = $product['product'][ProductInterface::NAME] . $storeCode;
169166

170167
$this->skus[] = $sku;
171168

172-
$product['product'][Product::NAME] = $newProductName;
173-
$product['product'][Product::TYPE_ID] = 'virtual';
169+
$product['product'][ProductInterface::NAME] = $newProductName;
170+
$product['product'][ProductInterface::TYPE_ID] = 'virtual';
174171

175172
$response = $this->updateProductAsync($product, $sku, $storeCode);
176173

@@ -197,14 +194,14 @@ private function asyncScheduleAndTest($product, $storeCode = null)
197194
$serviceInfo = [
198195
'rest' => [
199196
'resourcePath' => self::REST_RESOURCE_PATH . '/' . $sku,
200-
'httpMethod' => Request::HTTP_METHOD_GET
197+
'httpMethod' => Request::HTTP_METHOD_GET,
201198
]
202199
];
203200
$storeResponse = $this->_webApiCall($serviceInfo, $requestData, null, $checkingStore);
204201
if ($checkingStore == $storeCode || $storeCode == self::STORE_CODE_ALL) {
205202
$this->assertEquals(
206203
$newProductName,
207-
$storeResponse[Product::NAME],
204+
$storeResponse[ProductInterface::NAME],
208205
sprintf(
209206
'Product name in %s store is invalid after updating in store %s.',
210207
$checkingStore,
@@ -214,7 +211,7 @@ private function asyncScheduleAndTest($product, $storeCode = null)
214211
} else {
215212
$this->assertEquals(
216213
$productName,
217-
$storeResponse[Product::NAME],
214+
$storeResponse[ProductInterface::NAME],
218215
sprintf(
219216
'Product name in %s store is invalid after updating in store %s.',
220217
$checkingStore,
@@ -225,14 +222,20 @@ private function asyncScheduleAndTest($product, $storeCode = null)
225222
}
226223
}
227224

225+
/**
226+
* @inheritDoc
227+
*/
228228
protected function tearDown(): void
229229
{
230230
$this->clearProducts();
231231
$this->publisherConsumerController->stopConsumers();
232232
parent::tearDown();
233233
}
234234

235-
private function clearProducts()
235+
/**
236+
* @return void
237+
*/
238+
private function clearProducts(): void
236239
{
237240
$size = $this->objectManager->create(Collection::class)
238241
->addAttributeToFilter('sku', ['in' => $this->skus])
@@ -270,7 +273,7 @@ private function clearProducts()
270273
/**
271274
* @return array
272275
*/
273-
public function getProductData()
276+
public function getProductData(): array
274277
{
275278
$productBuilder = function ($data) {
276279
return array_replace_recursive(
@@ -280,23 +283,26 @@ public function getProductData()
280283
};
281284

282285
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-
),
286+
'product' => $productBuilder(
287+
[
288+
ProductInterface::TYPE_ID => 'simple',
289+
ProductInterface::SKU => 'multistore-sku-test-1',
290+
ProductInterface::NAME => 'Test Name ',
291+
]
292+
),
291293
];
292294
}
293295

294-
public function storeProvider()
296+
/**
297+
* @return array
298+
*/
299+
public function storeProvider(): array
295300
{
296301
$dataSets = [];
297302
foreach ($this->stores as $store) {
298303
$dataSets[$store] = [$store];
299304
}
305+
300306
return $dataSets;
301307
}
302308

@@ -306,28 +312,28 @@ public function storeProvider()
306312
* @param array $productData
307313
* @return array
308314
*/
309-
private function getSimpleProductData($productData = [])
315+
private function getSimpleProductData($productData = []): array
310316
{
311317
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,
318+
ProductInterface::SKU => isset($productData[ProductInterface::SKU])
319+
? $productData[ProductInterface::SKU] : uniqid('sku-', true),
320+
ProductInterface::NAME => isset($productData[ProductInterface::NAME])
321+
? $productData[ProductInterface::NAME] : uniqid('sku-', true),
322+
ProductInterface::VISIBILITY => 4,
323+
ProductInterface::TYPE_ID => 'simple',
324+
ProductInterface::PRICE => 3.62,
325+
ProductInterface::STATUS => 1,
326+
ProductInterface::ATTRIBUTE_SET_ID => 4,
322327
];
323328
}
324329

325330
/**
326-
* @param $requestData
331+
* @param array $requestData
332+
* @param string $sku
327333
* @param string|null $storeCode
328334
* @return mixed
329335
*/
330-
private function updateProductAsync($requestData, $sku, $storeCode = null)
336+
private function updateProductAsync(array $requestData, string $sku, $storeCode = null)
331337
{
332338
$serviceInfo = [
333339
'rest' => [
@@ -339,40 +345,19 @@ private function updateProductAsync($requestData, $sku, $storeCode = null)
339345
return $this->_webApiCall($serviceInfo, $requestData, null, $storeCode);
340346
}
341347

342-
public function assertProductCreation($product)
348+
/**
349+
* @param array $product
350+
* @return bool
351+
*/
352+
public function assertProductCreation(array $product): bool
343353
{
344-
$sku = $product['product'][Product::SKU];
354+
$sku = $product['product'][ProductInterface::SKU];
345355
$collection = $this->objectManager->create(Collection::class)
346-
->addAttributeToFilter(Product::SKU, ['eq' => $sku])
347-
->addAttributeToFilter(Product::TYPE_ID, ['eq' => 'virtual'])
356+
->addAttributeToFilter(ProductInterface::SKU, ['eq' => $sku])
357+
->addAttributeToFilter(ProductInterface::TYPE_ID, ['eq' => 'virtual'])
348358
->load();
349359
$size = $collection->getSize();
350360

351361
return $size > 0;
352362
}
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-
}
378363
}

dev/tests/integration/testsuite/Magento/Store/_files/core_fixturestore.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,28 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
use Magento\Store\Model\ResourceModel\Store as StoreResource;
8+
use Magento\Store\Model\StoreFactory;
9+
use Magento\Store\Model\StoreManagerInterface;
710
use Magento\TestFramework\Helper\Bootstrap;
811

9-
/** @var \Magento\Store\Model\StoreManagerInterface $storeManager */
10-
$storeManager = Bootstrap::getObjectManager()->get(\Magento\Store\Model\StoreManagerInterface::class);
11-
12-
/** @var \Magento\Store\Model\Store $store */
13-
$store = Bootstrap::getObjectManager()->create(\Magento\Store\Model\Store::class);
12+
$objectManager = Bootstrap::getObjectManager();
13+
/** @var StoreManagerInterface $storeManager */
14+
$storeManager = $objectManager->get(StoreManagerInterface::class);
15+
/** @var StoreFactory $storeFactory */
16+
$storeFactory = $objectManager->get(StoreFactory::class);
17+
/** @var StoreResource $storeResource */
18+
$storeResource = $objectManager->get(StoreResource::class);
1419
$storeCode = 'fixturestore';
1520

16-
if (!$store->load($storeCode)->getId()) {
17-
$store->setCode($storeCode)
18-
->setWebsiteId($storeManager->getWebsite()->getId())
19-
->setGroupId($storeManager->getWebsite()->getDefaultGroupId())
20-
->setName('Fixture Store')
21-
->setSortOrder(10)
22-
->setIsActive(1);
23-
$store->save();
24-
}
21+
$store = $storeFactory->create();
22+
$store->setCode($storeCode)
23+
->setWebsiteId($storeManager->getWebsite()->getId())
24+
->setGroupId($storeManager->getWebsite()->getDefaultGroupId())
25+
->setName('Fixture Store')
26+
->setSortOrder(10)
27+
->setIsActive(1);
28+
$storeResource->save($store);
2529

30+
$storeManager->reinitStores();
2631
//if test using this fixture relies on full text functionality it is required to explicitly perform re-indexation

0 commit comments

Comments
 (0)