Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigReaderPluginTest.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\Framework\MessageQueue\Consumer\Config\CompositeReader as ConsumerConfigCompositeReader;
12 
13 class ConfigReaderPluginTest extends \PHPUnit\Framework\TestCase
14 {
18  private $plugin;
19 
23  private $objectManagerHelper;
24 
28  private $configMock;
29 
33  private $subjectMock;
34 
35  protected function setUp()
36  {
37  $this->configMock = $this->getMockBuilder(ConfigInterface::class)
38  ->getMockForAbstractClass();
39  $this->subjectMock = $this->getMockBuilder(ConsumerConfigCompositeReader::class)
40  ->disableOriginalConstructor()
41  ->getMock();
42 
43  $this->objectManagerHelper = new ObjectManagerHelper($this);
44  $this->plugin = $this->objectManagerHelper->getObject(
45  ConsumerConfigReaderPlugin::class,
46  ['config' => $this->configMock]
47  );
48  }
49 
50  public function testAfterRead()
51  {
52  $result = ['consumer0' => []];
53  $consumers = [
54  [
55  'name' => 'consumer1',
56  'handlers' => [
57  ['handlerConfig1_1_1', 'handlerConfig1_1_2'],
58  ['handlerConfig1_2_1']
59  ],
60  'queue' => ['item1_1', 'item1_2'],
61  'instance_type' => 'type1',
62  'connection' => 'connection1',
63  'max_messages' => 100
64  ],
65  [
66  'name' => 'consumer2',
67  'handlers' => [],
68  'queue' => ['item2_1'],
69  'instance_type' => 'type2',
70  'connection' => 'connection2',
71  'max_messages' => 2
72  ]
73  ];
74  $finalResult = [
75  'consumer1' => [
76  'name' => 'consumer1',
77  'queue' => ['item1_1', 'item1_2'],
78  'consumerInstance' => 'type1',
79  'handlers' => ['handlerConfig1_1_1', 'handlerConfig1_1_2', 'handlerConfig1_2_1'],
80  'connection' => 'connection1',
81  'maxMessages' => 100
82  ],
83  'consumer2' => [
84  'name' => 'consumer2',
85  'queue' => ['item2_1'],
86  'consumerInstance' => 'type2',
87  'handlers' => [],
88  'connection' => 'connection2',
89  'maxMessages' => 2
90  ],
91  'consumer0' => []
92  ];
93 
94  $this->configMock->expects(static::atLeastOnce())
95  ->method('getConsumers')
96  ->willReturn($consumers);
97 
98  $this->assertEquals($finalResult, $this->plugin->afterRead($this->subjectMock, $result));
99  }
100 }