RedisClusterProxyTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 3
Bugs 2 Features 1
Metric Value
wmc 6
eloc 12
c 3
b 2
f 1
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUpBeforeClass() 0 12 4
A createConnection() 0 10 2
1
<?php
2
3
namespace Zenstruck\Governator\Tests\Integration\Redis;
4
5
use Symfony\Component\Cache\Adapter\RedisAdapter;
6
use Symfony\Component\Cache\Traits\RedisClusterProxy;
7
8
/**
9
 * @requires extension redis
10
 * @group time-sensitive
11
 *
12
 * @author Kevin Bond <[email protected]>
13
 */
14
final class RedisClusterProxyTest extends BaseRedisThrottleTest
15
{
16
    public static function setUpBeforeClass(): void
17
    {
18
        if (!\class_exists(RedisClusterProxy::class)) {
19
            self::markTestSkipped('The RedisClusterProxy class is required.');
20
        }
21
22
        if (!\class_exists('RedisCluster')) {
23
            self::markTestSkipped('The RedisCluster class is required.');
24
        }
25
26
        if (!\getenv('REDIS_CLUSTER_HOSTS')) {
27
            self::markTestSkipped('REDIS_CLUSTER_HOSTS env var is not defined.');
28
        }
29
    }
30
31
    protected function createConnection(): object
32
    {
33
        $hosts = \getenv('REDIS_CLUSTER_HOSTS');
34
        $connection = RedisAdapter::createConnection('redis:?host['.\str_replace(' ', ']&host[', $hosts).']', ['lazy' => true, 'redis_cluster' => true]);
35
36
        if (!$connection instanceof RedisClusterProxy) {
37
            throw new \RuntimeException('Expected instance of '.RedisClusterProxy::class);
38
        }
39
40
        return $connection;
41
    }
42
}
43