From 77d62ef15b1092d8869aa6dfbcd419effd157beb Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 25 Aug 2020 18:01:09 +0300 Subject: [PATCH] async-opetation-status-issue Added intagration test for testing saving bulk operation with not set 'operation_id' during executing \Magento\Catalog\Model\Attribute\Backend\Consumer::process() method. --- .../Model/Attribute/Backend/ConsumerTest.php | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php new file mode 100644 index 0000000000000..ebba99914d705 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php @@ -0,0 +1,149 @@ +objectManager = Bootstrap::getObjectManager(); + $this->publisherMock = $this->getMockForAbstractClass(BulkPublisherInterface::class); + + $this->bulkManagement = $this->objectManager->create( + BulkManagement::class, + [ + 'publisher' => $this->publisherMock + ] + ); + $this->bulkStatus = $this->objectManager->get(BulkStatus::class); + $catalogProductMock = $this->createMock(\Magento\Catalog\Helper\Product::class); + $productFlatIndexerProcessorMock = $this->createMock( + \Magento\Catalog\Model\Indexer\Product\Flat\Processor::class + ); + $productPriceIndexerProcessorMock = $this->createMock( + \Magento\Catalog\Model\Indexer\Product\Price\Processor::class + ); + $operationManagementMock = $this->createMock( + \Magento\Framework\Bulk\OperationManagementInterface::class + ); + $actionMock = $this->createMock(\Magento\Catalog\Model\Product\Action::class); + $loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class); + $this->serializer = $this->objectManager->get(\Magento\Framework\Serialize\SerializerInterface::class); + $entityManager = $this->objectManager->get(\Magento\Framework\EntityManager\EntityManager::class); + $this->model = $this->objectManager->create( + Consumer::class, + [ + 'catalogProduct' => $catalogProductMock, + 'productFlatIndexerProcessor' => $productFlatIndexerProcessorMock, + 'productPriceIndexerProcessor' => $productPriceIndexerProcessorMock, + 'operationManagement' => $operationManagementMock, + 'action' => $actionMock, + 'logger' => $loggerMock, + 'serializer' => $this->serializer, + 'entityManager' => $entityManager + ] + ); + + parent::setUp(); + } + + /** + * Testing saving bulk operation during processing operation by attribute backend consumer + */ + public function testSaveOperationDuringProcess() + { + $operation = $this->prepareUpdateAttributesBulkAndOperation(); + try { + $this->model->process($operation); + } catch (\Exception $e) { + $this->fail(sprintf('Operation save process failed.: %s', $e->getMessage())); + } + $operationStatus = $operation->getStatus(); + $this->assertEquals( + 1, + $this->bulkStatus->getOperationsCountByBulkIdAndStatus(self::BULK_UUID, $operationStatus) + ); + } + + /** + * Schedules test bulk and returns operation + * @return OperationInterface + */ + private function prepareUpdateAttributesBulkAndOperation(): OperationInterface + { + // general bulk information + $bulkUuid = self::BULK_UUID; + $bulkDescription = 'Update attributes for 2 selected products'; + $topicName = 'product_action_attribute.update'; + $userId = 1; + /** @var OperationInterfaceFactory $operationFactory */ + $operationFactory = $this->objectManager->get(OperationInterfaceFactory::class); + $operation = $operationFactory->create(); + $operation->setBulkUuid($bulkUuid) + ->setTopicName($topicName) + ->setSerializedData($this->serializer->serialize( + ['product_ids' => [1,3], 'attributes' => [], 'store_id' => '0'] + )); + $this->bulkManagement->scheduleBulk($bulkUuid, [$operation], $bulkDescription, $userId); + return $operation; + } + + /** + * Clear created bulk and operation + */ + protected function tearDown(): void + { + $this->bulkManagement->deleteBulk(self::BULK_UUID); + parent::tearDown(); + } +}