[2.0] Fix and test for result cache.
This commit is contained in:
parent
49434b0322
commit
be0088f00c
3 changed files with 67 additions and 2 deletions
|
@ -443,7 +443,12 @@ abstract class AbstractQuery
|
||||||
|
|
||||||
if ($cached === false) {
|
if ($cached === false) {
|
||||||
// Cache miss.
|
// Cache miss.
|
||||||
$result = $this->_doExecute($params);
|
$stmt = $this->_doExecute($params);
|
||||||
|
|
||||||
|
$result = $this->_em->getHydrator($this->_hydrationMode)->hydrateAll(
|
||||||
|
$stmt, $this->_resultSetMapping, $this->_hints
|
||||||
|
);
|
||||||
|
|
||||||
$cacheDriver->save($hash, serialize($result), $this->_resultCacheTTL);
|
$cacheDriver->save($hash, serialize($result), $this->_resultCacheTTL);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -467,7 +472,7 @@ abstract class AbstractQuery
|
||||||
/**
|
/**
|
||||||
* Prepares the given parameters for execution in an SQL statement.
|
* Prepares the given parameters for execution in an SQL statement.
|
||||||
*
|
*
|
||||||
* Note to inheritors: This method must return a numerically, continously indexed array,
|
* Note to inheritors: This method must return a numerically, continuously indexed array,
|
||||||
* starting with index 0 where the values (the parameter values) are in the order
|
* starting with index 0 where the values (the parameter values) are in the order
|
||||||
* in which the parameters appear in the SQL query.
|
* in which the parameters appear in the SQL query.
|
||||||
*
|
*
|
||||||
|
|
|
@ -25,6 +25,7 @@ class AllTests
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\ClassTableInheritanceTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\ClassTableInheritanceTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\DetachedEntityTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\DetachedEntityTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\QueryCacheTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\QueryCacheTest');
|
||||||
|
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\ResultCacheTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\QueryTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\QueryTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneUnidirectionalAssociationTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneUnidirectionalAssociationTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneBidirectionalAssociationTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneBidirectionalAssociationTest');
|
||||||
|
|
59
tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php
Normal file
59
tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?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 testQueryCache()
|
||||||
|
{
|
||||||
|
$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->setResultCache($cache);
|
||||||
|
$this->assertEquals(0, $cache->count());
|
||||||
|
|
||||||
|
$initialQueryCount = $this->_em->getConnection()->getQueryCount();
|
||||||
|
|
||||||
|
$users = $query->getResultList();
|
||||||
|
|
||||||
|
$this->assertEquals($initialQueryCount + 1, $this->_em->getConnection()->getQueryCount());
|
||||||
|
$this->assertEquals(1, $cache->count());
|
||||||
|
$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->setResultCache($cache);
|
||||||
|
|
||||||
|
$users = $query2->getResultList();
|
||||||
|
|
||||||
|
$this->assertEquals($initialQueryCount + 1, $this->_em->getConnection()->getQueryCount());
|
||||||
|
$this->assertEquals(1, $cache->count());
|
||||||
|
$this->assertEquals(1, count($users));
|
||||||
|
$this->assertEquals('Roman', $users[0]->name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue