1
0
mirror of synced 2025-02-22 07:03:13 +03:00

Test empty collections second level cache

This commit is contained in:
Asmir Mustafic 2014-02-11 17:39:16 +01:00
parent a5fbb20fbb
commit 4a6d6e34f8
3 changed files with 66 additions and 5 deletions

View File

@ -165,6 +165,7 @@ abstract class SecondLevelCacheAbstractTest extends OrmFunctionalTestCase
{ {
$t1 = new Travel($this->travelers[0]); $t1 = new Travel($this->travelers[0]);
$t2 = new Travel($this->travelers[1]); $t2 = new Travel($this->travelers[1]);
$t3 = new Travel($this->travelers[1]);
$t1->addVisitedCity($this->cities[0]); $t1->addVisitedCity($this->cities[0]);
$t1->addVisitedCity($this->cities[1]); $t1->addVisitedCity($this->cities[1]);
@ -175,9 +176,11 @@ abstract class SecondLevelCacheAbstractTest extends OrmFunctionalTestCase
$this->_em->persist($t1); $this->_em->persist($t1);
$this->_em->persist($t2); $this->_em->persist($t2);
$this->_em->persist($t3);
$this->travels[] = $t1; $this->travels[] = $t1;
$this->travels[] = $t2; $this->travels[] = $t2;
$this->travels[] = $t3;
$this->_em->flush(); $this->_em->flush();
} }

View File

@ -214,4 +214,33 @@ class SecondLevelCacheManyToManyTest extends SecondLevelCacheAbstractTest
$this->_em->persist($travel); $this->_em->persist($travel);
$this->_em->flush(); $this->_em->flush();
} }
public function testManyToManyWithEmptyRelation()
{
$this->loadFixturesCountries();
$this->loadFixturesStates();
$this->loadFixturesCities();
$this->loadFixturesTraveler();
$this->loadFixturesTravels();
$this->_em->clear();
$this->evictRegions();
$queryCount = $this->getCurrentQueryCount();
$entitiId = $this->travels[2]->getId(); //empty travel
$entity = $this->_em->find(Travel::CLASSNAME, $entitiId);
$this->assertEquals(0, $entity->getVisitedCities()->count());
$this->assertEquals($queryCount+2, $this->getCurrentQueryCount());
$this->_em->clear();
$entity = $this->_em->find(Travel::CLASSNAME, $entitiId);
$queryCount = $this->getCurrentQueryCount();
$this->assertEquals(0, $entity->getVisitedCities()->count());
$this->assertEquals($queryCount, $this->getCurrentQueryCount());
}
} }

View File

@ -284,6 +284,35 @@ class SecondLevelCacheOneToManyTest extends SecondLevelCacheAbstractTest
$this->assertEquals(0, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(State::CLASSNAME, 'cities'))); $this->assertEquals(0, $this->secondLevelCacheLogger->getRegionHitCount($this->getCollectionRegion(State::CLASSNAME, 'cities')));
} }
public function testOneToManyWithEmptyRelation()
{
$this->loadFixturesCountries();
$this->loadFixturesStates();
$this->loadFixturesCities();
$this->secondLevelCacheLogger->clearStats();
$this->cache->evictEntityRegion(City::CLASSNAME);
$this->cache->evictEntityRegion(State::CLASSNAME);
$this->cache->evictCollectionRegion(State::CLASSNAME, 'cities');
$this->_em->clear();
$entitiId = $this->states[2]->getId(); // bavaria (cities count = 0)
$queryCount = $this->getCurrentQueryCount();
$entity = $this->_em->find(State::CLASSNAME, $entitiId);
$this->assertEquals(0, $entity->getCities()->count());
$this->assertEquals($queryCount + 2, $this->getCurrentQueryCount());
$this->_em->clear();
$queryCount = $this->getCurrentQueryCount();
$entity = $this->_em->find(State::CLASSNAME, $entitiId);
$this->assertEquals(0, $entity->getCities()->count());
$this->assertEquals($queryCount, $this->getCurrentQueryCount());
}
public function testOneToManyCount() public function testOneToManyCount()
{ {
$this->loadFixturesCountries(); $this->loadFixturesCountries();