2009-07-21 14:48:19 +04:00
|
|
|
<?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();
|
|
|
|
}
|
|
|
|
|
2009-10-23 02:39:37 +04:00
|
|
|
public function testResultCache()
|
2009-07-21 14:48:19 +04:00
|
|
|
{
|
|
|
|
$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;
|
2009-10-24 04:28:43 +04:00
|
|
|
$query->setResultCacheDriver($cache);
|
2010-01-29 04:38:37 +03:00
|
|
|
|
2009-08-03 21:18:37 +04:00
|
|
|
$users = $query->getResult();
|
2009-07-21 14:48:19 +04:00
|
|
|
|
2010-01-29 04:38:37 +03:00
|
|
|
$this->assertTrue($cache->contains($query->getResultCacheId(array())));
|
2009-07-21 14:48:19 +04:00
|
|
|
$this->assertEquals(1, count($users));
|
|
|
|
$this->assertEquals('Roman', $users[0]->name);
|
2010-01-29 04:38:37 +03:00
|
|
|
|
2009-07-21 14:48:19 +04:00
|
|
|
$this->_em->clear();
|
2010-01-29 04:38:37 +03:00
|
|
|
|
2009-07-21 14:48:19 +04:00
|
|
|
$query2 = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
|
2009-10-24 04:28:43 +04:00
|
|
|
$query2->setResultCacheDriver($cache);
|
2010-01-29 04:38:37 +03:00
|
|
|
|
2009-08-03 21:18:37 +04:00
|
|
|
$users = $query2->getResult();
|
2009-07-21 14:48:19 +04:00
|
|
|
|
2010-01-29 04:38:37 +03:00
|
|
|
$this->assertTrue($cache->contains($query->getResultCacheId(array())));
|
2009-07-21 14:48:19 +04:00
|
|
|
$this->assertEquals(1, count($users));
|
|
|
|
$this->assertEquals('Roman', $users[0]->name);
|
|
|
|
}
|
|
|
|
|
2009-10-23 02:39:37 +04:00
|
|
|
public function testSetResultCacheId()
|
|
|
|
{
|
|
|
|
$cache = new ArrayCache;
|
|
|
|
|
|
|
|
$query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
|
2009-10-24 04:28:43 +04:00
|
|
|
$query->setResultCacheDriver($cache);
|
2009-10-23 02:39:37 +04:00
|
|
|
$query->setResultCacheId('testing_result_cache_id');
|
|
|
|
$users = $query->getResult();
|
|
|
|
|
|
|
|
$this->assertTrue($cache->contains('testing_result_cache_id'));
|
|
|
|
}
|
2009-10-24 04:28:43 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2009-10-23 02:39:37 +04:00
|
|
|
}
|