Skip to content

Commit fa00ff7

Browse files
🔃 [Magento Community Engineering] Community Contributions - 2.4-develop daily delivery
Accepted Community Pull Requests: - #26160: Changing the data type for quote column customer_note (by @ravi-chandra3197) - #26157: Remove blank space at the end of label (by @gihovani) - #26136: Code refactor, updated Unit Test with JsonHexTag Serializer (by @srsathish92) - #26154: [LayeredNavigation] Covering the ProductAttributeGridBuildObserver for LayeredNavigation � (by @eduard13) - #26150: [CatalogInventory] Covering the InvalidatePriceIndexUponConfigChangeObserver for Catalog� (by @eduard13) - #26148: [Bundle] Covering the SetAttributeTabBlockObserver for Bundles by Unit Test (by @eduard13) - #26127: [Weee] Cover Weee Plugin by Unit Test (by @edenduong) - #26140: [ImportExport] Cover Export Source Model by Unit Test (by @edenduong) - #25864: Adobe stock integration Issue-761: Highlight the selected image in the grid (by @serhiyzhovnir) - #26028: Refactor: Remove deprecated methods (by @andrewbess) - #26128: Refactor Magento Version module (+ Unit Tests) (by @lbajsarowicz) - #26096: [Checkout] Covering the ResetQuoteAddresses by Unit Test (by @eduard13) - #24849: Simplify some conditional checks (by @DanielRuf) Fixed GitHub Issues: - #26155: Table quote column customer_note uses wrong type (reported by @seppoviuh) has been fixed in #26160 by @ravi-chandra3197 in 2.4-develop branch Related commits: 1. 0621d52 - #761: A more verbose message when the db is not up to date. (reported by @tzyganu) has been fixed in #25864 by @serhiyzhovnir in 2.4-develop branch Related commits: 1. 2be7779 2. 83fadc4 3. a7f6e2d 4. ee115fe 5. 21bc869
2 parents 946c6ba + 3119437 commit fa00ff7

File tree

25 files changed

+1312
-172
lines changed

25 files changed

+1312
-172
lines changed

app/code/Magento/AsynchronousOperations/Model/OperationProcessor.php

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,24 @@
88

99
namespace Magento\AsynchronousOperations\Model;
1010

11-
use Magento\Framework\Serialize\Serializer\Json;
1211
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
13-
use Magento\Framework\Bulk\OperationManagementInterface;
1412
use Magento\AsynchronousOperations\Model\ConfigInterface as AsyncConfig;
15-
use Magento\Framework\MessageQueue\MessageValidator;
16-
use Magento\Framework\MessageQueue\MessageEncoder;
17-
use Magento\Framework\Exception\NoSuchEntityException;
18-
use Magento\Framework\MessageQueue\ConsumerConfigurationInterface;
19-
use Psr\Log\LoggerInterface;
20-
use Magento\Framework\Exception\LocalizedException;
21-
use Magento\Framework\Exception\TemporaryStateExceptionInterface;
13+
use Magento\Framework\Bulk\OperationManagementInterface;
14+
use Magento\Framework\Communication\ConfigInterface as CommunicationConfig;
2215
use Magento\Framework\DB\Adapter\ConnectionException;
2316
use Magento\Framework\DB\Adapter\DeadlockException;
2417
use Magento\Framework\DB\Adapter\LockWaitException;
18+
use Magento\Framework\Exception\LocalizedException;
19+
use Magento\Framework\Exception\NoSuchEntityException;
20+
use Magento\Framework\MessageQueue\ConsumerConfigurationInterface;
21+
use Magento\Framework\MessageQueue\MessageEncoder;
22+
use Magento\Framework\MessageQueue\MessageValidator;
23+
use Magento\Framework\Serialize\Serializer\Json;
2524
use Magento\Framework\Webapi\ServiceOutputProcessor;
26-
use Magento\Framework\Communication\ConfigInterface as CommunicationConfig;
25+
use Psr\Log\LoggerInterface;
2726

