diff --git a/src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php b/src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php index 4e525702aa..81baaac8d9 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/RedisExt/ConnectionTest.php @@ -57,13 +57,8 @@ class ConnectionTest extends TestCase public function testFromDsnWithOptions() { $this->assertEquals( - new Connection(['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1', 'auto_setup' => false], [ - 'host' => 'localhost', - 'port' => 6379, - ], [ - 'serializer' => 2, - ]), - Connection::fromDsn('redis://localhost/queue/group1/consumer1', ['serializer' => 2, 'auto_setup' => false]) + Connection::fromDsn('redis://localhost', ['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1', 'auto_setup' => false, 'serializer' => 2]), + Connection::fromDsn('redis://localhost/queue/group1/consumer1?serializer=2&auto_setup=0') ); } @@ -99,7 +94,21 @@ class ConnectionTest extends TestCase $redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock(); $redis->expects($this->exactly(1))->method('auth') - ->with('password'); + ->with('password') + ->willReturn(true); + + Connection::fromDsn('redis://password@localhost/queue', [], $redis); + } + + public function testFailedAuth() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('Redis connection failed'); + $redis = $this->getMockBuilder(\Redis::class)->disableOriginalConstructor()->getMock(); + + $redis->expects($this->exactly(1))->method('auth') + ->with('password') + ->willReturn(false); Connection::fromDsn('redis://password@localhost/queue', [], $redis); } diff --git a/src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php b/src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php index 59ec9f029d..6864cd1b9c 100644 --- a/src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php +++ b/src/Symfony/Component/Messenger/Transport/RedisExt/Connection.php @@ -20,6 +20,7 @@ use Symfony\Component\Messenger\Exception\TransportException; * * @author Alexander Schranz * @author Antoine Bluchet + * @author Robin Chalas * * @internal * @final @@ -52,8 +53,8 @@ class Connection $this->connection->connect($connectionCredentials['host'] ?? '127.0.0.1', $connectionCredentials['port'] ?? 6379); $this->connection->setOption(\Redis::OPT_SERIALIZER, $redisOptions['serializer'] ?? \Redis::SERIALIZER_PHP); - if (isset($connectionCredentials['auth'])) { - $this->connection->auth($connectionCredentials['auth']); + if (isset($connectionCredentials['auth']) && !$this->connection->auth($connectionCredentials['auth'])) { + throw new InvalidArgumentException(sprintf('Redis connection failed: %s', $redis->getLastError())); } $this->stream = $configuration['stream'] ?? self::DEFAULT_OPTIONS['stream']; @@ -70,9 +71,9 @@ class Connection $pathParts = explode('/', $parsedUrl['path'] ?? ''); - $stream = $pathParts[1] ?? null; - $group = $pathParts[2] ?? null; - $consumer = $pathParts[3] ?? null; + $stream = $pathParts[1] ?? $redisOptions['stream'] ?? null; + $group = $pathParts[2] ?? $redisOptions['group'] ?? null; + $consumer = $pathParts[3] ?? $redisOptions['consumer'] ?? null; $connectionCredentials = [ 'host' => $parsedUrl['host'] ?? '127.0.0.1',