20 private $objectManager;
35 $this->communicationConfigMock = $this->getMockBuilder(CommunicationConfig::class)
36 ->disableOriginalConstructor()
38 $this->consumerConfigMock = $this->getMockBuilder(ConsumerConfig::class)
39 ->disableOriginalConstructor()
49 $consumerFactory = $this->objectManager->getObject(ConsumerFactory::class);
50 $this->objectManager->setBackwardCompatibleProperty(
52 'communicationConfig',
53 $this->communicationConfigMock
55 $this->objectManager->setBackwardCompatibleProperty(
58 $this->consumerConfigMock
60 $consumerFactory->get(self::TEST_CONSUMER_NAME);
65 $consumerType =
'async';
66 $consumerTypeValue = \Magento\Framework\MessageQueue\Model\TestConsumer::class;
69 'type' => [$consumerType => $consumerTypeValue]
72 $consumerFactory = $this->getConsumerFactoryInstance($consumers);
73 $consumerInstanceMock = $this->getMockBuilder($consumerTypeValue)->getMock();
74 $this->assertInstanceOf(get_class($consumerInstanceMock), $consumerFactory->get(self::TEST_CONSUMER_NAME));
83 private function getConsumerFactoryInstance($consumers)
85 $consumerTypeValue = \Magento\Framework\MessageQueue\Model\TestConsumer::class;
86 $handlerTypeValue = \Magento\Framework\DataObject::class;
87 $consumerType =
'async';
90 $consumerConfigItemMock = $this->getMockBuilder(ConsumerConfigItem::class)->disableOriginalConstructor()
92 $consumerConfigItemMock->expects($this->any())->method(
'getName')->willReturn(self::TEST_CONSUMER_NAME);
93 $consumerConfigItemMock->expects($this->any())->method(
'getQueue')->willReturn(self::TEST_CONSUMER_QUEUE);
94 $consumerConfigItemMock->expects($this->any())->method(
'getConsumerInstance')->willReturn($consumerTypeValue);
95 $consumerConfigItemMock->expects($this->any())->method(
'getHandlers')->willReturn([]);
96 $this->consumerConfigMock->expects($this->any())
97 ->method(
'getConsumer')
98 ->with(
'test_consumer_name')
99 ->willReturn($consumerConfigItemMock);
100 $this->communicationConfigMock->expects($this->any())
101 ->method(
'getTopics')
105 CommunicationConfig::TOPIC_NAME =>
'topicName',
106 CommunicationConfig::TOPIC_IS_SYNCHRONOUS =>
false 110 $this->communicationConfigMock->expects($this->any())
115 CommunicationConfig::TOPIC_HANDLERS => [
117 CommunicationConfig::HANDLER_TYPE => $handlerTypeValue,
118 CommunicationConfig::HANDLER_METHOD => self::TEST_CONSUMER_METHOD
124 $consumerInstanceMock = $this->getMockBuilder($consumerTypeValue)->getMock();
125 $consumerMock = $this->getMockBuilder(\
Magento\Framework\MessageQueue\ConsumerInterface::class)
126 ->setMethods([
'configure'])
127 ->getMockForAbstractClass();
129 $consumerConfigurationMock =
130 $this->getMockBuilder(\
Magento\Framework\MessageQueue\ConsumerConfigurationInterface::class)
131 ->disableOriginalConstructor()
132 ->getMockForAbstractClass();
133 $consumerConfigurationMock->expects($this->any())->method(
'getType')->willReturn($consumerType);
135 $objectManagerMock = $this->getMockBuilder(\
Magento\Framework\ObjectManagerInterface::class)
136 ->setMethods([
'create'])
137 ->getMockForAbstractClass();
139 $objectManagerMock->expects($this->any())
141 ->willReturnOnConsecutiveCalls($consumerMock, $consumerConfigurationMock, $consumerInstanceMock);
143 $consumerFactory = $this->objectManager->getObject(
144 \
Magento\Framework\MessageQueue\ConsumerFactory::class,
146 'objectManager' => $objectManagerMock,
147 'consumers' => $consumers
150 $this->objectManager->setBackwardCompatibleProperty(
152 'communicationConfig',
153 $this->communicationConfigMock
155 $this->objectManager->setBackwardCompatibleProperty(
158 $this->consumerConfigMock
160 return $consumerFactory;
testUndeclaredConsumerName()
const TEST_CONSUMER_QUEUE
testConnectionInjectedForConsumer()
const TEST_CONSUMER_METHOD