Skip to content

Commit ed80391

Browse files
committed
AMQPSocketConnection has a different parameters order, lets consider it
1 parent f8670ca commit ed80391

File tree

3 files changed

+108
-16
lines changed

3 files changed

+108
-16
lines changed

RabbitMq/AMQPConnectionFactory.php

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,40 @@ public function __construct(
6060
*/
6161
public function createConnection()
6262
{
63-
return new $this->class(
64-
$this->parameters['host'],
65-
$this->parameters['port'],
66-
$this->parameters['user'],
67-
$this->parameters['password'],
68-
$this->parameters['vhost'],
69-
false, // insist
70-
'AMQPLAIN', // login_method
71-
null, // login_response
72-
'en_US', // locale
73-
$this->parameters['connection_timeout'],
74-
$this->parameters['read_write_timeout'],
75-
$this->parameters['ssl_context'],
76-
$this->parameters['keepalive'],
77-
$this->parameters['heartbeat']
78-
);
63+
if ($this->class == 'PhpAmqpLib\Connection\AMQPSocketConnection' || is_subclass_of($this->class , 'PhpAmqpLib\Connection\AMQPSocketConnection')) {
64+
return new $this->class(
65+
$this->parameters['host'],
66+
$this->parameters['port'],
67+
$this->parameters['user'],
68+
$this->parameters['password'],
69+
$this->parameters['vhost'],
70+
false, // insist
71+
'AMQPLAIN', // login_method
72+
null, // login_response
73+
'en_US', // locale
74+
isset($this->parameters['read_timeout']) ? $this->parameters['read_timeout'] : $this->parameters['read_write_timeout'],
75+
$this->parameters['keepalive'],
76+
isset($this->parameters['write_timeout']) ? $this->parameters['write_timeout'] : $this->parameters['read_write_timeout'],
77+
$this->parameters['heartbeat']
78+
);
79+
} else {
80+
return new $this->class(
81+
$this->parameters['host'],
82+
$this->parameters['port'],
83+
$this->parameters['user'],
84+
$this->parameters['password'],
85+
$this->parameters['vhost'],
86+
false, // insist
87+
'AMQPLAIN', // login_method
88+
null, // login_response
89+
'en_US', // locale
90+
$this->parameters['connection_timeout'],
91+
$this->parameters['read_write_timeout'],
92+
$this->parameters['ssl_context'],
93+
$this->parameters['keepalive'],
94+
$this->parameters['heartbeat']
95+
);
96+
}
7997
}
8098

8199
/**

Tests/RabbitMq/AMQPConnectionFactoryTest.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use OldSound\RabbitMqBundle\Provider\ConnectionParametersProviderInterface;
66
use OldSound\RabbitMqBundle\RabbitMq\AMQPConnectionFactory;
77
use OldSound\RabbitMqBundle\Tests\RabbitMq\Fixtures\AMQPConnection;
8+
use OldSound\RabbitMqBundle\Tests\RabbitMq\Fixtures\AMQPSocketConnection;
89
use PHPUnit\Framework\TestCase;
910

1011
class AMQPConnectionFactoryTest extends TestCase
@@ -37,6 +38,63 @@ public function testDefaultValues()
3738
), $instance->constructParams);
3839
}
3940

41+
public function testSocketConnection()
42+
{
43+
$factory = new AMQPConnectionFactory(
44+
'OldSound\RabbitMqBundle\Tests\RabbitMq\Fixtures\AMQPSocketConnection',
45+
array()
46+
);
47+
48+
/** @var AMQPSocketConnection $instance */
49+
$instance = $factory->createConnection();
50+
$this->assertInstanceOf('PhpAmqpLib\Connection\AMQPSocketConnection', $instance);
51+
$this->assertEquals(array(
52+
'localhost', // host
53+
5672, // port
54+
'guest', // user
55+
'guest', // password
56+
'/', // vhost
57+
false, // insist
58+
"AMQPLAIN", // login method
59+
null, // login response
60+
"en_US", // locale
61+
3, // read_timeout
62+
false, // keepalive
63+
3, // write_timeout
64+
0, // heartbeat
65+
), $instance->constructParams);
66+
}
67+
68+
public function testSocketConnectionWithParams()
69+
{
70+
$factory = new AMQPConnectionFactory(
71+
'OldSound\RabbitMqBundle\Tests\RabbitMq\Fixtures\AMQPSocketConnection',
72+
array(
73+
'read_timeout' => 31,
74+
'write_timeout' => 32,
75+
)
76+
);
77+
78+
/** @var AMQPSocketConnection $instance */
79+
$instance = $factory->createConnection();
80+
$this->assertInstanceOf('PhpAmqpLib\Connection\AMQPSocketConnection', $instance);
81+
$this->assertEquals(array(
82+
'localhost', // host
83+
5672, // port
84+
'guest', // user
85+
'guest', // password
86+
'/', // vhost
87+
false, // insist
88+
"AMQPLAIN", // login method
89+
null, // login response
90+
"en_US", // locale
91+
31, // read_timeout
92+
false, // keepalive
93+
32, // write_timeout
94+
0, // heartbeat
95+
), $instance->constructParams);
96+
}
97+
4098
public function testStandardConnectionParameters()
4199
{
42100
$factory = new AMQPConnectionFactory(
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace OldSound\RabbitMqBundle\Tests\RabbitMq\Fixtures;
4+
5+
use PhpAmqpLib\Connection\AMQPSocketConnection as BaseAMQPSocketConnection;
6+
7+
class AMQPSocketConnection extends BaseAMQPSocketConnection
8+
{
9+
public $constructParams;
10+
11+
public function __construct()
12+
{
13+
// save params for direct access in tests
14+
$this->constructParams = func_get_args();
15+
}
16+
}

0 commit comments

Comments
 (0)