2009-10-23 02:19:17 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\Common\Cache;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
|
|
|
|
2010-01-29 04:38:37 +03:00
|
|
|
abstract class CacheTest extends \Doctrine\Tests\DoctrineTestCase
|
2009-10-23 02:19:17 +04:00
|
|
|
{
|
2010-01-29 04:38:37 +03:00
|
|
|
public function testBasics()
|
2009-10-23 02:19:17 +04:00
|
|
|
{
|
2010-01-29 04:38:37 +03:00
|
|
|
$cache = $this->_getCacheDriver();
|
|
|
|
|
|
|
|
// 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'));
|
2009-10-23 02:19:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteAll()
|
|
|
|
{
|
2010-01-29 04:38:37 +03:00
|
|
|
$cache = $this->_getCacheDriver();
|
2009-10-23 02:19:17 +04:00
|
|
|
$cache->save('test_key1', '1');
|
|
|
|
$cache->save('test_key2', '2');
|
|
|
|
$cache->deleteAll();
|
|
|
|
|
2010-01-29 04:38:37 +03:00
|
|
|
$this->assertFalse($cache->contains('test_key1'));
|
|
|
|
$this->assertFalse($cache->contains('test_key2'));
|
2009-10-23 02:19:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteByRegex()
|
|
|
|
{
|
2010-01-29 04:38:37 +03:00
|
|
|
$cache = $this->_getCacheDriver();
|
2009-10-23 02:19:17 +04:00
|
|
|
$cache->save('test_key1', '1');
|
|
|
|
$cache->save('test_key2', '2');
|
|
|
|
$cache->deleteByRegex('/test_key[0-9]/');
|
|
|
|
|
2010-01-29 04:38:37 +03:00
|
|
|
$this->assertFalse($cache->contains('test_key1'));
|
|
|
|
$this->assertFalse($cache->contains('test_key2'));
|
2009-10-23 02:19:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteByPrefix()
|
|
|
|
{
|
2010-01-29 04:38:37 +03:00
|
|
|
$cache = $this->_getCacheDriver();
|
2009-10-23 02:19:17 +04:00
|
|
|
$cache->save('test_key1', '1');
|
|
|
|
$cache->save('test_key2', '2');
|
|
|
|
$cache->deleteByPrefix('test_key');
|
|
|
|
|
2010-01-29 04:38:37 +03:00
|
|
|
$this->assertFalse($cache->contains('test_key1'));
|
|
|
|
$this->assertFalse($cache->contains('test_key2'));
|
2009-10-23 02:19:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteBySuffix()
|
|
|
|
{
|
2010-01-29 04:38:37 +03:00
|
|
|
$cache = $this->_getCacheDriver();
|
2009-10-23 02:19:17 +04:00
|
|
|
$cache->save('1test_key', '1');
|
|
|
|
$cache->save('2test_key', '2');
|
|
|
|
$cache->deleteBySuffix('test_key');
|
|
|
|
|
2010-01-29 04:38:37 +03:00
|
|
|
$this->assertFalse($cache->contains('1test_key'));
|
|
|
|
$this->assertFalse($cache->contains('2test_key'));
|
2009-10-23 02:19:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteByWildcard()
|
|
|
|
{
|
2010-01-29 04:38:37 +03:00
|
|
|
$cache = $this->_getCacheDriver();
|
2009-10-23 02:19:17 +04:00
|
|
|
$cache->save('test_key1', '1');
|
|
|
|
$cache->save('test_key2', '2');
|
|
|
|
$cache->delete('test_key*');
|
|
|
|
|
2010-01-29 04:38:37 +03:00
|
|
|
$this->assertFalse($cache->contains('test_key1'));
|
|
|
|
$this->assertFalse($cache->contains('test_key2'));
|
2009-10-23 02:19:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNamespace()
|
|
|
|
{
|
2010-01-29 04:38:37 +03:00
|
|
|
$cache = $this->_getCacheDriver();
|
2009-10-23 02:19:17 +04:00
|
|
|
$cache->setNamespace('test_');
|
|
|
|
$cache->save('key1', 'test');
|
|
|
|
$this->assertTrue($cache->contains('key1'));
|
|
|
|
|
|
|
|
$ids = $cache->getIds();
|
|
|
|
$this->assertTrue(in_array('test_key1', $ids));
|
|
|
|
}
|
2010-01-29 04:38:37 +03:00
|
|
|
|
|
|
|
abstract protected function _getCacheDriver();
|
2009-10-23 02:19:17 +04:00
|
|
|
}
|