ConfigTest.php 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\Topology;
  7. use Magento\Framework\MessageQueue\Topology\Config\ExchangeConfigItem\BindingInterface;
  8. /**
  9. * Test of queue topology configuration reading and parsing.
  10. *
  11. * @magentoCache config disabled
  12. */
  13. class ConfigTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var \Magento\Framework\ObjectManagerInterface
  17. */
  18. private $objectManager;
  19. protected function setUp()
  20. {
  21. $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  22. }
  23. public function testGetExchangeByName()
  24. {
  25. /** @var \Magento\Framework\MessageQueue\Topology\ConfigInterface $config */
  26. $config = $this->objectManager->create(\Magento\Framework\MessageQueue\Topology\ConfigInterface::class);
  27. $exchange = $config->getExchange('magento-topic-based-exchange1', 'amqp');
  28. $this->assertEquals('magento-topic-based-exchange1', $exchange->getName());
  29. $this->assertEquals('topic', $exchange->getType());
  30. $this->assertEquals('amqp', $exchange->getConnection());
  31. $exchangeArguments = $exchange->getArguments();
  32. $expectedArguments = ['alternate-exchange' => 'magento-log-exchange'];
  33. $this->assertEquals($expectedArguments, $exchangeArguments);
  34. /** @var BindingInterface $binding */
  35. $binding = current($exchange->getBindings());
  36. $this->assertEquals('topicBasedRouting1', $binding->getId());
  37. $this->assertEquals('anotherTopic1', $binding->getTopic());
  38. $this->assertEquals('queue', $binding->getDestinationType());
  39. $this->assertEquals('topic-queue1', $binding->getDestination());
  40. $bindingArguments = $binding->getArguments();
  41. $expectedArguments = ['argument1' => 'value'];
  42. $this->assertEquals($expectedArguments, $bindingArguments);
  43. }
  44. public function testGetExchangeByNameWithDefaultValues()
  45. {
  46. /** @var \Magento\Framework\MessageQueue\Topology\ConfigInterface $config */
  47. $config = $this->objectManager->create(\Magento\Framework\MessageQueue\Topology\ConfigInterface::class);
  48. $exchange = $config->getExchange('magento-topic-based-exchange2', 'amqp');
  49. $this->assertEquals('magento-topic-based-exchange2', $exchange->getName());
  50. $this->assertEquals('topic', $exchange->getType());
  51. $this->assertEquals('amqp', $exchange->getConnection());
  52. $exchangeArguments = $exchange->getArguments();
  53. $expectedArguments = [
  54. 'alternate-exchange' => 'magento-log-exchange',
  55. 'arrayValue' => [
  56. 'element01' => '10',
  57. 'element02' => '20',
  58. ]
  59. ];
  60. $this->assertEquals($expectedArguments, $exchangeArguments);
  61. /** @var BindingInterface $binding */
  62. $binding = current($exchange->getBindings());
  63. $this->assertEquals('topicBasedRouting2', $binding->getId());
  64. $this->assertEquals('anotherTopic2', $binding->getTopic());
  65. $this->assertEquals('queue', $binding->getDestinationType());
  66. $this->assertEquals('topic-queue2', $binding->getDestination());
  67. $bindingArguments = $binding->getArguments();
  68. $expectedArguments = ['argument1' => 'value', 'argument2' => true, 'argument3' => 150];
  69. $this->assertEquals($expectedArguments, $bindingArguments);
  70. }
  71. public function testGetAllExchanges()
  72. {
  73. /** @var \Magento\Framework\MessageQueue\Topology\ConfigInterface $config */
  74. $config = $this->objectManager->create(\Magento\Framework\MessageQueue\Topology\ConfigInterface::class);
  75. $exchanges = $config->getExchanges();
  76. $expectedResults = ['magento-topic-based-exchange1', 'magento-topic-based-exchange2'];
  77. $actual = [];
  78. foreach ($exchanges as $exchange) {
  79. $actual[] = $exchange->getName();
  80. }
  81. $this->assertEmpty(array_diff($expectedResults, $actual));
  82. }
  83. }