Skip to content

Commit 4c8c863

Browse files
authored
Merge pull request vyuldashev#127 from AaronJan/patch-1
[5.4] implement `size()` method
2 parents 911770d + ddf5dd0 commit 4c8c863

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ public function __construct(AMQPStreamConnection $amqpConnection, $config)
7171
*/
7272
public function size($queue = null)
7373
{
74-
// TODO: Implement size() method.
74+
list(, $messageCount) = $this->channel->queue_declare($this->getQueueName($queue), true);
75+
76+
return $messageCount;
7577
}
7678

7779
/**

tests/RabbitMQQueueTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,18 @@ public function setUp()
4848

4949
public function test_size()
5050
{
51-
$this->queue->size();
51+
$messageCount = 5;
52+
$consumerCount = 1;
53+
54+
$this->channel->shouldReceive('queue_declare')->with(
55+
$this->config['queue'],
56+
true
57+
)->once()
58+
->andReturn([$this->config['queue'], $messageCount, $consumerCount]);
59+
60+
$size = $this->queue->size();
61+
62+
$this->assertEquals($messageCount, $size);
5263
}
5364

5465
public function test_push()

0 commit comments

Comments
 (0)