Skip to content

Commit fbc694d

Browse files
committed
Do not create channel for lazy socket connection on construct
1 parent 7fdd7c5 commit fbc694d

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

RabbitMq/BaseAmqp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct(AbstractConnection $conn, AMQPChannel $ch = null, $c
6464
$this->conn = $conn;
6565
$this->ch = $ch;
6666

67-
if (!($conn instanceof AMQPLazyConnection)) {
67+
if ($conn->connectOnConstruct()) {
6868
$this->getChannel();
6969
}
7070

Tests/RabbitMq/BaseAmqpTest.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,40 @@
55
use OldSound\RabbitMqBundle\Event\AMQPEvent;
66
use OldSound\RabbitMqBundle\RabbitMq\BaseAmqp;
77
use OldSound\RabbitMqBundle\RabbitMq\Consumer;
8-
use PhpAmqpLib\Connection\AMQPLazyConnection;
98

109
class BaseAmqpTest extends \PHPUnit_Framework_TestCase
1110
{
12-
/**
13-
* @expectedException \ErrorException
14-
*/
11+
1512
public function testLazyConnection()
1613
{
17-
$amqpLazyConnection = new AMQPLazyConnection('localhost', 123, 'lazy_user', 'lazy_password');
14+
$connection = $this->getMockBuilder('PhpAmqpLib\Connection\AbstractConnection')
15+
->disableOriginalConstructor()
16+
->getMock();
17+
18+
$connection
19+
->method('connectOnConstruct')
20+
->willReturn(false);
21+
$connection
22+
->expects(static::never())
23+
->method('channel');
24+
25+
new Consumer($connection, null);
26+
}
27+
28+
public function testNotLazyConnection()
29+
{
30+
$connection = $this->getMockBuilder('PhpAmqpLib\Connection\AbstractConnection')
31+
->disableOriginalConstructor()
32+
->getMock();
33+
34+
$connection
35+
->method('connectOnConstruct')
36+
->willReturn(true);
37+
$connection
38+
->expects(static::once())
39+
->method('channel');
1840

19-
$consumer = new Consumer($amqpLazyConnection, null);
20-
$consumer->getChannel();
41+
new Consumer($connection, null);
2142
}
2243

2344
public function testDispatchEvent()
@@ -26,7 +47,7 @@ public function testDispatchEvent()
2647
$baseAmqpConsumer = $this->getMockBuilder('OldSound\RabbitMqBundle\RabbitMq\BaseAmqp')
2748
->disableOriginalConstructor()
2849
->getMock();
29-
$eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcher')
50+
$eventDispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')
3051
->disableOriginalConstructor()
3152
->getMock();
3253
$baseAmqpConsumer->expects($this->atLeastOnce())

0 commit comments

Comments
 (0)