TopologyInstallerTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Amqp\Test\Unit;
  7. use Magento\Framework\Amqp\TopologyInstaller;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  9. use Magento\Framework\MessageQueue\Topology\ConfigInterface;
  10. use PhpAmqpLib\Exception\AMQPLogicException;
  11. use Psr\Log\LoggerInterface;
  12. /**
  13. * Unit tests for @see \Magento\Framework\Amqp\TopologyInstaller
  14. */
  15. class TopologyInstallerTest extends \PHPUnit\Framework\TestCase
  16. {
  17. /**
  18. * @var \Magento\Framework\Amqp\TopologyInstaller
  19. */
  20. private $topologyInstaller;
  21. /**
  22. * @var ObjectManager
  23. */
  24. private $objectManager;
  25. /**
  26. * @var ConfigInterface | \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. private $topologyConfigMock;
  29. /**
  30. * @var LoggerInterface | \PHPUnit_Framework_MockObject_MockObject
  31. */
  32. private $loggerMock;
  33. /**
  34. * Initialize topology installer.
  35. */
  36. protected function setUp()
  37. {
  38. $this->objectManager = new ObjectManager($this);
  39. $this->topologyConfigMock = $this->createMock(ConfigInterface::class);
  40. $this->loggerMock = $this->createMock(LoggerInterface::class);
  41. $this->topologyInstaller = $this->objectManager->getObject(
  42. TopologyInstaller::class,
  43. ['topologyConfig' => $this->topologyConfigMock, 'logger' => $this->loggerMock]
  44. );
  45. parent::setUp();
  46. }
  47. /**
  48. * Make sure that topology creation errors in log contain actual error message.
  49. */
  50. public function testInstallException()
  51. {
  52. $exceptionMessage = "Exception message";
  53. $this->topologyConfigMock
  54. ->expects($this->once())
  55. ->method('getQueues')
  56. ->willThrowException(new AMQPLogicException($exceptionMessage));
  57. $this->loggerMock
  58. ->expects($this->once())
  59. ->method('error')
  60. ->with($this->stringContains("AMQP topology installation failed: {$exceptionMessage}"));
  61. $this->topologyInstaller->install();
  62. }
  63. }