MemcachedCacheTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Doctrine\Tests\Common\Cache;
  3. use Doctrine\Common\Cache\MemcachedCache;
  4. class MemcachedCacheTest extends CacheTest
  5. {
  6. private $memcached;
  7. public function setUp()
  8. {
  9. if (extension_loaded('memcached')) {
  10. $this->memcached = new \Memcached();
  11. $this->memcached->setOption(\Memcached::OPT_COMPRESSION, false);
  12. $this->memcached->addServer('127.0.0.1', 11211);
  13. $fh = @fsockopen('127.0.0.1', 11211);
  14. if (!$fh) {
  15. $this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
  16. }
  17. } else {
  18. $this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
  19. }
  20. }
  21. public function testNoExpire() {
  22. $cache = $this->_getCacheDriver();
  23. $cache->save('noexpire', 'value', 0);
  24. sleep(1);
  25. $this->assertTrue($cache->contains('noexpire'), 'Memcache provider should support no-expire');
  26. }
  27. public function testLongLifetime()
  28. {
  29. $cache = $this->_getCacheDriver();
  30. $cache->save('key', 'value', 30 * 24 * 3600 + 1);
  31. $this->assertTrue($cache->contains('key'), 'Memcached provider should support TTL > 30 days');
  32. }
  33. protected function _getCacheDriver()
  34. {
  35. $driver = new MemcachedCache();
  36. $driver->setMemcached($this->memcached);
  37. return $driver;
  38. }
  39. }