ExchangeRepositoryTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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\Bulk;
  7. /**
  8. * Unit test for ExchangeRepository.
  9. */
  10. class ExchangeRepositoryTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Framework\MessageQueue\Bulk\ExchangeFactoryInterface|\PHPUnit_Framework_MockObject_MockObject
  14. */
  15. private $exchangeFactory;
  16. /**
  17. * @var \Magento\Framework\MessageQueue\Bulk\ExchangeRepository
  18. */
  19. private $exchangeRepository;
  20. /**
  21. * Set up.
  22. *
  23. * @return void
  24. */
  25. protected function setUp()
  26. {
  27. $this->exchangeFactory = $this
  28. ->getMockBuilder(\Magento\Framework\MessageQueue\Bulk\ExchangeFactoryInterface::class)
  29. ->disableOriginalConstructor()->getMock();
  30. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  31. $this->exchangeRepository = $objectManager->getObject(
  32. \Magento\Framework\MessageQueue\Bulk\ExchangeRepository::class
  33. );
  34. $objectManager->setBackwardCompatibleProperty(
  35. $this->exchangeRepository,
  36. 'exchangeFactory',
  37. $this->exchangeFactory
  38. );
  39. }
  40. /**
  41. * Test for getByConnectionName method.
  42. *
  43. * @return void
  44. */
  45. public function testGetByConnectionName()
  46. {
  47. $connectionName = 'amqp';
  48. $exchange = $this
  49. ->getMockBuilder(\Magento\Framework\Amqp\Bulk\Exchange::class)
  50. ->disableOriginalConstructor()->getMock();
  51. $this->exchangeFactory->expects($this->once())->method('create')->with($connectionName)->willReturn($exchange);
  52. $this->assertEquals($exchange, $this->exchangeRepository->getByConnectionName($connectionName));
  53. }
  54. }