From 09b63c7e378eea2db2453653b1348eb33e45600d Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Fri, 3 Jul 2020 09:48:44 +0200 Subject: [PATCH 1/4] Set up operation_key as nullable for support B2B implementations --- app/code/Magento/AsynchronousOperations/etc/db_schema.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/AsynchronousOperations/etc/db_schema.xml b/app/code/Magento/AsynchronousOperations/etc/db_schema.xml index 5d49d71ee46b0..ab482d2e2c761 100644 --- a/app/code/Magento/AsynchronousOperations/etc/db_schema.xml +++ b/app/code/Magento/AsynchronousOperations/etc/db_schema.xml @@ -34,7 +34,7 @@ - Date: Tue, 25 Aug 2020 18:01:09 +0300 Subject: [PATCH 2/4] 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(); + } +} From 4da31ea9c11948ca6853524295fa5276c5c5ff9b Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Wed, 9 Sep 2020 14:03:54 +0200 Subject: [PATCH 3/4] Fix static tests and small alignments --- .../Model/Attribute/Backend/ConsumerTest.php | 41 ++++++++++++------- 1 file changed, 27 insertions(+), 14 deletions(-) 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 index ebba99914d705..fd7e01dee6b1e 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php @@ -8,21 +8,34 @@ namespace Magento\Catalog\Model\Attribute\Backend; +use Magento\AsynchronousOperations\Api\Data\OperationInterface; use Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory; -use PHPUnit\Framework\TestCase; -use Magento\TestFramework\Helper\Bootstrap; -use Magento\Framework\ObjectManagerInterface; use Magento\AsynchronousOperations\Model\BulkManagement; use Magento\AsynchronousOperations\Model\BulkStatus; -use Magento\AsynchronousOperations\Api\Data\OperationInterface; use Magento\Framework\MessageQueue\BulkPublisherInterface; +use Magento\Framework\ObjectManagerInterface; +use Magento\TestFramework\Helper\Bootstrap; +use PHPUnit\Framework\TestCase; +use Magento\Catalog\Helper\Product; +use Magento\Catalog\Model\Indexer\Product\Flat\Processor; +use Magento\Framework\Bulk\OperationManagementInterface; +use Magento\Catalog\Model\Product\Action; +use Psr\Log\LoggerInterface; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\EntityManager\EntityManager; +use Magento\Catalog\Model\Attribute\Backend\Consumer; +/** + * Test for Mysql Consumer execution + * + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ class ConsumerTest extends TestCase { const BULK_UUID = '5a12c1bd-a8b5-41d4-8c00-3f5bcaa6d3c8'; /** - * @var \Magento\Catalog\Model\Attribute\Backend\Consumer + * @var Consumer */ private $model; @@ -47,7 +60,7 @@ class ConsumerTest extends TestCase private $objectManager; /** - * @var \Magento\Framework\Serialize\SerializerInterface + * @var SerializerInterface */ private $serializer; @@ -66,20 +79,20 @@ protected function setUp(): void ] ); $this->bulkStatus = $this->objectManager->get(BulkStatus::class); - $catalogProductMock = $this->createMock(\Magento\Catalog\Helper\Product::class); + $catalogProductMock = $this->createMock(Product::class); $productFlatIndexerProcessorMock = $this->createMock( - \Magento\Catalog\Model\Indexer\Product\Flat\Processor::class + Processor::class ); $productPriceIndexerProcessorMock = $this->createMock( - \Magento\Catalog\Model\Indexer\Product\Price\Processor::class + Processor::class ); $operationManagementMock = $this->createMock( - \Magento\Framework\Bulk\OperationManagementInterface::class + 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); + $actionMock = $this->createMock(Action::class); + $loggerMock = $this->createMock(LoggerInterface::class); + $this->serializer = $this->objectManager->get(SerializerInterface::class); + $entityManager = $this->objectManager->get(EntityManager::class); $this->model = $this->objectManager->create( Consumer::class, [ From a0e65ed26f6b31fcff0eec02c72a1da1ffa86938 Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Wed, 9 Sep 2020 17:35:38 +0200 Subject: [PATCH 4/4] Align tests --- .../Catalog/Model/Attribute/Backend/ConsumerTest.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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 index fd7e01dee6b1e..8dffcdbdd4582 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php @@ -17,7 +17,8 @@ use Magento\TestFramework\Helper\Bootstrap; use PHPUnit\Framework\TestCase; use Magento\Catalog\Helper\Product; -use Magento\Catalog\Model\Indexer\Product\Flat\Processor; +use Magento\Catalog\Model\Indexer\Product\Flat\Processor as FlatProcessor; +use Magento\Catalog\Model\Indexer\Product\Price\Processor as PriceProcessor; use Magento\Framework\Bulk\OperationManagementInterface; use Magento\Catalog\Model\Product\Action; use Psr\Log\LoggerInterface; @@ -81,10 +82,10 @@ protected function setUp(): void $this->bulkStatus = $this->objectManager->get(BulkStatus::class); $catalogProductMock = $this->createMock(Product::class); $productFlatIndexerProcessorMock = $this->createMock( - Processor::class + FlatProcessor::class ); $productPriceIndexerProcessorMock = $this->createMock( - Processor::class + PriceProcessor::class ); $operationManagementMock = $this->createMock( OperationManagementInterface::class