Skip to content

Commit

Permalink
Changed some tests to be compatible with the new implementation of
Browse files Browse the repository at this point in the history
multiget region
  • Loading branch information
goetas committed Jan 17, 2015
1 parent c96dd0d commit cc47d6a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 36 deletions.
24 changes: 5 additions & 19 deletions lib/Doctrine/ORM/Cache/DefaultCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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) {

Expand Down
14 changes: 0 additions & 14 deletions tests/Doctrine/Tests/ORM/Cache/DefaultCacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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')));
Expand Down

0 comments on commit cc47d6a

Please sign in to comment.