RedisCacheTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Doctrine\Tests\Common\Cache;
  3. use Doctrine\Common\Cache\RedisCache;
  4. use Doctrine\Common\Cache\Cache;
  5. /**
  6. * @requires extension redis
  7. */
  8. class RedisCacheTest extends CacheTest
  9. {
  10. private $_redis;
  11. protected function setUp()
  12. {
  13. $this->_redis = new \Redis();
  14. $ok = @$this->_redis->connect('127.0.0.1');
  15. if (!$ok) {
  16. $this->markTestSkipped('Cannot connect to Redis.');
  17. }
  18. }
  19. public function testHitMissesStatsAreProvided()
  20. {
  21. $cache = $this->_getCacheDriver();
  22. $stats = $cache->getStats();
  23. $this->assertNotNull($stats[Cache::STATS_HITS]);
  24. $this->assertNotNull($stats[Cache::STATS_MISSES]);
  25. }
  26. public function testGetRedisReturnsInstanceOfRedis()
  27. {
  28. $this->assertInstanceOf('Redis', $this->_getCacheDriver()->getRedis());
  29. }
  30. public function testSerializerOptionWithOutIgbinaryExtension()
  31. {
  32. if (defined('Redis::SERIALIZER_IGBINARY') && extension_loaded('igbinary')) {
  33. $this->markTestSkipped('Extension igbinary is loaded.');
  34. }
  35. $this->assertEquals(
  36. \Redis::SERIALIZER_PHP,
  37. $this->_getCacheDriver()->getRedis()->getOption(\Redis::OPT_SERIALIZER)
  38. );
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. protected function _getCacheDriver()
  44. {
  45. $driver = new RedisCache();
  46. $driver->setRedis($this->_redis);
  47. return $driver;
  48. }
  49. }