1
0
mirror of synced 2025-02-02 21:41:45 +03:00

add a not weel writend/nammed test testing Query::expireResultCache()

This commit is contained in:
bruno da silva 2017-04-11 10:27:14 +02:00 committed by Luís Cobucci
parent 2c1ebc4ef1
commit 85a52d781e
No known key found for this signature in database
GPG Key ID: EC61C5F01750ED3C
2 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,95 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Tests\OrmFunctionalTestCase;
/**
* @group 2947
*/
class GH2947Test extends OrmFunctionalTestCase
{
protected function setUp()
{
$this->resultCacheImpl = new ArrayCache();
parent::setUp();
$this->_schemaTool->createSchema([$this->_em->getClassMetadata(GH2947Car::class)]);
}
public function testIssue()
{
$this->createData();
$initialQueryCount = $this->getCurrentQueryCount();
$query = $this->createQuery();
self::assertEquals('BMW', (string) $query->getSingleResult());
self::assertEquals($initialQueryCount + 1, $this->getCurrentQueryCount());
$this->updateData();
self::assertEquals('BMW', (string) $query->getSingleResult());
self::assertEquals($initialQueryCount + 2, $this->getCurrentQueryCount());
$query->expireResultCache(true);
self::assertEquals('Dacia', (string) $query->getSingleResult());
self::assertEquals($initialQueryCount + 3, $this->getCurrentQueryCount());
$query->expireResultCache(false);
self::assertEquals('Dacia', (string) $query->getSingleResult());
self::assertEquals($initialQueryCount + 3, $this->getCurrentQueryCount());
}
private function createQuery()
{
return $this->_em->createQueryBuilder()
->select('car')
->from(GH2947Car::class, 'car')
->getQuery()
->useResultCache(true, 3600, 'foo-cache-id');
}
private function createData()
{
$this->_em->persist(new GH2947Car('BMW'));
$this->_em->flush();
$this->_em->clear();
}
private function updateData()
{
$this->_em->createQueryBuilder()
->update(GH2947Car::class, 'car')
->set('car.brand', ':newBrand')
->where('car.brand = :oldBrand')
->setParameter('newBrand', 'Dacia')
->setParameter('oldBrand', 'BMW')
->getQuery()
->execute();
}
}
/**
* @Entity
* @Table(name="GH2947_car")
*/
class GH2947Car
{
/**
* @Id
* @Column(type="string", length=25)
* @GeneratedValue(strategy="NONE")
*/
public $brand;
public function __construct(string $brand)
{
$this->brand = $brand;
}
public function __toString(): string
{
return $this->brand;
}
}

View File

@ -68,6 +68,13 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
*/
protected $_usedModelSets = [];
/**
* To be configured by the test that uses result set cache
*
* @var \Doctrine\Common\Cache\Cache|null
*/
protected $resultCacheImpl;
/**
* Whether the database schema has already been created.
*
@ -699,6 +706,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Doctrine\Tests\Proxies');
if (null !== $this->resultCacheImpl) {
$config->setResultCacheImpl($this->resultCacheImpl);
}
$enableSecondLevelCache = getenv('ENABLE_SECOND_LEVEL_CACHE');
if ($this->isSecondLevelCacheEnabled || $enableSecondLevelCache) {