2827
/**
29-
* Class OperationProcessor
28+
* Proccess operation
3029
*
3130
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3231
*/
@@ -80,9 +79,9 @@ class OperationProcessor
8079
* @param ConsumerConfigurationInterface $configuration
8180
* @param Json $jsonHelper
8281
* @param OperationManagementInterface $operationManagement
83-
* @param LoggerInterface $logger
8482
* @param \Magento\Framework\Webapi\ServiceOutputProcessor $serviceOutputProcessor
8583
* @param \Magento\Framework\Communication\ConfigInterface $communicationConfig
84+
* @param LoggerInterface $logger
8685
*/
8786
public function __construct(
8887
MessageValidator $messageValidator,
@@ -137,7 +136,9 @@ public function process(string $encodedMessage)
137136
$result = $this->executeHandler($callback, $entityParams);
138137
$status = $result['status'];
139138
$errorCode = $result['error_code'];
139+
// phpcs:disable Magento2.Performance.ForeachArrayMerge
140140
$messages = array_merge($messages, $result['messages']);
141+
// phpcs:enable Magento2.Performance.ForeachArrayMerge
141142
$outputData = $result['output_data'];
142143
}
143144
}
@@ -174,8 +175,8 @@ public function process(string $encodedMessage)
174175
/**
175176
* Execute topic handler
176177
*
177-
* @param $callback
178-
* @param $entityParams
178+
* @param callable $callback
179+
* @param array $entityParams
179180
* @return array
180181
*/
181182
private function executeHandler($callback, $entityParams)
@@ -187,7 +188,9 @@ private function executeHandler($callback, $entityParams)
187188
'output_data' => null
188189
];
189190
try {
191+
// phpcs:disable Magento2.Functions.DiscouragedFunction
190192
$result['output_data'] = call_user_func_array($callback, $entityParams);
193+
// phpcs:enable Magento2.Functions.DiscouragedFunction
191194
$result['messages'][] = sprintf('Service execution success %s::%s', get_class($callback[0]), $callback[1]);
192195
} catch (\Zend_Db_Adapter_Exception $e) {
193196
$this->logger->critical($e->getMessage());
@@ -206,9 +209,7 @@ private function executeHandler($callback, $entityParams)
206209
}
207210
} catch (NoSuchEntityException $e) {
208211
$this->logger->error($e->getMessage());
209-
$result['status'] = ($e instanceof TemporaryStateExceptionInterface) ?
210-
OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED :
211-
OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED;
212+
$result['status'] = OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED;
212213
$result['error_code'] = $e->getCode();
213214
$result['messages'][] = $e->getMessage();
214215
} catch (LocalizedException $e) {
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Bundle\Test\Unit\Observer;
9+
10+
use Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Attributes;
11+
use Magento\Bundle\Observer\SetAttributeTabBlockObserver;
12+
use Magento\Catalog\Helper\Catalog;
13+
use Magento\Catalog\Model\Product;
14+
use Magento\Catalog\Model\Product\Type;
15+
use Magento\Framework\Event;
16+
use Magento\Framework\Event\Observer;
17+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
18+
use PHPUnit\Framework\MockObject\MockObject;
19+
use PHPUnit\Framework\TestCase;
20+
21+
/**
22+
* Class SetAttributeTabBlockObserverTest
23+
*
24+
* Test setting attribute tab block for bundle products
25+
*/
26+
class SetAttributeTabBlockObserverTest extends TestCase
27+
{
28+
/**
29+
* @var SetAttributeTabBlockObserver
30+
*/
31+
private $observer;
32+
33+
/**
34+
* @var Catalog|MockObject
35+
*/
36+
private $helperCatalogMock;
37+
38+
/**
39+
* @var Observer|MockObject
40+
*/
41+
private $observerMock;
42+
43+
/**
44+
* @var Event|MockObject
45+
*/
46+
private $eventMock;
47+
48+
/**
49+
* @var Product|MockObject
50+
*/
51+
private $productMock;
52+
53+
/**
54+
* Set Up
55+
*/
56+
public function setUp()
57+
{
58+
$objectManager = new ObjectManager($this);
59+
$this->helperCatalogMock = $this->createMock(Catalog::class);
60+
$this->observerMock = $this->createMock(Observer::class);
61+
$this->eventMock = $this->getMockBuilder(Event::class)
62+
->disableOriginalConstructor()
63+
->setMethods(['getProduct'])
64+
->getMock();
65+
$this->productMock = $this->getMockBuilder(Product::class)
66+
->disableOriginalConstructor()
67+
->getMock();
68+
69+
$this->observer = $objectManager->getObject(
70+
SetAttributeTabBlockObserver::class,
71+
[
72+
'helperCatalog' => $this->helperCatalogMock
73+
]
74+
);
75+
}
76+
77+
/**
78+
* Test setting attribute tab block for bundle product
79+
*/
80+
public function testAddingAttributeTabForBundleProduct()
81+
{
82+
$this->productMock->expects($this->any())
83+
->method('getTypeId')
84+
->willReturn(Type::TYPE_BUNDLE);
85+
$this->eventMock->expects($this->any())
86+
->method('getProduct')
87+
->willReturn($this->productMock);
88+
$this->observerMock->expects($this->any())
89+
->method('getEvent')
90+
->willReturn($this->eventMock);
91+
$this->helperCatalogMock->expects($this->once())
92+
->method('setAttributeTabBlock')
93+
->with(Attributes::class);
94+
95+
$this->observer->execute($this->observerMock);
96+
}
97+
98+
/**
99+
* Test setting attribute tab block for a non bundle product
100+
*/
101+
public function testAddingAttributeTabForNonBundleProduct()
102+
{
103+
$this->productMock->expects($this->any())
104+
->method('getTypeId')
105+
->willReturn(Type::TYPE_VIRTUAL);
106+
$this->eventMock->expects($this->any())
107+
->method('getProduct')
108+
->willReturn($this->productMock);
109+
$this->observerMock->expects($this->any())
110+
->method('getEvent')
111+
->willReturn($this->eventMock);
112+
$this->helperCatalogMock->expects($this->never())
113+
->method('setAttributeTabBlock');
114+
115+
$this->observer->execute($this->observerMock);
116+
}
117+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogInventory\Test\Unit\Observer;
9+
10+
use Magento\Catalog\Model\Indexer\Product\Price\Processor;
11+
use Magento\CatalogInventory\Model\Configuration;
12+
use Magento\CatalogInventory\Observer\InvalidatePriceIndexUponConfigChangeObserver;
13+
use Magento\Framework\Event;
14+
use Magento\Framework\Event\Observer;
15+
use Magento\Framework\Indexer\IndexerInterface;
16+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
17+
use PHPUnit\Framework\MockObject\MockObject;
18+
use PHPUnit\Framework\TestCase;
19+
20+
/**
21+
* Class InvalidatePriceIndexUponConfigChangeObserverTest
22+
*
23+
* Testing invalidating product price index onn config changing
24+
*/
25+
class InvalidatePriceIndexUponConfigChangeObserverTest extends TestCase
26+
{
27+
/**
28+
* @var InvalidatePriceIndexUponConfigChangeObserver
29+
*/
30+
private $observer;
31+
32+
/**
33+
* @var Processor|MockObject
34+
*/
35+
private $priceIndexProcessorMock;
36+
37+
/**
38+
* @var Observer|MockObject
39+
*/
40+
private $observerMock;
41+
42+
/**
43+
* @var Event|MockObject
44+
*/
45+
private $eventMock;
46+
47+
/**
48+
* @var IndexerInterface|MockObject
49+
*/
50+
private $indexerMock;
51+
52+
/**
53+
* Set Up
54+
*/
55+
public function setUp()
56+
{
57+
$objectManager = new ObjectManager($this);
58+
$this->priceIndexProcessorMock = $this->createMock(Processor::class);
59+
$this->indexerMock = $this->getMockBuilder(IndexerInterface::class)
60+
->getMockForAbstractClass();
61+
$this->observerMock = $this->createMock(Observer::class);
62+
$this->eventMock = $this->getMockBuilder(Event::class)
63+
->disableOriginalConstructor()
64+
->setMethods(['getChangedPaths'])
65+
->getMock();
66+
67+
$this->observer = $objectManager->getObject(
68+
InvalidatePriceIndexUponConfigChangeObserver::class,
69+
[
70+
'priceIndexProcessor' => $this->priceIndexProcessorMock
71+
]
72+
);
73+
}
74+
75+
/**
76+
* Testing invalidating product price index on catalog inventory config changes
77+
*/
78+
public function testInvalidatingPriceOnChangingOutOfStockConfig()
79+
{
80+
$changedPaths = [Configuration::XML_PATH_SHOW_OUT_OF_STOCK];
81+
82+
$this->eventMock->expects($this->once())
83+
->method('getChangedPaths')
84+
->willReturn($changedPaths);
85+
$this->observerMock->expects($this->once())
86+
->method('getEvent')
87+
->willReturn($this->eventMock);
88+
$this->indexerMock->expects($this->once())
89+
->method('invalidate');
90+
$this->priceIndexProcessorMock->expects($this->once())
91+
->method('getIndexer')
92+
->willReturn($this->indexerMock);
93+
94+
$this->observer->execute($this->observerMock);
95+
}
96+
97+
/**
98+
* Testing invalidating product price index on changing any other config
99+
*/
100+
public function testInvalidatingPriceOnChangingAnyOtherConfig()
101+
{
102+
$changedPaths = [Configuration::XML_PATH_ITEM_AUTO_RETURN];
103+
104+
$this->eventMock->expects($this->once())
105+
->method('getChangedPaths')
106+
->willReturn($changedPaths);
107+
$this->observerMock->expects($this->once())
108+
->method('getEvent')
109+
->willReturn($this->eventMock);
110+
$this->indexerMock->expects($this->never())
111+
->method('invalidate');
112+
$this->priceIndexProcessorMock->expects($this->never())
113+
->method('getIndexer')
114+
->willReturn($this->indexerMock);
115+
116+
$this->observer->execute($this->observerMock);
117+
}
118+
}

0 commit comments

Comments
 (0)