X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FFunctional%2FHydrationCacheTest.php;fp=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FFunctional%2FHydrationCacheTest.php;h=9dc556d4b809c011b77f8259374f3e13e035cb70;hb=8b04b2d11798dee4f3e1358e4f43e97a6df851f6;hp=0000000000000000000000000000000000000000;hpb=73568cf05a785a45f94ca3f2351d9e07bf917958;p=zf2.biz%2Fgalerie.git diff --git a/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php new file mode 100644 index 0000000..9dc556d --- /dev/null +++ b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/HydrationCacheTest.php @@ -0,0 +1,88 @@ +useModelSet('cms'); + + parent::setUp(); + + $user = new CmsUser; + $user->name = "Benjamin"; + $user->username = "beberlei"; + $user->status = 'active'; + + $this->_em->persist($user); + $this->_em->flush(); + $this->_em->clear(); + } + + public function testHydrationCache() + { + $cache = new ArrayCache(); + $dql = "SELECT u FROM Doctrine\Tests\Models\Cms\CmsUser u"; + + $users = $this->_em->createQuery($dql) + ->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache)) + ->getResult(); + + $c = $this->getCurrentQueryCount(); + $users = $this->_em->createQuery($dql) + ->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache)) + ->getResult(); + + $this->assertEquals($c, $this->getCurrentQueryCount(), "Should not execute query. Its cached!"); + + $users = $this->_em->createQuery($dql) + ->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache)) + ->getArrayResult(); + + $this->assertEquals($c + 1, $this->getCurrentQueryCount(), "Hydration is part of cache key."); + + $users = $this->_em->createQuery($dql) + ->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache)) + ->getArrayResult(); + + $this->assertEquals($c + 1, $this->getCurrentQueryCount(), "Hydration now cached"); + + $users = $this->_em->createQuery($dql) + ->setHydrationCacheProfile(new QueryCacheProfile(null, 'cachekey', $cache)) + ->getArrayResult(); + + $this->assertTrue($cache->contains('cachekey'), 'Explicit cache key'); + + $users = $this->_em->createQuery($dql) + ->setHydrationCacheProfile(new QueryCacheProfile(null, 'cachekey', $cache)) + ->getArrayResult(); + $this->assertEquals($c + 2, $this->getCurrentQueryCount(), "Hydration now cached"); + } + + public function testHydrationParametersSerialization() + { + $cache = new ArrayCache(); + + $dql = "SELECT u FROM Doctrine\Tests\Models\Cms\CmsUser u WHERE u.id = ?1"; + $query = $this->_em->createQuery($dql) + ->setParameter(1, $userId = 1) + ->setHydrationCacheProfile(new QueryCacheProfile(null, null, $cache)); + + $query->getResult(); + + $c = $this->getCurrentQueryCount(); + + $query->getResult(); + + $this->assertEquals($c, $this->getCurrentQueryCount(), "Should not execute query. Its cached!"); + } +} +