1
0
mirror of synced 2024-12-13 22:56:04 +03:00
doctrine2/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php
hobodave 1ad982a4fe [2.0][DC-460] Refactored cache bulk deletion methods to use driver specific features to retrieve list of keys. Also, refactored tests
so that all methods are tested for all drivers.

Removed:

- Doctrine\Common\Cache\AbstractCache::count()
- Doctrine\Common\Cache\AbstractCache::deleteAll()

API Changes:

- Doctrine\ORM\AbstractQuery::getResultCacheId() now public

Bugs fixed:

- Doctrine\Common\Cache\AbstractCache::deleteByPrefix() was deleting _every_ key in cache
2010-01-29 01:38:37 +00:00

80 lines
2.3 KiB
PHP

<?php
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Common\Cache\ArrayCache;
require_once __DIR__ . '/../../TestInit.php';
/**
* ResultCacheTest
*
* @author robo
*/
class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp() {
$this->useModelSet('cms');
parent::setUp();
}
public function testResultCache()
{
$user = new CmsUser;
$user->name = 'Roman';
$user->username = 'romanb';
$user->status = 'dev';
$this->_em->persist($user);
$this->_em->flush();
$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
$cache = new ArrayCache;
$query->setResultCacheDriver($cache);
$users = $query->getResult();
$this->assertTrue($cache->contains($query->getResultCacheId(array())));
$this->assertEquals(1, count($users));
$this->assertEquals('Roman', $users[0]->name);
$this->_em->clear();
$query2 = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
$query2->setResultCacheDriver($cache);
$users = $query2->getResult();
$this->assertTrue($cache->contains($query->getResultCacheId(array())));
$this->assertEquals(1, count($users));
$this->assertEquals('Roman', $users[0]->name);
}
public function testSetResultCacheId()
{
$cache = new ArrayCache;
$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
$query->setResultCacheDriver($cache);
$query->setResultCacheId('testing_result_cache_id');
$users = $query->getResult();
$this->assertTrue($cache->contains('testing_result_cache_id'));
}
public function testUseResultCache()
{
$cache = new \Doctrine\Common\Cache\ArrayCache();
$this->_em->getConfiguration()->setResultCacheImpl($cache);
$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
$query->useResultCache(true);
$query->setResultCacheId('testing_result_cache_id');
$users = $query->getResult();
$this->assertTrue($cache->contains('testing_result_cache_id'));
$this->_em->getConfiguration()->setResultCacheImpl(null);
}
}