7 declare(strict_types=1);
60 private $publisherConsumerController;
65 private $productRepository;
70 private $objectManager;
77 protected function setUp()
80 $this->logFilePath = TESTS_TEMP_DIR .
"/MessageQueueTestLog.txt";
81 $this->registry = $this->objectManager->get(Registry::class);
83 $params = array_merge_recursive(
85 [
'MAGE_DIRS' => [
'cache' => [
'path' => TESTS_TEMP_DIR .
'/cache']]]
89 $this->publisherConsumerController = $this->objectManager->create(PublisherConsumerController::class, [
90 'consumers' => $this->consumers,
91 'logFilePath' => $this->logFilePath,
94 $this->productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
97 $this->publisherConsumerController->initialize();
99 $this->markTestSkipped($e->getMessage());
119 $this->clearProducts();
122 $this->assertArrayHasKey(self::BULK_UUID_KEY,
$response);
123 $this->assertNotNull(
$response[self::BULK_UUID_KEY]);
125 $this->assertCount(2,
$response[
'request_items']);
127 $this->assertEquals(
'accepted',
$response[
'request_items'][$key][
'status']);
133 $this->publisherConsumerController->waitForAsynchronousResult(
134 [$this,
'assertProductCreation'],
138 $this->fail(
"Not all products were created");
150 $this->clearProducts();
153 $this->assertArrayHasKey(self::BULK_UUID_KEY,
$response);
154 $this->assertNotNull(
$response[self::BULK_UUID_KEY]);
156 $this->assertCount(1,
$response[
'request_items']);
157 $this->assertEquals(
'accepted',
$response[
'request_items'][0][
'status']);
162 $this->publisherConsumerController->waitForAsynchronousResult(
163 [$this,
'assertProductCreation'],
167 $this->fail(
"Not all products were created");
181 $this->clearProducts();
187 $this->assertEquals(500, $e->getCode());
205 'resourcePath' => self::ASYNC_BULK_RESOURCE_PATH .
'/' . $sku,
214 $this->assertEquals(400, $e->getCode());
221 $this->clearProducts();
222 $this->publisherConsumerController->stopConsumers();
226 private function clearProducts()
228 $size = $this->objectManager->create(Collection::class)
229 ->addAttributeToFilter(
'sku', [
'in' => $this->skus])
237 $this->registry->unregister(
'isSecureArea');
238 $this->registry->register(
'isSecureArea',
true);
240 foreach ($this->skus as $sku) {
241 $this->productRepository->deleteById($sku);
243 }
catch (\Exception $e) {
247 $this->registry->unregister(
'isSecureArea');
249 $size = $this->objectManager->create(Collection::class)
250 ->addAttributeToFilter(
'sku', [
'in' => $this->skus])
255 throw new Exception(
new Phrase(
"Collection size after clearing the products: %size", [
'size' => $size]));
264 $productBuilder =
function (
$data) {
265 return array_replace_recursive(
266 $this->getSimpleProductData(),
283 'product' => $productBuilder([
298 $productBuilder =
function (
$data) {
299 return array_replace_recursive(
300 $this->getSimpleProductData(),
326 $productBuilder =
function (
$data) {
327 return array_replace_recursive(
328 $this->getSimpleProductData(),
333 $wrongProductBuilder =
function (
$data) {
334 return array_replace_recursive(
335 $this->getWrongProductStructureData(),
352 'product' => $productBuilder([
359 $wrongProductBuilder([
360 'wrong_attribute' =>
'simple',
375 [
'psku-test-1',
null],
385 private function getSimpleProductData(
$productData = [])
398 'custom_attributes' => [
399 [
'attribute_code' =>
'cost',
'value' =>
''],
400 [
'attribute_code' =>
'description',
'value' =>
'Description'],
411 private function getWrongProductStructureData(
$productData = [])
438 $collection = $this->objectManager->create(Collection::class)
439 ->addAttributeToFilter(
'sku', [
'in' => $this->skus])
443 return $size == count($this->skus);
451 $collection = $this->objectManager->create(Collection::class)
452 ->addAttributeToFilter(
'sku', [
'in' => $this->skus])
testAsyncScheduleBulkMultipleEntities($products)
_markTestAsRestOnly($message=null)
_webApiCall( $serviceInfo, $arguments=[], $webApiAdapterCode=null, $storeCode=null, $integration=null)
testAsyncScheduleBulkWrongEntity($products)
productSingleCreationProvider()
productsArrayCreationProvider()
testGETRequestToAsyncBulk($sku, $storeCode=null)
testAsyncScheduleBulkSingleEntity($products)
wrongProductCreationProvider()
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
const ASYNC_CONSUMER_NAME
const ASYNC_BULK_RESOURCE_PATH
static getObjectManager()