ConfigReaderPluginTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\Config\Publisher;
  7. use Magento\Framework\MessageQueue\Config\Publisher\ConfigReaderPlugin as PublisherConfigReaderPlugin;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  9. use Magento\Framework\MessageQueue\ConfigInterface;
  10. use Magento\Framework\MessageQueue\Publisher\Config\CompositeReader as PublisherConfigCompositeReader;
  11. class ConfigReaderPluginTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var PublisherConfigReaderPlugin
  15. */
  16. private $plugin;
  17. /**
  18. * @var ObjectManagerHelper
  19. */
  20. private $objectManagerHelper;
  21. /**
  22. * @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $configMock;
  25. /**
  26. * @var PublisherConfigCompositeReader|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. private $subjectMock;
  29. protected function setUp()
  30. {
  31. $this->configMock = $this->getMockBuilder(ConfigInterface::class)
  32. ->getMockForAbstractClass();
  33. $this->subjectMock = $this->getMockBuilder(PublisherConfigCompositeReader::class)
  34. ->disableOriginalConstructor()
  35. ->getMock();
  36. $this->objectManagerHelper = new ObjectManagerHelper($this);
  37. $this->plugin = $this->objectManagerHelper->getObject(
  38. PublisherConfigReaderPlugin::class,
  39. ['config' => $this->configMock]
  40. );
  41. }
  42. public function testAfterRead()
  43. {
  44. $result = ['topic0' => []];
  45. $binds = [
  46. [
  47. 'topic' => 'topic1',
  48. 'exchange' => 'exchange1'
  49. ],
  50. [
  51. 'topic' => 'topic2',
  52. 'exchange' => 'exchange2'
  53. ]
  54. ];
  55. $finalResult = [
  56. 'topic1' => [
  57. 'topic' => 'topic1',
  58. 'connection' => [
  59. 'name' => 'connection1',
  60. 'exchange' => 'exchange1',
  61. 'disabled' => false
  62. ],
  63. 'disabled' => false
  64. ],
  65. 'topic2' => [
  66. 'topic' => 'topic2',
  67. 'connection' => [
  68. 'name' => 'connection2',
  69. 'exchange' => 'exchange2',
  70. 'disabled' => false
  71. ],
  72. 'disabled' => false
  73. ],
  74. 'topic0' => []
  75. ];
  76. $this->configMock->expects(static::atLeastOnce())
  77. ->method('getBinds')
  78. ->willReturn($binds);
  79. $this->configMock->expects(static::atLeastOnce())
  80. ->method('getConnectionByTopic')
  81. ->willReturnMap(
  82. [
  83. ['topic1', 'connection1'],
  84. ['topic2', 'connection2']
  85. ]
  86. );
  87. $this->assertEquals($finalResult, $this->plugin->afterRead($this->subjectMock, $result));
  88. }
  89. }