ConfigReaderPluginTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\Test\Unit\Config\Topology;
  7. use Magento\Framework\MessageQueue\Config\Topology\ConfigReaderPlugin as TopologyConfigReaderPlugin;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  9. use Magento\Framework\MessageQueue\ConfigInterface;
  10. use Magento\Framework\MessageQueue\Topology\Config\CompositeReader as TopologyConfigCompositeReader;
  11. class ConfigReaderPluginTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var TopologyConfigReaderPlugin
  15. */
  16. private $plugin;
  17. /**
  18. * @var ObjectManagerHelper
  19. */
  20. private $objectManagerHelper;
  21. /**
  22. * @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $configMock;
  25. /**
  26. * @var TopologyConfigCompositeReader|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. private $subjectMock;
  29. protected function setUp()
  30. {
  31. $this->configMock = $this->getMockBuilder(ConfigInterface::class)
  32. ->getMockForAbstractClass();
  33. $this->subjectMock = $this->getMockBuilder(TopologyConfigCompositeReader::class)
  34. ->disableOriginalConstructor()
  35. ->setMethods(['getBinds', 'getConnectionByTopic'])
  36. ->getMock();
  37. $this->objectManagerHelper = new ObjectManagerHelper($this);
  38. $this->plugin = $this->objectManagerHelper->getObject(
  39. TopologyConfigReaderPlugin::class,
  40. ['queueConfig' => $this->configMock]
  41. );
  42. }
  43. public function testAfterRead()
  44. {
  45. $binding = [
  46. [
  47. 'queue' => 'catalog_product_removed_queue',
  48. 'exchange' => 'magento-db',
  49. 'topic' => 'catalog.product.removed'
  50. ],
  51. [
  52. 'queue' => 'inventory_qty_counter_queue',
  53. 'exchange' => 'magento',
  54. 'topic' => 'inventory.counter.updated'
  55. ]
  56. ];
  57. $magento = [
  58. 'name' => 'magento',
  59. 'type' => 'topic',
  60. 'connection' => 'amqp',
  61. 'bindings' => []
  62. ];
  63. $dbDefaultBinding = [
  64. 'id' => 'defaultBinding',
  65. 'destinationType' => 'queue',
  66. 'destination' => 'catalog_product_removed_queue',
  67. 'topic' => 'catalog.product.removed',
  68. ];
  69. $amqpDefaultBinding = [
  70. 'id' => 'defaultBinding',
  71. 'destinationType' => 'queue',
  72. 'destination' => 'inventory_qty_counter_queue',
  73. 'topic' => 'inventory.counter.updated',
  74. ];
  75. $result = [
  76. 'magento' => $magento,
  77. 'magento-db--db' => [
  78. 'name' => 'magento-db',
  79. 'type' => 'topic',
  80. 'connection' => 'db',
  81. 'bindings' => [
  82. 'defaultBinding' => $dbDefaultBinding
  83. ]
  84. ],
  85. 'magento--amqp' => [
  86. 'name' => 'magento',
  87. 'type' => 'topic',
  88. 'connection' => 'amqp',
  89. 'bindings' => [
  90. 'defaultBinding' => $amqpDefaultBinding
  91. ]
  92. ]
  93. ];
  94. $expectedResult = [
  95. 'magento' => $magento,
  96. 'magento-db--db' => [
  97. 'name' => 'magento-db',
  98. 'type' => 'topic',
  99. 'connection' => 'db',
  100. 'bindings' => [
  101. 'queue--catalog_product_removed_queue--catalog.product.removed' => [
  102. 'id' => 'queue--catalog_product_removed_queue--catalog.product.removed',
  103. 'destinationType' => 'queue',
  104. 'destination' => 'catalog_product_removed_queue',
  105. 'disabled' => false,
  106. 'topic' => 'catalog.product.removed',
  107. 'arguments' => []
  108. ],
  109. 'defaultBinding' => $dbDefaultBinding
  110. ]
  111. ],
  112. 'magento--amqp' => [
  113. 'name' => 'magento',
  114. 'type' => 'topic',
  115. 'connection' => 'amqp',
  116. 'bindings' => [
  117. 'queue--inventory_qty_counter_queue--inventory.counter.updated' => [
  118. 'id' => 'queue--inventory_qty_counter_queue--inventory.counter.updated',
  119. 'destinationType' => 'queue',
  120. 'destination' => 'inventory_qty_counter_queue',
  121. 'disabled' => false,
  122. 'topic' => 'inventory.counter.updated',
  123. 'arguments' => []
  124. ],
  125. 'defaultBinding' => $amqpDefaultBinding
  126. ]
  127. ]
  128. ];
  129. $this->configMock->expects(static::atLeastOnce())
  130. ->method('getBinds')
  131. ->willReturn($binding);
  132. $this->configMock->expects(static::exactly(2))
  133. ->method('getConnectionByTopic')
  134. ->willReturnMap([
  135. ['catalog.product.removed', 'db'],
  136. ['inventory.counter.updated', 'amqp']
  137. ]);
  138. $this->assertEquals($expectedResult, $this->plugin->afterRead($this->subjectMock, $result));
  139. }
  140. }