Skip to content

Commit cdb51f0

Browse files
Merge remote-tracking branch 'origin/MC-34353' into 2.4-develop-pr36
2 parents 9ac97b8 + 101c138 commit cdb51f0

File tree

4 files changed

+54
-27
lines changed

4 files changed

+54
-27
lines changed

lib/internal/Magento/Framework/MessageQueue/Config/Reader/Env.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ public function read($scope = null)
5454
{
5555
$configData = $this->deploymentConfig->getConfigData(self::ENV_QUEUE) ?: [];
5656
if (isset($configData['config'])) {
57-
$configData = $this->publisherConverter->convert($configData = $configData['config']);
57+
$convertedConfigData = $this->publisherConverter->convert($configData['config']);
58+
unset($configData['config']);
59+
$configData = array_replace_recursive($configData, $convertedConfigData);
5860
}
61+
5962
return $configData;
6063
}
6164
}

lib/internal/Magento/Framework/MessageQueue/Config/Reader/Env/Validator.php

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,14 @@ public function __construct(
4040
* @param array $configData
4141
* @param array|null $xmlConfigData
4242
* @return void
43+
* @throws \LogicException
4344
*/
4445
public function validate($configData, array $xmlConfigData = [])
4546
{
4647
if (isset($configData[QueueConfig::TOPICS])) {
4748
foreach ($configData[QueueConfig::TOPICS] as $topicName => $configDataItem) {
48-
$schemaType = $configDataItem[QueueConfig::TOPIC_SCHEMA][QueueConfig::TOPIC_SCHEMA_VALUE];
49-
$responseSchemaType =
50-
$configDataItem[QueueConfig::TOPIC_RESPONSE_SCHEMA][QueueConfig::TOPIC_SCHEMA_VALUE];
49+
$this->validateTopic($topicName, $configDataItem);
5150
$publisherName = $configDataItem[QueueConfig::TOPIC_PUBLISHER];
52-
$this->validateSchemaType($schemaType, $topicName);
53-
$this->validateResponseSchemaType($responseSchemaType, $topicName);
5451
$this->validateTopicPublisher(
5552
$this->getAvailablePublishers($configData, $xmlConfigData),
5653
$publisherName,
@@ -81,14 +78,36 @@ public function validate($configData, array $xmlConfigData = [])
8178
}
8279
}
8380

81+
/**
82+
* Validate topic config data
83+
*
84+
* @param string $topicName
85+
* @param array $configDataItem
86+
* @return void
87+
* @throws \LogicException
88+
*/
89+
private function validateTopic(string $topicName, array $configDataItem): void
90+
{
91+
if (isset($configDataItem[QueueConfig::TOPIC_SCHEMA])) {
92+
$schemaType = $configDataItem[QueueConfig::TOPIC_SCHEMA][QueueConfig::TOPIC_SCHEMA_VALUE];
93+
$this->validateSchemaType($schemaType, $topicName);
94+
}
95+
if (isset($configDataItem[QueueConfig::TOPIC_RESPONSE_SCHEMA])) {
96+
$responseSchemaType = $configDataItem[QueueConfig::TOPIC_RESPONSE_SCHEMA][QueueConfig::TOPIC_SCHEMA_VALUE];
97+
if (null !== $responseSchemaType) {
98+
$this->validateResponseSchemaType($responseSchemaType, $topicName);
99+
}
100+
}
101+
}
102+
84103
/**
85104
* Return all available publishers from xml and env configs
86105
*
87106
* @param array $configData
88107
* @param array $xmlConfigData
89108
* @return array
90109
*/
91-
private function getAvailablePublishers($configData, $xmlConfigData)
110+
private function getAvailablePublishers(array $configData, array $xmlConfigData): array
92111
{
93112
$envConfigPublishers = isset($configData[QueueConfig::PUBLISHERS]) ? $configData[QueueConfig::PUBLISHERS] : [];
94113
$xmlConfigPublishers = isset($xmlConfigData[QueueConfig::PUBLISHERS])
@@ -108,7 +127,7 @@ private function getAvailablePublishers($configData, $xmlConfigData)
108127
* @param array $xmlConfigData
109128
* @return array
110129
*/
111-
private function getAvailableTopics($configData, $xmlConfigData)
130+
private function getAvailableTopics(array $configData, array $xmlConfigData): array
112131
{
113132
$envConfigTopics = isset($configData[QueueConfig::TOPICS]) ? $configData[QueueConfig::TOPICS] : [];
114133
$xmlConfigTopics = isset($xmlConfigData[QueueConfig::TOPICS]) ? $xmlConfigData[QueueConfig::TOPICS] : [];

lib/internal/Magento/Framework/MessageQueue/Config/Topology/ConfigReaderPlugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function afterRead(
4747
$topologyConfigDataFromQueueConfig = $this->getTopologyConfigDataFromQueueConfig();
4848
foreach ($topologyConfigDataFromQueueConfig as $exchangeKey => $exchangeConfig) {
4949
if (isset($result[$exchangeKey])) {
50+
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
5051
$result[$exchangeKey]['bindings'] = array_merge(
5152
$exchangeConfig['bindings'],
5253
$result[$exchangeKey]['bindings']
@@ -80,7 +81,7 @@ private function getTopologyConfigDataFromQueueConfig()
8081
'arguments' => []
8182
];
8283

83-
$exchangeName = $queueConfigBinding['exchange'];
84+
$exchangeName = $this->queueConfig->getExchangeByTopic($topic);
8485
$connection = $this->queueConfig->getConnectionByTopic($topic);
8586
if (isset($result[$exchangeName . '--' . $connection])) {
8687
$result[$exchangeName . '--' . $connection]['bindings'][$bindingId] = $bindingData;

lib/internal/Magento/Framework/MessageQueue/Test/Unit/Config/Topology/ConfigReaderPluginTest.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
namespace Magento\Framework\MessageQueue\Test\Unit\Config\Topology;
99

1010
use Magento\Framework\MessageQueue\Config\Topology\ConfigReaderPlugin as TopologyConfigReaderPlugin;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1112
use Magento\Framework\MessageQueue\ConfigInterface;
1213
use Magento\Framework\MessageQueue\Topology\Config\CompositeReader as TopologyConfigCompositeReader;
13-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1414
use PHPUnit\Framework\MockObject\MockObject;
1515
use PHPUnit\Framework\TestCase;
1616

@@ -36,14 +36,13 @@ class ConfigReaderPluginTest extends TestCase
3636
*/
3737
private $subjectMock;
3838

39+
/**
40+
* @inheritDoc
41+
*/
3942
protected function setUp(): void
4043
{
41-
$this->configMock = $this->getMockBuilder(ConfigInterface::class)
42-
->getMockForAbstractClass();
43-
$this->subjectMock = $this->getMockBuilder(TopologyConfigCompositeReader::class)
44-
->disableOriginalConstructor()
45-
->setMethods(['getBinds', 'getConnectionByTopic'])
46-
->getMock();
44+
$this->configMock = $this->createMock(ConfigInterface::class);
45+
$this->subjectMock = $this->createMock(TopologyConfigCompositeReader::class);
4746

4847
$this->objectManagerHelper = new ObjectManagerHelper($this);
4948
$this->plugin = $this->objectManagerHelper->getObject(
@@ -52,7 +51,12 @@ protected function setUp(): void
5251
);
5352
}
5453

55-
public function testAfterRead()
54+
/**
55+
* Test get config after read
56+
*
57+
* @return void
58+
*/
59+
public function testAfterRead(): void
5660
{
5761
$binding = [
5862
[
@@ -90,17 +94,13 @@ public function testAfterRead()
9094
'name' => 'magento-db',
9195
'type' => 'topic',
9296
'connection' => 'db',
93-
'bindings' => [
94-
'defaultBinding' => $dbDefaultBinding
95-
]
97+
'bindings' => ['defaultBinding' => $dbDefaultBinding]
9698
],
9799
'magento--amqp' => [
98100
'name' => 'magento',
99101
'type' => 'topic',
100102
'connection' => 'amqp',
101-
'bindings' => [
102-
'defaultBinding' => $amqpDefaultBinding
103-
]
103+
'bindings' => ['defaultBinding' => $amqpDefaultBinding]
104104
]
105105
];
106106
$expectedResult = [
@@ -138,17 +138,21 @@ public function testAfterRead()
138138
]
139139
]
140140
];
141-
142-
$this->configMock->expects(static::atLeastOnce())
141+
$this->configMock->expects($this->atLeastOnce())
143142
->method('getBinds')
144143
->willReturn($binding);
145-
$this->configMock->expects(static::exactly(2))
144+
$this->configMock->expects($this->exactly(2))
145+
->method('getExchangeByTopic')
146+
->willReturnMap([
147+
['catalog.product.removed', 'magento-db'],
148+
['inventory.counter.updated', 'magento']
149+
]);
150+
$this->configMock->expects($this->exactly(2))
146151
->method('getConnectionByTopic')
147152
->willReturnMap([
148153
['catalog.product.removed', 'db'],
149154
['inventory.counter.updated', 'amqp']
150155
]);
151-
152156
$this->assertEquals($expectedResult, $this->plugin->afterRead($this->subjectMock, $result));
153157
}
154158
}

0 commit comments

Comments
 (0)