Skip to content

Commit 74bf81e

Browse files
committed
Added tests for consumer not sending ACKs on return
1 parent 2365003 commit 74bf81e

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

Tests/RabbitMq/ConsumerTest.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ protected function prepareAMQPChannel()
3838
*
3939
* @dataProvider processMessageProvider
4040
*/
41-
public function testProcessMessage($processFlag, $expectedMethod, $expectedRequeue = null)
41+
public function testProcessMessage($processFlag, $expectedMethod = null, $expectedRequeue = null)
4242
{
4343
$amqpConnection = $this->prepareAMQPConnection();
4444
$amqpChannel = $this->prepareAMQPChannel();
@@ -52,18 +52,24 @@ public function testProcessMessage($processFlag, $expectedMethod, $expectedReque
5252
$amqpMessage->delivery_info['channel'] = $amqpChannel;
5353
$amqpMessage->delivery_info['delivery_tag'] = 0;
5454

55-
$amqpChannel->expects($this->any())
56-
->method('basic_reject')
57-
->will($this->returnCallback(function($delivery_tag, $requeue) use ($expectedMethod, $expectedRequeue) {
58-
\PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_reject'); // Check if this function should be called.
59-
\PHPUnit_Framework_Assert::assertSame($requeue, $expectedRequeue); // Check if the message should be requeued.
60-
}));
61-
62-
$amqpChannel->expects($this->any())
63-
->method('basic_ack')
64-
->will($this->returnCallback(function($delivery_tag) use ($expectedMethod) {
65-
\PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_ack'); // Check if this function should be called.
66-
}));
55+
if ($expectedMethod) {
56+
$amqpChannel->expects($this->any())
57+
->method('basic_reject')
58+
->will($this->returnCallback(function ($delivery_tag, $requeue) use ($expectedMethod, $expectedRequeue) {
59+
\PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_reject'); // Check if this function should be called.
60+
\PHPUnit_Framework_Assert::assertSame($requeue, $expectedRequeue); // Check if the message should be requeued.
61+
}));
62+
63+
$amqpChannel->expects($this->any())
64+
->method('basic_ack')
65+
->will($this->returnCallback(function ($delivery_tag) use ($expectedMethod) {
66+
\PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_ack'); // Check if this function should be called.
67+
}));
68+
} else {
69+
$amqpChannel->expects($this->never())->method('basic_reject');
70+
$amqpChannel->expects($this->never())->method('basic_ack');
71+
$amqpChannel->expects($this->never())->method('basic_nack');
72+
}
6773
$eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')
6874
->getMock();
6975
$consumer->setEventDispatcher($eventDispatcher);
@@ -87,6 +93,7 @@ public function processMessageProvider()
8793
array(ConsumerInterface::MSG_ACK, 'basic_ack'), // Remove message from queue only if callback return not false
8894
array(ConsumerInterface::MSG_REJECT_REQUEUE, 'basic_reject', true), // Reject and requeue message to RabbitMQ
8995
array(ConsumerInterface::MSG_REJECT, 'basic_reject', false), // Reject and drop
96+
array(ConsumerInterface::MSG_ACK_SENT), // ack not sent by the consumer but should be sent by the implementer of ConsumerInterface
9097
);
9198
}
9299

0 commit comments

Comments
 (0)