Passed
Pull Request — master (#16)
by Mihail
11:07 queued 02:40
created

RedisWithBinarySerializerTest::setUp()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 4
nop 0
dl 0
loc 20
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace Koded\Caching;
4
5
use Koded\Caching\Client\CacheClientFactory;
6
use Koded\Caching\Configuration\ConfigFactory;
7
use Koded\Stdlib\Interfaces\Serializer;
8
use PHPUnit\Framework\TestCase;
9
10
class RedisWithBinarySerializerTest extends TestCase
11
{
12
13
    use SimpleCacheTestCaseTrait;
14
15
    /**
16
     * @dataProvider simpleData
17
     *
18
     * @param $data
19
     */
20
    public function test_get_multi_with_default_value($data)
21
    {
22
        $this->cache->setMultiple($data);
23
24
        $this->assertSame([
25
            'key1' => 'foo',
26
            'non-existent-key' => 'with default value',
27
        ], $this->cache->getMultiple(['key1', 'non-existent-key'], 'with default value'));
28
    }
29
30
    public function test_should_return_redis_client()
31
    {
32
        $this->assertInstanceOf(\Redis::class, $this->cache->client());
33
    }
34
35
    protected function setUp(): void
36
    {
37
        putenv('CACHE_CLIENT=redis');
38
39
        if (false === extension_loaded('redis')) {
40
            $this->markTestSkipped('Redis extension is not loaded.');
41
        }
42
43
        if (false === extension_loaded('igbinary')) {
44
            $this->markTestSkipped('"igbinary" extension is not loaded.');
45
        }
46
47
        $this->cache = (new CacheClientFactory(new ConfigFactory([
48
            'host' => getenv('REDIS_SERVER_HOST'),
49
            'port' => getenv('REDIS_SERVER_PORT'),
50
51
            'serializer' => Serializer::PHP,
52
        ])))->new();
53
54
        $this->cache->clear();
55
    }
56
}