-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
1,262 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*~ | ||
/composer.lock | ||
/composer.phar | ||
/phpunit.xml | ||
/vendor/ | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
sudo: false | ||
|
||
git: | ||
depth: 1 | ||
|
||
language: php | ||
|
||
php: | ||
- '5.6' | ||
- '7.0' | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache | ||
|
||
install: | ||
- composer self-update | ||
- composer install --prefer-source --ignore-platform-reqs | ||
|
||
script: | ||
- vendor/bin/phpunit --exclude-group=functional |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,281 @@ | ||
<?php | ||
|
||
namespace Enqueue\AmqpLib\Tests; | ||
|
||
use Enqueue\AmqpLib\AmqpConnectionFactory; | ||
use Enqueue\Test\ClassExtensionTrait; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* The class contains the factory tests dedicated to configuration. | ||
*/ | ||
class AmqpConnectionFactoryConfigTest extends TestCase | ||
{ | ||
use ClassExtensionTrait; | ||
|
||
public function testThrowNeitherArrayStringNorNullGivenAsConfig() | ||
{ | ||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('The config must be either an array of options, a DSN string or null'); | ||
|
||
new AmqpConnectionFactory(new \stdClass()); | ||
} | ||
|
||
public function testThrowIfSchemeIsNotAmqp() | ||
{ | ||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('The given DSN scheme "http" is not supported. Could be "amqp" only.'); | ||
|
||
new AmqpConnectionFactory('http://example.com'); | ||
} | ||
|
||
public function testThrowIfDsnCouldNotBeParsed() | ||
{ | ||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('Failed to parse DSN "amqp://:@/"'); | ||
|
||
new AmqpConnectionFactory('amqp://:@/'); | ||
} | ||
|
||
public function testThrowIfReceiveMenthodIsInvalid() | ||
{ | ||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('Invalid "receive_method" option value "invalidMethod". It could be only "basic_get", "basic_consume"'); | ||
|
||
new AmqpConnectionFactory(['receive_method' => 'invalidMethod']); | ||
} | ||
|
||
/** | ||
* @dataProvider provideConfigs | ||
* | ||
* @param mixed $config | ||
* @param mixed $expectedConfig | ||
*/ | ||
public function testShouldParseConfigurationAsExpected($config, $expectedConfig) | ||
{ | ||
$factory = new AmqpConnectionFactory($config); | ||
|
||
$this->assertAttributeEquals($expectedConfig, 'config', $factory); | ||
} | ||
|
||
public static function provideConfigs() | ||
{ | ||
yield [ | ||
null, | ||
[ | ||
'host' => 'localhost', | ||
'port' => 5672, | ||
'vhost' => '/', | ||
'user' => 'guest', | ||
'pass' => 'guest', | ||
'read_timeout' => 3, | ||
'write_timeout' => 3, | ||
'lazy' => true, | ||
'receive_method' => 'basic_get', | ||
'stream' => true, | ||
'insist' => false, | ||
'login_method' => 'AMQPLAIN', | ||
'login_response' => null, | ||
'locale' => 'en_US', | ||
'keepalive' => false, | ||
'heartbeat' => 0, | ||
'connection_timeout' => 3.0, | ||
'read_write_timeout' => 3.0, | ||
], | ||
]; | ||
|
||
// some examples from Appendix A: Examples (https://www.rabbitmq.com/uri-spec.html) | ||
|
||
yield [ | ||
'amqp://user:pass@host:10000/vhost', | ||
[ | ||
'host' => 'host', | ||
'port' => 10000, | ||
'vhost' => 'vhost', | ||
'user' => 'user', | ||
'pass' => 'pass', | ||
'read_timeout' => 3, | ||
'write_timeout' => 3, | ||
'lazy' => true, | ||
'receive_method' => 'basic_get', | ||
'stream' => true, | ||
'insist' => false, | ||
'login_method' => 'AMQPLAIN', | ||
'login_response' => null, | ||
'locale' => 'en_US', | ||
'keepalive' => false, | ||
'heartbeat' => 0, | ||
'connection_timeout' => 3.0, | ||
'read_write_timeout' => 3.0, | ||
], | ||
]; | ||
|
||
yield [ | ||
'amqp://user%61:%61pass@ho%61st:10000/v%2fhost', | ||
[ | ||
'host' => 'hoast', | ||
'port' => 10000, | ||
'vhost' => 'v/host', | ||
'user' => 'usera', | ||
'pass' => 'apass', | ||
'read_timeout' => 3, | ||
'write_timeout' => 3, | ||
'lazy' => true, | ||
'receive_method' => 'basic_get', | ||
'stream' => true, | ||
'insist' => false, | ||
'login_method' => 'AMQPLAIN', | ||
'login_response' => null, | ||
'locale' => 'en_US', | ||
'keepalive' => false, | ||
'heartbeat' => 0, | ||
'connection_timeout' => 3.0, | ||
'read_write_timeout' => 3.0, | ||
], | ||
]; | ||
|
||
yield [ | ||
'amqp://', | ||
[ | ||
'host' => 'localhost', | ||
'port' => 5672, | ||
'vhost' => '/', | ||
'user' => 'guest', | ||
'pass' => 'guest', | ||
'read_timeout' => 3, | ||
'write_timeout' => 3, | ||
'lazy' => true, | ||
'receive_method' => 'basic_get', | ||
'stream' => true, | ||
'insist' => false, | ||
'login_method' => 'AMQPLAIN', | ||
'login_response' => null, | ||
'locale' => 'en_US', | ||
'keepalive' => false, | ||
'heartbeat' => 0, | ||
'connection_timeout' => 3.0, | ||
'read_write_timeout' => 3.0, | ||
], | ||
]; | ||
|
||
yield [ | ||
'amqp://user:pass@host:10000/vhost?connection_timeout=2&lazy=', | ||
[ | ||
'host' => 'host', | ||
'port' => 10000, | ||
'vhost' => 'vhost', | ||
'user' => 'user', | ||
'pass' => 'pass', | ||
'read_timeout' => 3, | ||
'write_timeout' => 3, | ||
'lazy' => '', | ||
'receive_method' => 'basic_get', | ||
'stream' => true, | ||
'insist' => false, | ||
'login_method' => 'AMQPLAIN', | ||
'login_response' => null, | ||
'locale' => 'en_US', | ||
'keepalive' => false, | ||
'heartbeat' => 0, | ||
'connection_timeout' => '2', | ||
'read_write_timeout' => 3.0, | ||
], | ||
]; | ||
|
||
yield [ | ||
[], | ||
[ | ||
'host' => 'localhost', | ||
'port' => 5672, | ||
'vhost' => '/', | ||
'user' => 'guest', | ||
'pass' => 'guest', | ||
'read_timeout' => 3, | ||
'write_timeout' => 3, | ||
'lazy' => true, | ||
'receive_method' => 'basic_get', | ||
'stream' => true, | ||
'insist' => false, | ||
'login_method' => 'AMQPLAIN', | ||
'login_response' => null, | ||
'locale' => 'en_US', | ||
'keepalive' => false, | ||
'heartbeat' => 0, | ||
'connection_timeout' => 3.0, | ||
'read_write_timeout' => 3.0, | ||
], | ||
]; | ||
|
||
yield [ | ||
['lazy' => false, 'host' => 'host'], | ||
[ | ||
'host' => 'host', | ||
'port' => 5672, | ||
'vhost' => '/', | ||
'user' => 'guest', | ||
'pass' => 'guest', | ||
'read_timeout' => 3, | ||
'write_timeout' => 3, | ||
'lazy' => false, | ||
'receive_method' => 'basic_get', | ||
'stream' => true, | ||
'insist' => false, | ||
'login_method' => 'AMQPLAIN', | ||
'login_response' => null, | ||
'locale' => 'en_US', | ||
'keepalive' => false, | ||
'heartbeat' => 0, | ||
'connection_timeout' => 3.0, | ||
'read_write_timeout' => 3.0, | ||
], | ||
]; | ||
|
||
yield [ | ||
['connection_timeout' => 123, 'read_write_timeout' => 321], | ||
[ | ||
'host' => 'localhost', | ||
'port' => 5672, | ||
'vhost' => '/', | ||
'user' => 'guest', | ||
'pass' => 'guest', | ||
'read_timeout' => 3, | ||
'write_timeout' => 3, | ||
'lazy' => true, | ||
'receive_method' => 'basic_get', | ||
'stream' => true, | ||
'insist' => false, | ||
'login_method' => 'AMQPLAIN', | ||
'login_response' => null, | ||
'locale' => 'en_US', | ||
'keepalive' => false, | ||
'heartbeat' => 0, | ||
'connection_timeout' => 123, | ||
'read_write_timeout' => 321, | ||
], | ||
]; | ||
|
||
yield [ | ||
'amqp://user:pass@host:10000/vhost?connection_timeout=123&read_write_timeout=321', | ||
[ | ||
'host' => 'host', | ||
'port' => 10000, | ||
'vhost' => 'vhost', | ||
'user' => 'user', | ||
'pass' => 'pass', | ||
'read_timeout' => 3, | ||
'write_timeout' => 3, | ||
'lazy' => true, | ||
'receive_method' => 'basic_get', | ||
'stream' => true, | ||
'insist' => false, | ||
'login_method' => 'AMQPLAIN', | ||
'login_response' => null, | ||
'locale' => 'en_US', | ||
'keepalive' => false, | ||
'heartbeat' => 0, | ||
'connection_timeout' => '123', | ||
'read_write_timeout' => '321', | ||
], | ||
]; | ||
} | ||
} |
Oops, something went wrong.