Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigReaderPluginTest.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\Framework\MessageQueue\Topology\Config\CompositeReader as TopologyConfigCompositeReader;
12 
13 class ConfigReaderPluginTest extends \PHPUnit\Framework\TestCase
14 {
18  private $plugin;
19 
23  private $objectManagerHelper;
24 
28  private $configMock;
29 
33  private $subjectMock;
34 
35  protected function setUp()
36  {
37  $this->configMock = $this->getMockBuilder(ConfigInterface::class)
38  ->getMockForAbstractClass();
39  $this->subjectMock = $this->getMockBuilder(TopologyConfigCompositeReader::class)
40  ->disableOriginalConstructor()
41  ->setMethods(['getBinds', 'getConnectionByTopic'])
42  ->getMock();
43 
44  $this->objectManagerHelper = new ObjectManagerHelper($this);
45  $this->plugin = $this->objectManagerHelper->getObject(
46  TopologyConfigReaderPlugin::class,
47  ['queueConfig' => $this->configMock]
48  );
49  }
50 
51  public function testAfterRead()
52  {
53  $binding = [
54  [
55  'queue' => 'catalog_product_removed_queue',
56  'exchange' => 'magento-db',
57  'topic' => 'catalog.product.removed'
58  ],
59  [
60  'queue' => 'inventory_qty_counter_queue',
61  'exchange' => 'magento',
62  'topic' => 'inventory.counter.updated'
63  ]
64  ];
65  $magento = [
66  'name' => 'magento',
67  'type' => 'topic',
68  'connection' => 'amqp',
69  'bindings' => []
70  ];
71  $dbDefaultBinding = [
72  'id' => 'defaultBinding',
73  'destinationType' => 'queue',
74  'destination' => 'catalog_product_removed_queue',
75  'topic' => 'catalog.product.removed',
76  ];
77  $amqpDefaultBinding = [
78  'id' => 'defaultBinding',
79  'destinationType' => 'queue',
80  'destination' => 'inventory_qty_counter_queue',
81  'topic' => 'inventory.counter.updated',
82  ];
83  $result = [
84  'magento' => $magento,
85  'magento-db--db' => [
86  'name' => 'magento-db',
87  'type' => 'topic',
88  'connection' => 'db',
89  'bindings' => [
90  'defaultBinding' => $dbDefaultBinding
91  ]
92  ],
93  'magento--amqp' => [
94  'name' => 'magento',
95  'type' => 'topic',
96  'connection' => 'amqp',
97  'bindings' => [
98  'defaultBinding' => $amqpDefaultBinding
99  ]
100  ]
101  ];
102  $expectedResult = [
103  'magento' => $magento,
104  'magento-db--db' => [
105  'name' => 'magento-db',
106  'type' => 'topic',
107  'connection' => 'db',
108  'bindings' => [
109  'queue--catalog_product_removed_queue--catalog.product.removed' => [
110  'id' => 'queue--catalog_product_removed_queue--catalog.product.removed',
111  'destinationType' => 'queue',
112  'destination' => 'catalog_product_removed_queue',
113  'disabled' => false,
114  'topic' => 'catalog.product.removed',
115  'arguments' => []
116  ],
117  'defaultBinding' => $dbDefaultBinding
118  ]
119  ],
120  'magento--amqp' => [
121  'name' => 'magento',
122  'type' => 'topic',
123  'connection' => 'amqp',
124  'bindings' => [
125  'queue--inventory_qty_counter_queue--inventory.counter.updated' => [
126  'id' => 'queue--inventory_qty_counter_queue--inventory.counter.updated',
127  'destinationType' => 'queue',
128  'destination' => 'inventory_qty_counter_queue',
129  'disabled' => false,
130  'topic' => 'inventory.counter.updated',
131  'arguments' => []
132  ],
133  'defaultBinding' => $amqpDefaultBinding
134  ]
135  ]
136  ];
137 
138  $this->configMock->expects(static::atLeastOnce())
139  ->method('getBinds')
140  ->willReturn($binding);
141  $this->configMock->expects(static::exactly(2))
142  ->method('getConnectionByTopic')
143  ->willReturnMap([
144  ['catalog.product.removed', 'db'],
145  ['inventory.counter.updated', 'amqp']
146  ]);
147 
148  $this->assertEquals($expectedResult, $this->plugin->afterRead($this->subjectMock, $result));
149  }
150 }