MemcacheCacheTest.php 1.2 KB

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