Completed
Push — master ( ed1354...366677 )
by Avtandil
05:33
created

RedisTest::createConnection()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 2
dl 0
loc 21
rs 9.584
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Tests\Unit;
5
6
use Longman\LaravelLodash\Redis\RedisManager;
7
8
class RedisTest extends TestCase
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: artisan, be, call, seed
Loading history...
9
{
10
    private const PHPREDIS_OPT_SERIALIZER = 1;
11
    private const PHPREDIS_SERIALIZER_IGBINARY = 2;
12
13
    /** @test */
14
    public function it_should_return_instance_with_custom_serializer()
15
    {
16
        $redis = $this->createConnection('phpredis', [
17
            'default' => [
18
                'serializer' => 'igbinary',
19
            ],
20
        ]);
21
        $client = $redis->connection()->client();
22
23
        $this->assertEquals($client->getOption(self::PHPREDIS_OPT_SERIALIZER), self::PHPREDIS_SERIALIZER_IGBINARY);
0 ignored issues
show
Bug introduced by
The method getOption() does not exist on Predis\Client. Did you maybe mean getOptions()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
24
    }
25
26
    public function createConnection(string $driver, array $config = []): RedisManager
27
    {
28
        $host = getenv('REDIS_HOST') ?: '127.0.0.1';
29
        $port = getenv('REDIS_PORT') ?: 6379;
30
        $defaultConfig = [
31
            'cluster' => false,
32
            'default' => [
33
                'host'         => $host,
34
                'port'         => $port,
35
                'database'     => 5,
36
                'options'      => ['prefix' => 'lodash:'],
37
                'timeout'      => 0.5,
38
                'read_timeout' => 1.5,
39
            ],
40
        ];
41
        $options = array_replace_recursive($defaultConfig, $config);
42
43
        $redis = new RedisManager($this->app, $driver, $options);
44
45
        return $redis;
46
    }
47
}
48