From cc47d6a6799b59b75190a4b24cbe22050b538d13 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Sat, 17 Jan 2015 18:37:06 +0100 Subject: [PATCH] Changed some tests to be compatible with the new implementation of multiget region --- .../ORM/Cache/DefaultCacheFactory.php | 24 ++++--------------- .../ORM/Cache/DefaultCacheFactoryTest.php | 14 ----------- .../Cache/DefaultCollectionHydratorTest.php | 7 +++--- 3 files changed, 9 insertions(+), 36 deletions(-) diff --git a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php index 88a80a1a924..b3d6e0f46cf 100644 --- a/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php +++ b/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php @@ -181,20 +181,8 @@ public function buildQueryCache(EntityManagerInterface $em, $regionName = null) */ public function buildCollectionHydrator(EntityManagerInterface $em, array $mapping) { - if ($mapping['cache']) { - $targetPersister = $em->getUnitOfWork()->getEntityPersister($mapping['targetEntity']); - - if (! ($targetPersister instanceof CachedPersister)) { - throw CacheException::nonCacheableEntity($mapping['targetEntity']); - } - $targetRegion = $targetPersister->getCacheRegion(); - - if ($targetRegion instanceof MultiGetRegion) { - return new MultiGetCollectionHydrator($em, $targetRegion); - } - } - - return new DefaultCollectionHydrator($em); + $targetPersister = $em->getUnitOfWork()->getEntityPersister($mapping['targetEntity']); + return new DefaultCollectionHydrator($em, $targetPersister->getCacheRegion()); } /** @@ -218,11 +206,9 @@ public function getRegion(array $cache) $cacheAdapter->setNamespace($cache['region']); - if ($cacheAdapter instanceof MultiGetCache) { - $region = new DefaultMultiGetRegion($cache['region'], $cacheAdapter, $this->regionsConfig->getLifetime($cache['region'])); - } else { - $region = new DefaultRegion($cache['region'], $cacheAdapter, $this->regionsConfig->getLifetime($cache['region'])); - } + $region = ($cacheAdapter instanceof MultiGetCache) + ? new DefaultMultiGetRegion($cache['region'], $cacheAdapter, $this->regionsConfig->getLifetime($cache['region'])) + : new DefaultRegion($cache['region'], $cacheAdapter, $this->regionsConfig->getLifetime($cache['region'])); if ($cache['usage'] === ClassMetadata::CACHE_USAGE_READ_WRITE) { diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php index ea5b9cf9e15..cb872e52077 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php @@ -64,7 +64,6 @@ public function testBuildCachedEntityPersisterReadOnly() ->with($this->equalTo($metadata->cache)) ->will($this->returnValue($region)); - $cachedPersister = $this->factory->buildCachedEntityPersister($em, $persister, $metadata); $this->assertInstanceOf('Doctrine\ORM\Cache\Persister\Entity\CachedEntityPersister', $cachedPersister); @@ -282,17 +281,4 @@ public function testBuildsNewNamespacedCacheInstancePerRegionInstance() $this->assertSame('bar', $barRegion->getCache()->getNamespace()); } - public function testBuildCachedCollectioHydrator() - { - $em = $this->em; - $entityName = 'Doctrine\Tests\Models\Cache\State'; - $metadata = $em->getClassMetadata($entityName); - $mapping = $metadata->associationMappings['cities']; - - $mapping['cache']['usage'] = ClassMetadata::CACHE_USAGE_READ_ONLY; - - $hydrator = $this->factory->buildCollectionHydrator($em, $mapping); - - $this->assertInstanceOf('Doctrine\ORM\Cache\MultiGetCollectionHydrator', $hydrator); - } } diff --git a/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php b/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php index 74082d8a7bb..ed0456e3908 100644 --- a/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Cache/DefaultCollectionHydratorTest.php @@ -29,7 +29,8 @@ protected function setUp() $this->enableSecondLevelCache(); parent::setUp(); - $this->structure = new DefaultCollectionHydrator($this->_em); + $targetPersister = $this->_em->getUnitOfWork()->getEntityPersister(City::CLASSNAME); + $this->structure = new DefaultCollectionHydrator($this->_em, $targetPersister); } public function testImplementsCollectionEntryStructure() @@ -41,8 +42,8 @@ public function testLoadCacheCollection() { $targetRegion = $this->_em->getCache()->getEntityCacheRegion(City::CLASSNAME); $entry = new CollectionCacheEntry(array( - array('id'=>31), - array('id'=>32), + new EntityCacheKey(City::CLASSNAME, array('id'=>31)), + new EntityCacheKey(City::CLASSNAME, array('id'=>32)), )); $targetRegion->put(new EntityCacheKey(City::CLASSNAME, array('id'=>31)), new EntityCacheEntry(City::CLASSNAME, array('id'=>31, 'name'=>'Foo')));