/**
* Check if the message is requeued or not correctly.
*
* @dataProvider processMessageProvider
*/
public function testProcessMessage($processFlag, $expectedMethod, $expectedRequeue = null)
{
$amqpConnection = $this->getMockBuilder('\\PhpAmqpLib\\Connection\\AMQPConnection')->disableOriginalConstructor()->getMock();
$amqpChannel = $this->getMockBuilder('\\PhpAmqpLib\\Channel\\AMQPChannel')->disableOriginalConstructor()->getMock();
$consumer = new Consumer($amqpConnection, $amqpChannel);
$callbackFunction = function () use($processFlag) {
return $processFlag;
};
// Create a callback function with a return value set by the data provider.
$consumer->setCallback($callbackFunction);
// Create a default message
$amqpMessage = new AMQPMessage('foo body');
$amqpMessage->delivery_info['channel'] = $amqpChannel;
$amqpMessage->delivery_info['delivery_tag'] = 0;
$amqpChannel->expects($this->any())->method('basic_reject')->will($this->returnCallback(function ($delivery_tag, $requeue) use($expectedMethod, $expectedRequeue) {
\PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_reject');
// Check if this function should be called.
\PHPUnit_Framework_Assert::assertSame($requeue, $expectedRequeue);
// Check if the message should be requeued.
}));
$amqpChannel->expects($this->any())->method('basic_ack')->will($this->returnCallback(function ($delivery_tag) use($expectedMethod) {
\PHPUnit_Framework_Assert::assertSame($expectedMethod, 'basic_ack');
// Check if this function should be called.
}));
$consumer->processMessage($amqpMessage);
}