forked from php-enqueue/enqueue-dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[redis] add dsn support for redis transport.
- Loading branch information
Showing
5 changed files
with
226 additions
and
18 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
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
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,135 @@ | ||
<?php | ||
|
||
namespace Enqueue\Redis\Tests; | ||
|
||
use Enqueue\Redis\RedisConnectionFactory; | ||
use Enqueue\Test\ClassExtensionTrait; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* The class contains the factory tests dedicated to configuration. | ||
*/ | ||
class RedisConnectionFactoryConfigTest 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 RedisConnectionFactory(new \stdClass()); | ||
} | ||
|
||
public function testThrowIfSchemeIsNotAmqp() | ||
{ | ||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('The given DSN "http://example.com" is not supported. Must start with "redis:".'); | ||
|
||
new RedisConnectionFactory('http://example.com'); | ||
} | ||
|
||
public function testThrowIfDsnCouldNotBeParsed() | ||
{ | ||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('Failed to parse DSN "redis://:@/"'); | ||
|
||
new RedisConnectionFactory('redis://:@/'); | ||
} | ||
|
||
public function testThrowIfVendorIsInvalid() | ||
{ | ||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('Unsupported redis vendor given. It must be either "predis", "phpredis". Got "invalidVendor"'); | ||
|
||
new RedisConnectionFactory(['vendor' => 'invalidVendor']); | ||
} | ||
|
||
/** | ||
* @dataProvider provideConfigs | ||
* | ||
* @param mixed $config | ||
* @param mixed $expectedConfig | ||
*/ | ||
public function testShouldParseConfigurationAsExpected($config, $expectedConfig) | ||
{ | ||
$factory = new RedisConnectionFactory($config); | ||
|
||
$this->assertAttributeEquals($expectedConfig, 'config', $factory); | ||
} | ||
|
||
public static function provideConfigs() | ||
{ | ||
yield [ | ||
null, | ||
[ | ||
'host' => 'localhost', | ||
'port' => 6379, | ||
'timeout' => null, | ||
'reserved' => null, | ||
'retry_interval' => null, | ||
'vendor' => 'phpredis', | ||
'persisted' => false, | ||
'lazy' => true, | ||
], | ||
]; | ||
|
||
yield [ | ||
'redis:', | ||
[ | ||
'host' => 'localhost', | ||
'port' => 6379, | ||
'timeout' => null, | ||
'reserved' => null, | ||
'retry_interval' => null, | ||
'vendor' => 'phpredis', | ||
'persisted' => false, | ||
'lazy' => true, | ||
], | ||
]; | ||
|
||
yield [ | ||
[], | ||
[ | ||
'host' => 'localhost', | ||
'port' => 6379, | ||
'timeout' => null, | ||
'reserved' => null, | ||
'retry_interval' => null, | ||
'vendor' => 'phpredis', | ||
'persisted' => false, | ||
'lazy' => true, | ||
], | ||
]; | ||
|
||
yield [ | ||
'redis://localhost:1234?foo=bar&lazy=0&persisted=true', | ||
[ | ||
'host' => 'localhost', | ||
'port' => 1234, | ||
'timeout' => null, | ||
'reserved' => null, | ||
'retry_interval' => null, | ||
'vendor' => 'phpredis', | ||
'persisted' => true, | ||
'lazy' => false, | ||
'foo' => 'bar', | ||
], | ||
]; | ||
|
||
yield [ | ||
['host' => 'localhost', 'port' => 1234, 'foo' => 'bar'], | ||
[ | ||
'host' => 'localhost', | ||
'port' => 1234, | ||
'timeout' => null, | ||
'reserved' => null, | ||
'retry_interval' => null, | ||
'vendor' => 'phpredis', | ||
'persisted' => false, | ||
'lazy' => true, | ||
'foo' => 'bar', | ||
], | ||
]; | ||
} | ||
} |