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