| 1 | <?php |
||
| 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); |
||
| 66 |