8000 Fix test to use REDIS_CLUSTER_HOSTS env variable · symfony/symfony@ad64692 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad64692

Browse files
committed
Fix test to use REDIS_CLUSTER_HOSTS env variable
1 parent b6453d2 commit ad64692

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/Symfony/Component/Cache/Tests/Traits/RedisTraitTest.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
class RedisTraitTest extends TestCase
1919
{
20+
public static function setUpBeforeClass(): void
21+
{
22+
if (!getenv('REDIS_CLUSTER_HOSTS')) {
23+
throw new SkippedTestSuiteError('REDIS_CLUSTER_HOSTS env var is not defined.');
24+
}
25+
}
2026
/**
2127
* @dataProvider provideCreateConnection
2228
*/
@@ -25,6 +31,9 @@ public function testCreateConnection(string $dsn, string $expectedClass)
2531
if (!class_exists($expectedClass)) {
2632
throw new SkippedTestSuiteError(sprintf('The "%s" class is required.', $expectedClass));
2733
}
34+
if (!getenv('REDIS_CLUSTER_HOSTS')) {
35+
throw new SkippedTestSuiteError('REDIS_CLUSTER_HOSTS env var is not defined.');
36+
}
2837

2938
$mock = self::getObjectForTrait(RedisTrait::class);
3039
$connection = $mock::createConnection($dsn);
@@ -34,21 +43,23 @@ public function testCreateConnection(string $dsn, string $expectedClass)
3443

3544
public function provideCreateConnection(): array
3645
{
46+
$hosts = array_map(fn(string $host) => sprintf('host[%s]', $host), explode(' ', getenv('REDIS_CLUSTER_HOSTS')));
47+
3748
return [
3849
[
39-
'dsn' => 'redis:?host[localhost:7000]&redis_cluster=1',
50+
'dsn' => sprintf('redis:?%s&redis_cluster=1', $hosts[0]),
4051
'expectedClass' => '\RedisCluster',
4152
],
4253
[
43-
'dsn' => 'redis:?host[localhost:7000]&redis_cluster=true',
54+
'dsn' => sprintf('redis:?%s&redis_cluster=true', $hosts[0]),
4455
'expectedClass' => '\RedisCluster',
4556
],
4657
[
47-
'dsn' => 'redis:?host[localhost:7000]',
58+
'dsn' => sprintf('redis:?%s', $hosts[0]),
4859
'expectedClass' => '\Redis',
4960
],
5061
[
51-
'dsn' => 'redis:?host[localhost:7000]&host[localhost:7001]',
62+
'dsn' => sprintf('redis:?%s', join('&', array_slice($hosts, 0, 2))),
5263
'expectedClass' => '\RedisArray',
5364
],
5465
];

0 commit comments

Comments
 (0)
0