TopologyTest.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. use Magento\TestFramework\MessageQueue\PreconditionFailedException;
  9. /**
  10. * @see dev/tests/integration/_files/Magento/TestModuleMessageQueueConfiguration
  11. * @see dev/tests/integration/_files/Magento/TestModuleMessageQueueConfigOverride
  12. */
  13. class TopologyTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * List of declared exchanges.
  17. *
  18. * @var array
  19. */
  20. private $declaredExchanges;
  21. /**
  22. * @var \Magento\TestFramework\Helper\Amqp
  23. */
  24. private $helper;
  25. protected function setUp()
  26. {
  27. $this->helper = Bootstrap::getObjectManager()->create(\Magento\TestFramework\Helper\Amqp::class);
  28. if (!$this->helper->isAvailable()) {
  29. $this->fail('This test relies on RabbitMQ Management Plugin.');
  30. }
  31. $this->declaredExchanges = $this->helper->getExchanges();
  32. }
  33. /**
  34. * @dataProvider exchangeDataProvider
  35. * @param array $expectedConfig
  36. * @param array $bindingConfig
  37. */
  38. public function testTopologyInstallation(array $expectedConfig, array $bindingConfig)
  39. {
  40. $name = $expectedConfig['name'];
  41. $this->assertArrayHasKey($name, $this->declaredExchanges);
  42. unset($this->declaredExchanges[$name]['message_stats']);
  43. unset($this->declaredExchanges[$name]['user_who_performed_action']);
  44. $this->assertEquals(
  45. $expectedConfig,
  46. $this->declaredExchanges[$name],
  47. 'Invalid exchange configuration: ' . $name
  48. );
  49. $bindings = $this->helper->getExchangeBindings($name);
  50. $bindings = array_map(function ($value) {
  51. unset($value['properties_key']);
  52. return $value;
  53. }, $bindings);
  54. $this->assertEquals(
  55. $bindingConfig,
  56. $bindings,
  57. 'Invalid exchange bindings configuration: ' . $name
  58. );
  59. }
  60. /**
  61. * @return array
  62. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  63. */
  64. public function exchangeDataProvider()
  65. {
  66. return [
  67. 'magento-topic-based-exchange1' => [
  68. 'exchangeConfig' => [
  69. 'name' => 'magento-topic-based-exchange1',
  70. 'vhost' => '/',
  71. 'type' => 'topic',
  72. 'durable' => true,
  73. 'auto_delete' => false,
  74. 'internal' => false,
  75. 'arguments' => [
  76. 'alternate-exchange' => 'magento-log-exchange'
  77. ],
  78. ],
  79. 'bindingConfig' => [
  80. [
  81. 'source' => 'magento-topic-based-exchange1',
  82. 'vhost' => '/',
  83. 'destination' => 'topic-queue1',
  84. 'destination_type' => 'queue',
  85. 'routing_key' => 'anotherTopic1',
  86. 'arguments' => [
  87. 'argument1' => 'value'
  88. ],
  89. ],
  90. ]
  91. ],
  92. 'magento-topic-based-exchange2' => [
  93. 'exchangeConfig' => [
  94. 'name' => 'magento-topic-based-exchange2',
  95. 'vhost' => '/',
  96. 'type' => 'topic',
  97. 'durable' => true,
  98. 'auto_delete' => false,
  99. 'internal' => false,
  100. 'arguments' => [
  101. 'alternate-exchange' => 'magento-log-exchange',
  102. 'arrayValue' => ['10', '20']
  103. ],
  104. ],
  105. 'bindingConfig' => [
  106. [
  107. 'source' => 'magento-topic-based-exchange2',
  108. 'vhost' => '/',
  109. 'destination' => 'topic-queue2',
  110. 'destination_type' => 'queue',
  111. 'routing_key' => 'anotherTopic2',
  112. 'arguments' => [
  113. 'argument1' => 'value',
  114. 'argument2' => true,
  115. 'argument3' => '150',
  116. ],
  117. ],
  118. ]
  119. ],
  120. 'magento-topic-based-exchange3' => [
  121. 'exchangeConfig' => [
  122. 'name' => 'magento-topic-based-exchange3',
  123. 'vhost' => '/',
  124. 'type' => 'topic',
  125. 'durable' => false,
  126. 'auto_delete' => true,
  127. 'internal' => true,
  128. 'arguments' => [],
  129. ],
  130. 'bindingConfig' => [],
  131. ],
  132. 'magento-topic-based-exchange4' => [
  133. 'exchangeConfig' => [
  134. 'name' => 'magento-topic-based-exchange4',
  135. 'vhost' => '/',
  136. 'type' => 'topic',
  137. 'durable' => true,
  138. 'auto_delete' => false,
  139. 'internal' => false,
  140. 'arguments' => [],
  141. ],
  142. 'bindingConfig' => [
  143. [
  144. 'source' => 'magento-topic-based-exchange4',
  145. 'vhost' => '/',
  146. 'destination' => 'topic-queue1',
  147. 'destination_type' => 'queue',
  148. 'routing_key' => '#',
  149. 'arguments' => [
  150. 'test' => 'one'
  151. ],
  152. ],
  153. [
  154. 'source' => 'magento-topic-based-exchange4',
  155. 'vhost' => '/',
  156. 'destination' => 'topic-queue2',
  157. 'destination_type' => 'queue',
  158. 'routing_key' => '*.*.*',
  159. 'arguments' => [],
  160. ],
  161. ]
  162. ],
  163. ];
  164. }
  165. }