Skip to content
This repository has been archived by the owner on Jul 28, 2022. It is now read-only.

Commit

Permalink
Do not use deprecated getChannel method. (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
makasim authored and OskarStark committed Nov 20, 2018
1 parent bc957e5 commit 7306003
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
6 changes: 5 additions & 1 deletion src/Backend/AMQPBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ public function getIterator()
$this->consumer = $this->getContext()->createConsumer($this->getContext()->createQueue($this->queue));
$this->consumer->setConsumerTag('sonata_notification_'.uniqid());

return new AMQPMessageIterator($this->getChannel(), $this->consumer);
if (!$context instanceof \Enqueue\AmqpLib\AmqpContext) {
throw new \LogicException('The BC layer works only if enqueue/amqp-lib lib is being used.');
}

return new AMQPMessageIterator($context->getLibChannel(), $this->consumer);
}

/**
Expand Down
19 changes: 10 additions & 9 deletions tests/Backend/AMQPBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
namespace Sonata\NotificationBundle\Tests\Backend;

use Enqueue\AmqpLib\AmqpConnectionFactory;
use Enqueue\AmqpLib\AmqpConsumer;
use Enqueue\AmqpLib\AmqpContext;
use Interop\Amqp\AmqpBind;
use Interop\Amqp\AmqpConsumer;
use Interop\Amqp\AmqpContext;
use Interop\Amqp\AmqpQueue;
use Interop\Amqp\AmqpTopic;
use Interop\Amqp\Impl\AmqpBind as ImplAmqpBind;
Expand Down Expand Up @@ -259,6 +259,10 @@ public function testGetIteratorWithNoPrefetchCount()
->with($this->identicalTo($queue))
->willReturn($consumerMock);

$contextMock->expects($this->once())
->method('getLibChannel')
->willReturn($this->createMock(AMQPChannel::class));

AmqpConnectionFactoryStub::$context = $contextMock;

$iterator = $backend->getIterator();
Expand Down Expand Up @@ -290,6 +294,10 @@ public function testGetIteratorWithPrefetchCount()
->with($this->identicalTo($queue))
->willReturn($consumerMock);

$contextMock->expects($this->once())
->method('getLibChannel')
->willReturn($this->createMock(AMQPChannel::class));

AmqpConnectionFactoryStub::$context = $contextMock;

$iterator = $backend->getIterator();
Expand Down Expand Up @@ -328,15 +336,8 @@ protected function buildBackend($recover = false, $deadLetterExchange = null, $d

$dispatcherMock = $this->getMockBuilder(AMQPBackendDispatcher::class)
->setConstructorArgs([$settings, $queues, 'default', [['type' => self::KEY, 'backend' => $backend]]])
->setMethods(['getChannel'])
->getMock();

$dispatcherMock
->expects($this->any())
->method('getChannel')
->willReturn($this->createMock(AMQPChannel::class))
;

$backend->setDispatcher($dispatcherMock);

return $backend;
Expand Down

0 comments on commit 7306003

Please sign in to comment.