22 private $communicationConfig;
27 private $publisherConfig;
37 private $bulkExchange;
46 $this->amqpConfig = $this->getMockBuilder(\
Magento\Framework\Amqp\Config::class)
47 ->disableOriginalConstructor()->getMock();
48 $this->communicationConfig = $this->getMockBuilder(\
Magento\Framework\Communication\ConfigInterface::class)
49 ->disableOriginalConstructor()->getMock();
50 $this->publisherConfig = $this
51 ->getMockBuilder(\
Magento\Framework\MessageQueue\Publisher\ConfigInterface::class)
52 ->disableOriginalConstructor()->getMock();
53 $this->exchange = $this->getMockBuilder(\
Magento\Framework\Amqp\Exchange::class)
54 ->disableOriginalConstructor()->getMock();
56 $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
58 \
Magento\Framework\Amqp\Bulk\Exchange::class,
60 'amqpConfig' => $this->amqpConfig,
61 'communicationConfig' => $this->communicationConfig,
62 'publisherConfig' => $this->publisherConfig,
63 'exchange' => $this->exchange,
75 $topicName =
'topic.name';
76 $exchangeName =
'exchangeName';
77 $envelopeBody =
'envelopeBody';
78 $envelopeProperties = [
'property_key_1' =>
'property_value_1'];
82 $this->communicationConfig->expects($this->once())
83 ->method(
'getTopic')->with($topicName)->willReturn($topicData);
84 $channel = $this->getMockBuilder(\AMQPChannel::class)
85 ->setMethods([
'batch_basic_publish',
'publish_batch'])
86 ->disableOriginalConstructor()->getMock();
87 $this->amqpConfig->expects($this->once())->method(
'getChannel')->willReturn($channel);
89 ->getMockBuilder(\
Magento\Framework\MessageQueue\Publisher\
Config\PublisherConfigItemInterface::class)
90 ->disableOriginalConstructor()->getMock();
91 $this->publisherConfig->expects($this->once())
92 ->method(
'getPublisher')->with($topicName)->willReturn($publisher);
94 ->getMockBuilder(\
Magento\Framework\MessageQueue\Publisher\
Config\PublisherConnectionInterface::class)
95 ->disableOriginalConstructor()->getMock();
96 $publisher->expects($this->once())->method(
'getConnection')->with()->willReturn(
$connection);
97 $connection->expects($this->once())->method(
'getExchange')->with()->willReturn($exchangeName);
99 ->getMockBuilder(\
Magento\Framework\MessageQueue\EnvelopeInterface::class)
100 ->disableOriginalConstructor()->getMock();
101 $envelope->expects($this->once())->method(
'getBody')->willReturn($envelopeBody);
102 $envelope->expects($this->once())->method(
'getProperties')->willReturn($envelopeProperties);
103 $channel->expects($this->once())->method(
'batch_basic_publish')
104 ->with($this->isInstanceOf(\PhpAmqpLib\Message\AMQPMessage::class), $exchangeName, $topicName);
105 $channel->expects($this->once())->method(
'publish_batch');
106 $this->assertNull($this->bulkExchange->enqueue($topicName, [$envelope]));
116 $topicName =
'topic.name';
121 $this->communicationConfig->expects($this->once())
122 ->method(
'getTopic')->with($topicName)->willReturn($topicData);
124 ->getMockBuilder(\
Magento\Framework\MessageQueue\EnvelopeInterface::class)
125 ->disableOriginalConstructor()->getMock();
126 $this->exchange->expects($this->once())->method(
'enqueue')->with($topicName, $envelope)->willReturn(
$response);
127 $this->assertEquals([
$response], $this->bulkExchange->enqueue($topicName, [$envelope]));
testEnqueueWithSynchronousTopic()
const TOPIC_IS_SYNCHRONOUS