-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix of Asynchronous opetations status issue #29814
Merged
magento-engcom-team
merged 6 commits into
magento:2.4-develop
from
comwrap:async-opetation-status-issue
Sep 23, 2020
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
09b63c7
Set up operation_key as nullable
nuzil 2450b14
Merge branch '2.4-develop' into async-opetation-status-issue
Neos2007 77d62ef
async-opetation-status-issue Added intagration test for testing savin…
Neos2007 4da31ea
Fix static tests and small alignments
nuzil a0e65ed
Align tests
nuzil 5c87afe
Merge remote-tracking branch 'upstream-nuzil/2.4-develop' into async-…
nuzil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
dev/tests/integration/testsuite/Magento/Catalog/Model/Attribute/Backend/ConsumerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Catalog\Model\Attribute\Backend; | ||
|
||
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; | ||
|
||
class ConsumerTest extends TestCase | ||
{ | ||
const BULK_UUID = '5a12c1bd-a8b5-41d4-8c00-3f5bcaa6d3c8'; | ||
|
||
/** | ||
* @var \Magento\Catalog\Model\Attribute\Backend\Consumer | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var \PHPUnit\Framework\MockObject\MockObject | ||
*/ | ||
private $publisherMock; | ||
|
||
/** | ||
* @var BulkManagement | ||
*/ | ||
private $bulkManagement; | ||
|
||
/** | ||
* @var BulkStatus | ||
*/ | ||
private $bulkStatus; | ||
|
||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var \Magento\Framework\Serialize\SerializerInterface | ||
*/ | ||
private $serializer; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->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(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @nuzil. What do you think about using imports everywhere instead of FQN? Currently, we use both. But I believe we may make the code a little bit more readable by using the same approach for all places.
Just a minor suggestion