From 2e890362c5496d6bdbc51ed1ac9686787d0ab28b Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sun, 18 Jan 2015 23:24:15 +0100 Subject: [PATCH] Tested second level cache with composite primary keys --- ...ompositePrimaryKeyWithAssociationsTest.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php diff --git a/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php new file mode 100644 index 000000000..dc4f40db0 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheCompositePrimaryKeyWithAssociationsTest.php @@ -0,0 +1,81 @@ +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() + { + $admin1Repo = $this->_em->getRepository('Doctrine\Tests\Models\GeoNames\Admin1'); + + $queries = $this->getCurrentQueryCount(); + + $admin1Rome = $admin1Repo->findOneBy(array('country' => 'IT', 'id' => 1)); + + $this->assertEquals("Italy", $admin1Rome->country->name); + $this->assertEquals(2, count($admin1Rome->names)); + $this->assertEquals($queries + 3, $this->getCurrentQueryCount()); + + $this->_em->clear(); + + $queries = $this->getCurrentQueryCount(); + + $admin1Rome = $admin1Repo->findOneBy(array('country' => 'IT', 'id' => 1)); + + $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(); + } +}