1717
1818class 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