1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\MessageQueue\Publisher;
/**
* Test of queue publisher configuration reading and parsing.
*
* @magentoCache config disabled
*/
class ConfigTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
}
public function testGetPublishersWithOneEnabledConnection()
{
/** @var \Magento\Framework\MessageQueue\Publisher\ConfigInterface $config */
$config = $this->objectManager->create(\Magento\Framework\MessageQueue\Publisher\ConfigInterface::class);
$publishers = $config->getPublishers();
$publisher = $config->getPublisher('topic.message.queue.config.01');
$itemFromList = null;
foreach ($publishers as $item) {
if ($item->getTopic() == 'topic.message.queue.config.01') {
$itemFromList = $item;
break;
}
}
$this->assertEquals($publisher, $itemFromList, 'Inconsistent publisher object');
$this->assertEquals('topic.message.queue.config.01', $publisher->getTopic(), 'Incorrect topic name');
$this->assertFalse($publisher->isDisabled(), 'Incorrect publisher state');
/** @var \Magento\Framework\MessageQueue\Publisher\Config\PublisherConnectionInterface $connection */
$connection = $publisher->getConnection();
$this->assertEquals('amqp', $connection->getName(), 'Incorrect connection name');
$this->assertEquals('magento2', $connection->getExchange(), 'Incorrect exchange name');
$this->assertFalse($connection->isDisabled(), 'Incorrect connection status');
}
public function testGetPublisherConnectionWithoutConfiguredExchange()
{
/** @var \Magento\Framework\MessageQueue\Publisher\ConfigInterface $config */
$config = $this->objectManager->create(\Magento\Framework\MessageQueue\Publisher\ConfigInterface::class);
$publisher = $config->getPublisher('topic.message.queue.config.04');
$connection = $publisher->getConnection();
$this->assertEquals('magento', $connection->getExchange(), 'Incorrect exchange name');
}
public function testGetPublishersWithoutEnabledConnection()
{
/** @var \Magento\Framework\MessageQueue\Publisher\ConfigInterface $config */
$config = $this->objectManager->create(\Magento\Framework\MessageQueue\Publisher\ConfigInterface::class);
$publisher = $config->getPublisher('topic.message.queue.config.02');
$this->assertEquals('topic.message.queue.config.02', $publisher->getTopic(), 'Incorrect topic name');
$this->assertFalse($publisher->isDisabled(), 'Incorrect publisher state');
/** @var \Magento\Framework\MessageQueue\Publisher\Config\PublisherConnectionInterface $connection */
$connection = $publisher->getConnection();
$this->assertEquals('amqp', $connection->getName(), 'Incorrect default connection name');
$this->assertEquals('magento', $connection->getExchange(), 'Incorrect default exchange name');
$this->assertFalse($connection->isDisabled(), 'Incorrect connection status');
}
/**
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage Publisher 'topic.message.queue.config.03' is not declared.
*/
public function testGetDisabledPublisherThrowsException()
{
/** @var \Magento\Framework\MessageQueue\Publisher\ConfigInterface $config */
$config = $this->objectManager->create(\Magento\Framework\MessageQueue\Publisher\ConfigInterface::class);
$config->getPublisher('topic.message.queue.config.03');
}
}