Skip to content

Commit 26fdd2d

Browse files
committed
Add DequeuerInterface to BaseConsumer.
1 parent f2124c4 commit 26fdd2d

File tree

4 files changed

+84
-3
lines changed

4 files changed

+84
-3
lines changed

RabbitMq/BaseConsumer.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
namespace OldSound\RabbitMqBundle\RabbitMq;
44

5-
use OldSound\RabbitMqBundle\RabbitMq\BaseAmqp;
6-
7-
abstract class BaseConsumer extends BaseAmqp
5+
abstract class BaseConsumer extends BaseAmqp implements DequeuerInterface
86
{
97
protected $target;
108

RabbitMq/DequeuerAwareInterface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace OldSound\RabbitMqBundle\RabbitMq;
4+
5+
interface DequeuerAwareInterface
6+
{
7+
public function setDequeuer(DequeuerInterface $dequeuer);
8+
}

RabbitMq/DequeuerInterface.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace OldSound\RabbitMqBundle\RabbitMq;
4+
5+
interface DequeuerInterface
6+
{
7+
/**
8+
* Stop dequeuing messages.
9+
*
10+
* @return void
11+
*/
12+
public function forceStopConsumer();
13+
14+
/**
15+
* Set idle timeout
16+
*
17+
* @param $idleTimeout
18+
*
19+
* @return void
20+
*/
21+
public function setIdleTimeout($idleTimeout);
22+
23+
/**
24+
* Get current idle timeout
25+
*
26+
* @return int
27+
*/
28+
public function getIdleTimeout();
29+
}

Tests/RabbitMq/BaseConsumerTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace OldSound\RabbitMqBundle\Tests\RabbitMq;
4+
5+
use OldSound\RabbitMqBundle\RabbitMq\BaseConsumer;
6+
7+
class BaseConsumerTest extends \PHPUnit_Framework_TestCase
8+
{
9+
/** @var BaseConsumer */
10+
protected $consumer;
11+
12+
protected function setUp()
13+
{
14+
$amqpConnection = $this->getMockBuilder('\PhpAmqpLib\Connection\AMQPConnection')
15+
->disableOriginalConstructor()
16+
->getMock();
17+
18+
$this->consumer = $this->getMockBuilder('\OldSound\RabbitMqBundle\RabbitMq\BaseConsumer')
19+
->setConstructorArgs(array($amqpConnection))
20+
->getMockForAbstractClass();
21+
}
22+
23+
public function testItExtendsBaseAmqpInterface()
24+
{
25+
$this->assertInstanceOf('OldSound\RabbitMqBundle\RabbitMq\BaseAmqp', $this->consumer);
26+
}
27+
28+
public function testItImplementsDequeuerInterface()
29+
{
30+
$this->assertInstanceOf('OldSound\RabbitMqBundle\RabbitMq\DequeuerInterface', $this->consumer);
31+
}
32+
33+
public function testItsIdleTimeoutIsMutable()
34+
{
35+
$this->assertEquals(0, $this->consumer->getIdleTimeout());
36+
$this->consumer->setIdleTimeout(42);
37+
$this->assertEquals(42, $this->consumer->getIdleTimeout());
38+
}
39+
40+
public function testForceStopConsumer()
41+
{
42+
$this->assertAttributeEquals(false, 'forceStop', $this->consumer);
43+
$this->consumer->forceStopConsumer();
44+
$this->assertAttributeEquals(true, 'forceStop', $this->consumer);
45+
}
46+
}

0 commit comments

Comments
 (0)