CouchbaseCacheTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Doctrine\Tests\Common\Cache;
  3. use Couchbase;
  4. use Doctrine\Common\Cache\CouchbaseCache;
  5. class CouchbaseCacheTest extends CacheTest
  6. {
  7. private $couchbase;
  8. public function setUp()
  9. {
  10. if (extension_loaded('couchbase')) {
  11. try {
  12. $this->couchbase = new Couchbase('127.0.0.1', 'Administrator', 'password', 'default');
  13. } catch(Exception $ex) {
  14. $this->markTestSkipped('Could not instantiate the Couchbase cache because of: ' . $ex);
  15. }
  16. } else {
  17. $this->markTestSkipped('The ' . __CLASS__ .' requires the use of the couchbase extension');
  18. }
  19. }
  20. public function testNoExpire()
  21. {
  22. $cache = $this->_getCacheDriver();
  23. $cache->save('noexpire', 'value', 0);
  24. sleep(1);
  25. $this->assertTrue($cache->contains('noexpire'), 'Couchbase 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'), 'Couchbase provider should support TTL > 30 days');
  32. }
  33. protected function _getCacheDriver()
  34. {
  35. $driver = new CouchbaseCache();
  36. $driver->setCouchbase($this->couchbase);
  37. return $driver;
  38. }
  39. }