add a not weel writend/nammed test testing Query::expireResultCache()
This commit is contained in:
parent
2c1ebc4ef1
commit
85a52d781e
95
tests/Doctrine/Tests/ORM/Functional/Ticket/GH2947Test.php
Normal file
95
tests/Doctrine/Tests/ORM/Functional/Ticket/GH2947Test.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -68,6 +68,13 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
|||||||
*/
|
*/
|
||||||
protected $_usedModelSets = [];
|
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.
|
* Whether the database schema has already been created.
|
||||||
*
|
*
|
||||||
@ -699,6 +706,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
|
|||||||
$config->setProxyDir(__DIR__ . '/Proxies');
|
$config->setProxyDir(__DIR__ . '/Proxies');
|
||||||
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
$config->setProxyNamespace('Doctrine\Tests\Proxies');
|
||||||
|
|
||||||
|
if (null !== $this->resultCacheImpl) {
|
||||||
|
$config->setResultCacheImpl($this->resultCacheImpl);
|
||||||
|
}
|
||||||
|
|
||||||
$enableSecondLevelCache = getenv('ENABLE_SECOND_LEVEL_CACHE');
|
$enableSecondLevelCache = getenv('ENABLE_SECOND_LEVEL_CACHE');
|
||||||
|
|
||||||
if ($this->isSecondLevelCacheEnabled || $enableSecondLevelCache) {
|
if ($this->isSecondLevelCacheEnabled || $enableSecondLevelCache) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user