2009-07-15 02:36:09 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\Common\Cache;
|
|
|
|
|
|
|
|
use Doctrine\Common\Cache\MemcacheCache;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
|
|
|
|
|
|
|
class MemcacheCacheTest extends \Doctrine\Tests\DoctrineTestCase
|
|
|
|
{
|
2009-11-08 14:07:49 +03:00
|
|
|
private $_memcache;
|
|
|
|
|
2009-07-15 02:36:09 +04:00
|
|
|
public function setUp()
|
|
|
|
{
|
2009-11-08 14:07:49 +03:00
|
|
|
if (extension_loaded('memcache')) {
|
|
|
|
$memcache = new \Memcache;
|
|
|
|
$ok = @$memcache->connect('localhost', 11211);
|
|
|
|
if (!$ok) {
|
|
|
|
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
|
|
|
|
}
|
|
|
|
} else {
|
2009-07-15 02:36:09 +04:00
|
|
|
$this->markTestSkipped('The ' . __CLASS__ .' requires the use of memcache');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMemcacheCacheDriver()
|
|
|
|
{
|
|
|
|
$cache = new MemcacheCache();
|
2009-11-08 14:07:49 +03:00
|
|
|
$cache->setMemcache($this->_memcache);
|
2009-07-15 02:36:09 +04:00
|
|
|
|
|
|
|
// Test save
|
|
|
|
$cache->save('test_key', 'testing this out');
|
|
|
|
|
|
|
|
// Test contains to test that save() worked
|
|
|
|
$this->assertTrue($cache->contains('test_key'));
|
|
|
|
|
|
|
|
// Test fetch
|
|
|
|
$this->assertEquals('testing this out', $cache->fetch('test_key'));
|
|
|
|
|
|
|
|
// Test delete
|
|
|
|
$cache->save('test_key2', 'test2');
|
|
|
|
$cache->delete('test_key2');
|
|
|
|
$this->assertFalse($cache->contains('test_key2'));
|
|
|
|
}
|
|
|
|
}
|