Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,48 @@ public function testSupportsOnlyRedisTransports()

$this->assertTrue($factory->supports('redis://localhost', []));
$this->assertTrue($factory->supports('rediss://localhost', []));
$this->assertTrue($factory->supports('redis:?host[host1:5000]&host[host2:5000]&host[host3:5000]&sentinel_master=test&dbindex=0', []));
$this->assertFalse($factory->supports('sqs://localhost', []));
$this->assertFalse($factory->supports('invalid-dsn', []));
}

/**
* @group integration
*
* @dataProvider createTransportProvider
*/
public function testCreateTransport()
public function testCreateTransport(string $dsn, array $options = [])
{
$this->skipIfRedisUnavailable();

$factory = new RedisTransportFactory();
$serializer = $this->createMock(SerializerInterface::class);
$expectedTransport = new RedisTransport(Connection::fromDsn('redis://'.getenv('REDIS_HOST'), ['stream' => 'bar', 'delete_after_ack' => true]), $serializer);

$this->assertEquals($expectedTransport, $factory->createTransport('redis://'.getenv('REDIS_HOST'), ['stream' => 'bar', 'delete_after_ack' => true], $serializer));
$this->assertEquals(
new RedisTransport(Connection::fromDsn($dsn, $options), $serializer),
$factory->createTransport($dsn, $options, $serializer)
);
}

/**
* @return iterable<array{0: string, 1: array}>
*/
public static function createTransportProvider(): iterable
{
yield 'scheme "redis" without options' => [
'redis://'.getenv('REDIS_HOST'),
[],
];

yield 'scheme "redis" with options' => [
'redis://'.getenv('REDIS_HOST'),
['stream' => 'bar', 'delete_after_ack' => true],
];

yield 'redis_sentinel' => [
'redis:?host['.str_replace(' ', ']&host[', getenv('REDIS_SENTINEL_HOSTS')).']',
['sentinel_master' => getenv('REDIS_SENTINEL_SERVICE')],
];
}

private function skipIfRedisUnavailable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public function createTransport(#[\SensitiveParameter] string $dsn, array $optio

public function supports(#[\SensitiveParameter] string $dsn, array $options): bool
{
return str_starts_with($dsn, 'redis://') || str_starts_with($dsn, 'rediss://');
return str_starts_with($dsn, 'redis:') || str_starts_with($dsn, 'rediss:');
}
}