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
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\MessageQueue\Test\Unit\Config\Publisher;
use Magento\Framework\MessageQueue\Config\Publisher\ConfigReaderPlugin as PublisherConfigReaderPlugin;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\MessageQueue\ConfigInterface;
use Magento\Framework\MessageQueue\Publisher\Config\CompositeReader as PublisherConfigCompositeReader;
class ConfigReaderPluginTest extends \PHPUnit\Framework\TestCase
{
/**
* @var PublisherConfigReaderPlugin
*/
private $plugin;
/**
* @var ObjectManagerHelper
*/
private $objectManagerHelper;
/**
* @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $configMock;
/**
* @var PublisherConfigCompositeReader|\PHPUnit_Framework_MockObject_MockObject
*/
private $subjectMock;
protected function setUp()
{
$this->configMock = $this->getMockBuilder(ConfigInterface::class)
->getMockForAbstractClass();
$this->subjectMock = $this->getMockBuilder(PublisherConfigCompositeReader::class)
->disableOriginalConstructor()
->getMock();
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->plugin = $this->objectManagerHelper->getObject(
PublisherConfigReaderPlugin::class,
['config' => $this->configMock]
);
}
public function testAfterRead()
{
$result = ['topic0' => []];
$binds = [
[
'topic' => 'topic1',
'exchange' => 'exchange1'
],
[
'topic' => 'topic2',
'exchange' => 'exchange2'
]
];
$finalResult = [
'topic1' => [
'topic' => 'topic1',
'connection' => [
'name' => 'connection1',
'exchange' => 'exchange1',
'disabled' => false
],
'disabled' => false
],
'topic2' => [
'topic' => 'topic2',
'connection' => [
'name' => 'connection2',
'exchange' => 'exchange2',
'disabled' => false
],
'disabled' => false
],
'topic0' => []
];
$this->configMock->expects(static::atLeastOnce())
->method('getBinds')
->willReturn($binds);
$this->configMock->expects(static::atLeastOnce())
->method('getConnectionByTopic')
->willReturnMap(
[
['topic1', 'connection1'],
['topic2', 'connection2']
]
);
$this->assertEquals($finalResult, $this->plugin->afterRead($this->subjectMock, $result));
}
}