ConfigTest.php 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\MessageQueue\Publisher;
  7. /**
  8. * Test of queue publisher configuration reading and parsing.
  9. *
  10. * @magentoCache config disabled
  11. */
  12. class ConfigTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\Framework\ObjectManagerInterface
  16. */
  17. private $objectManager;
  18. protected function setUp()
  19. {
  20. $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  21. }
  22. public function testGetPublishersWithOneEnabledConnection()
  23. {
  24. /** @var \Magento\Framework\MessageQueue\Publisher\ConfigInterface $config */
  25. $config = $this->objectManager->create(\Magento\Framework\MessageQueue\Publisher\ConfigInterface::class);
  26. $publishers = $config->getPublishers();
  27. $publisher = $config->getPublisher('topic.message.queue.config.01');
  28. $itemFromList = null;
  29. foreach ($publishers as $item) {
  30. if ($item->getTopic() == 'topic.message.queue.config.01') {
  31. $itemFromList = $item;
  32. break;
  33. }
  34. }
  35. $this->assertEquals($publisher, $itemFromList, 'Inconsistent publisher object');
  36. $this->assertEquals('topic.message.queue.config.01', $publisher->getTopic(), 'Incorrect topic name');
  37. $this->assertFalse($publisher->isDisabled(), 'Incorrect publisher state');
  38. /** @var \Magento\Framework\MessageQueue\Publisher\Config\PublisherConnectionInterface $connection */
  39. $connection = $publisher->getConnection();
  40. $this->assertEquals('amqp', $connection->getName(), 'Incorrect connection name');
  41. $this->assertEquals('magento2', $connection->getExchange(), 'Incorrect exchange name');
  42. $this->assertFalse($connection->isDisabled(), 'Incorrect connection status');
  43. }
  44. public function testGetPublisherConnectionWithoutConfiguredExchange()
  45. {
  46. /** @var \Magento\Framework\MessageQueue\Publisher\ConfigInterface $config */
  47. $config = $this->objectManager->create(\Magento\Framework\MessageQueue\Publisher\ConfigInterface::class);
  48. $publisher = $config->getPublisher('topic.message.queue.config.04');
  49. $connection = $publisher->getConnection();
  50. $this->assertEquals('magento', $connection->getExchange(), 'Incorrect exchange name');
  51. }
  52. public function testGetPublishersWithoutEnabledConnection()
  53. {
  54. /** @var \Magento\Framework\MessageQueue\Publisher\ConfigInterface $config */
  55. $config = $this->objectManager->create(\Magento\Framework\MessageQueue\Publisher\ConfigInterface::class);
  56. $publisher = $config->getPublisher('topic.message.queue.config.02');
  57. $this->assertEquals('topic.message.queue.config.02', $publisher->getTopic(), 'Incorrect topic name');
  58. $this->assertFalse($publisher->isDisabled(), 'Incorrect publisher state');
  59. /** @var \Magento\Framework\MessageQueue\Publisher\Config\PublisherConnectionInterface $connection */
  60. $connection = $publisher->getConnection();
  61. $this->assertEquals('amqp', $connection->getName(), 'Incorrect default connection name');
  62. $this->assertEquals('magento', $connection->getExchange(), 'Incorrect default exchange name');
  63. $this->assertFalse($connection->isDisabled(), 'Incorrect connection status');
  64. }
  65. /**
  66. * @expectedException \Magento\Framework\Exception\LocalizedException
  67. * @expectedExceptionMessage Publisher 'topic.message.queue.config.03' is not declared.
  68. */
  69. public function testGetDisabledPublisherThrowsException()
  70. {
  71. /** @var \Magento\Framework\MessageQueue\Publisher\ConfigInterface $config */
  72. $config = $this->objectManager->create(\Magento\Framework\MessageQueue\Publisher\ConfigInterface::class);
  73. $config->getPublisher('topic.message.queue.config.03');
  74. }
  75. }