Passed
Pull Request — master (#251)
by Gabriel
10:21
created

RedisCacheTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 49
rs 10
1
<?php
2
3
namespace Doctrine\Tests\Common\Cache;
4
5
use Doctrine\Common\Cache\Cache;
6
use Doctrine\Common\Cache\CacheProvider;
7
use Doctrine\Common\Cache\RedisCache;
8
use Redis;
9
use function defined;
10
use function extension_loaded;
11
12
/**
13
 * @requires extension redis
14
 */
15
class RedisCacheTest extends CacheTest
16
{
17
    private $_redis;
18
19
    protected function setUp() : void
20
    {
21
        $this->_redis = new Redis();
22
        $ok           = @$this->_redis->connect('127.0.0.1');
23
        if ($ok) {
24
            return;
25
        }
26
27
        $this->markTestSkipped('Cannot connect to Redis.');
28
    }
29
30
    public function testHitMissesStatsAreProvided() : void
31
    {
32
        $cache = $this->_getCacheDriver();
33
        $stats = $cache->getStats();
34
35
        self::assertNotNull($stats[Cache::STATS_HITS]);
36
        self::assertNotNull($stats[Cache::STATS_MISSES]);
37
    }
38
39
    public function testGetRedisReturnsInstanceOfRedis() : void
40
    {
41
        self::assertInstanceOf(Redis::class, $this->_getCacheDriver()->getRedis());
42
    }
43
44
    public function testSerializerOptionWithOutIgbinaryExtension() : void
45
    {
46
        if (defined('Redis::SERIALIZER_IGBINARY') && extension_loaded('igbinary')) {
47
            $this->markTestSkipped('Extension igbinary is loaded.');
48
        }
49
50
        self::assertEquals(
51
            Redis::SERIALIZER_PHP,
52
            $this->_getCacheDriver()->getRedis()->getOption(Redis::OPT_SERIALIZER)
53
        );
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59
    protected function _getCacheDriver() : CacheProvider
60
    {
61
        $driver = new RedisCache();
62
        $driver->setRedis($this->_redis);
63
        return $driver;
64
    }
65
}
66