Skip to content

Commit e8c310a

Browse files
committed
Merge remote-tracking branch 'l3/MC-40788' into L3-PR-20210310
2 parents 4f17e02 + d56f33f commit e8c310a

File tree

4 files changed

+165
-0
lines changed

4 files changed

+165
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/queue.xsd">
9+
<broker topic="media.content.synchronization" exchange="magento-db" type="db">
10+
<queue name="media.content.synchronization" consumer="media.content.synchronization" consumerInstance="Magento\Framework\MessageQueue\Consumer" handler="Magento\MediaContentSynchronization\Model\Consume::execute" />
11+
</broker>
12+
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/queue.xsd">
9+
<broker topic="media.gallery.renditions.update" exchange="magento-db" type="db">
10+
<queue name="media.gallery.renditions.update" consumer="media.gallery.renditions.update" consumerInstance="Magento\Framework\MessageQueue\Consumer" handler="Magento\MediaGalleryRenditions\Model\Queue\UpdateRenditions::execute" />
11+
</broker>
12+
</config>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework-message-queue:etc/queue.xsd">
9+
<broker topic="media.gallery.synchronization" exchange="magento-db" type="db">
10+
<queue name="media.gallery.synchronization" consumer="media.gallery.synchronization" consumerInstance="Magento\Framework\MessageQueue\Consumer" handler="Magento\MediaGallerySynchronization\Model\Consume::execute" />
11+
</broker>
12+
</config>
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Framework\MessageQueue;
10+
11+
use Magento\Framework\App\DeploymentConfig\FileReader;
12+
use Magento\Framework\App\DeploymentConfig\Writer;
13+
use Magento\Framework\App\Filesystem\DirectoryList;
14+
use Magento\Framework\Config\File\ConfigFilePool;
15+
use Magento\Framework\Filesystem;
16+
use Magento\Framework\MessageQueue\Config;
17+
use Magento\Framework\MessageQueue\Config\Data;
18+
use Magento\Framework\MessageQueue\Config\Reader\Xml;
19+
use Magento\TestFramework\Helper\Bootstrap;
20+
use PHPUnit\Framework\TestCase;
21+
22+
class ConfigGetConsumersTest extends TestCase
23+
{
24+
/**
25+
* @var \Magento\Framework\ObjectManagerInterface
26+
*/
27+
private $objectManager;
28+
/**
29+
* @var Config
30+
*/
31+
private $configSubject;
32+
33+
/**
34+
* @var FileReader
35+
*/
36+
private $fileReader;
37+
/**
38+
* @var array
39+
*/
40+
private $envConfigBackup;
41+
42+
/**
43+
* @var Writer
44+
*/
45+
private $fileWriter;
46+
47+
/**
48+
* @var Xml
49+
*/
50+
private $xmlReader;
51+
52+
/**
53+
* @inheritdoc
54+
*/
55+
protected function setUp(): void
56+
{
57+
$this->objectManager = Bootstrap::getObjectManager();
58+
$this->fileWriter = $this->objectManager->get(Writer::class);
59+
$this->xmlReader = $this->objectManager->create(Xml::class);
60+
$this->fileReader = $this->objectManager->get(FileReader::class);
61+
62+
$this->envConfigBackup = $this->fileReader->load(ConfigFilePool::APP_ENV);
63+
$customEnvConfig = $this->buildCustomEnvConfigWithConsumers();
64+
$this->fileWriter->saveConfig([ConfigFilePool::APP_ENV => $customEnvConfig]);
65+
66+
/** @var Data data */
67+
$configData = $this->objectManager->create(
68+
Data::class,
69+
[
70+
'cacheId' => uniqid(microtime())
71+
]
72+
);
73+
74+
$this->configSubject = $this->objectManager->create(
75+
Config::class,
76+
[
77+
'queueConfigData' => $configData
78+
]
79+
);
80+
}
81+
82+
public function testGetConsumers(): void
83+
{
84+
$consumers = $this->configSubject->getConsumers();
85+
86+
foreach ($consumers as $consumer) {
87+
$this->assertIsString($consumer['name']);
88+
$this->assertIsArray($consumer['handlers']);
89+
}
90+
}
91+
92+
/**
93+
* @inheritdoc
94+
*/
95+
protected function tearDown(): void
96+
{
97+
$filesystem = $this->objectManager->get(Filesystem::class);
98+
$configFilePool = $this->objectManager->get(ConfigFilePool::class);
99+
$filesystem->getDirectoryWrite(DirectoryList::CONFIG)->writeFile(
100+
$configFilePool->getPath(ConfigFilePool::APP_ENV),
101+
"<?php\n return array();\n"
102+
);
103+
$this->fileWriter->saveConfig([ConfigFilePool::APP_ENV => $this->envConfigBackup]);
104+
}
105+
106+
private function buildCustomEnvConfigWithConsumers(): array
107+
{
108+
$data = $this->xmlReader->read();
109+
$names = array_keys($data['consumers']);
110+
$consumers = [];
111+
foreach ($names as $name) {
112+
$consumers[$name] = ['connection' => 'amqp'];
113+
}
114+
115+
return [
116+
'queue' => [
117+
'amqp' => [
118+
'host' => 'localhost',
119+
'port' => '5672',
120+
'user' => 'guest',
121+
'password' => 'guest',
122+
'virtualhost' => '/',
123+
'ssl' => ''
124+
],
125+
'consumers' => $consumers
126+
],
127+
];
128+
}
129+
}

0 commit comments

Comments
 (0)