17
17
18
18
class RedisTraitTest extends TestCase
19
19
{
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
+ }
20
26
/**
21
27
* @dataProvider provideCreateConnection
22
28
*/
@@ -25,6 +31,9 @@ public function testCreateConnection(string $dsn, string $expectedClass)
25
31
if (!class_exists ($ expectedClass )) {
26
32
throw new SkippedTestSuiteError (sprintf ('The "%s" class is required. ' , $ expectedClass ));
27
33
}
34
+ if (!getenv ('REDIS_CLUSTER_HOSTS ' )) {
35
+ throw new SkippedTestSuiteError ('REDIS_CLUSTER_HOSTS env var is not defined. ' );
36
+ }
28
37
29
38
$ mock = self ::getObjectForTrait (RedisTrait::class);
30
39
$ connection = $ mock ::createConnection ($ dsn );
@@ -34,21 +43,23 @@ public function testCreateConnection(string $dsn, string $expectedClass)
34
43
35
44
public function provideCreateConnection (): array
36
45
{
46
+ $ hosts = array_map (fn (string $ host ) => sprintf ('host[%s] ' , $ host ), explode (' ' , getenv ('REDIS_CLUSTER_HOSTS ' )));
47
+
37
48
return [
38
49
[
39
- 'dsn ' => 'redis:?host[localhost:7000] &redis_cluster=1 ' ,
50
+ 'dsn ' => sprintf ( 'redis:?%s &redis_cluster=1 ' , $ hosts [ 0 ]) ,
40
51
'expectedClass ' => '\RedisCluster ' ,
41
52
],
42
53
[
43
- 'dsn ' => 'redis:?host[localhost:7000] &redis_cluster=true ' ,
54
+ 'dsn ' => sprintf ( 'redis:?%s &redis_cluster=true ' , $ hosts [ 0 ]) ,
44
55
'expectedClass ' => '\RedisCluster ' ,
45
56
],
46
57
[
47
- 'dsn ' => 'redis:?host[localhost:7000] ' ,
58
+ 'dsn ' => sprintf ( 'redis:?%s ' , $ hosts [ 0 ]) ,
48
59
'expectedClass ' => '\Redis ' ,
49
60
],
50
61
[
51
- 'dsn ' => 'redis:?host[localhost:7000]&host[localhost:7001] ' ,
62
+ 'dsn ' => sprintf ( 'redis:?%s ' , join ( ' & ' , array_slice ( $ hosts , 0 , 2 ))) ,
52
63
'expectedClass ' => '\RedisArray ' ,
53
64
],
54
65
];
0 commit comments