2015-01-18 23:24:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional;
|
|
|
|
|
|
|
|
use Doctrine\Tests\Models\GeoNames\Admin1;
|
|
|
|
use Doctrine\Tests\Models\GeoNames\Admin1AlternateName;
|
2016-12-08 18:01:04 +01:00
|
|
|
use Doctrine\Tests\Models\GeoNames\Country;
|
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
2015-01-18 23:24:15 +01:00
|
|
|
|
|
|
|
class SecondLevelCacheCompositePrimaryKeyWithAssociationsTest extends OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \Doctrine\ORM\Cache
|
|
|
|
*/
|
|
|
|
protected $cache;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this->enableSecondLevelCache();
|
|
|
|
$this->useModelSet('geonames');
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->cache = $this->_em->getCache();
|
|
|
|
|
|
|
|
$it = new Country("IT", "Italy");
|
|
|
|
|
|
|
|
$this->_em->persist($it);
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$admin1 = new Admin1(1, "Rome", $it);
|
|
|
|
|
|
|
|
$this->_em->persist($admin1);
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$name1 = new Admin1AlternateName(1, "Roma", $admin1);
|
|
|
|
$name2 = new Admin1AlternateName(2, "Rome", $admin1);
|
|
|
|
|
|
|
|
$admin1->names[] = $name1;
|
|
|
|
$admin1->names[] = $name2;
|
|
|
|
|
|
|
|
$this->_em->persist($admin1);
|
|
|
|
$this->_em->persist($name1);
|
|
|
|
$this->_em->persist($name2);
|
|
|
|
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
$this->evictRegions();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindByReturnsCachedEntity()
|
|
|
|
{
|
2016-12-08 18:01:04 +01:00
|
|
|
$admin1Repo = $this->_em->getRepository(Admin1::class);
|
2015-01-18 23:24:15 +01:00
|
|
|
|
|
|
|
$queries = $this->getCurrentQueryCount();
|
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$admin1Rome = $admin1Repo->findOneBy(['country' => 'IT', 'id' => 1]);
|
2015-01-18 23:24:15 +01:00
|
|
|
|
|
|
|
$this->assertEquals("Italy", $admin1Rome->country->name);
|
|
|
|
$this->assertEquals(2, count($admin1Rome->names));
|
|
|
|
$this->assertEquals($queries + 3, $this->getCurrentQueryCount());
|
|
|
|
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
$queries = $this->getCurrentQueryCount();
|
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$admin1Rome = $admin1Repo->findOneBy(['country' => 'IT', 'id' => 1]);
|
2015-01-18 23:24:15 +01:00
|
|
|
|
|
|
|
$this->assertEquals("Italy", $admin1Rome->country->name);
|
|
|
|
$this->assertEquals(2, count($admin1Rome->names));
|
|
|
|
$this->assertEquals($queries, $this->getCurrentQueryCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
private function evictRegions()
|
|
|
|
{
|
|
|
|
$this->cache->evictQueryRegions();
|
|
|
|
$this->cache->evictEntityRegions();
|
|
|
|
$this->cache->evictCollectionRegions();
|
|
|
|
}
|
|
|
|
}
|