1
0
mirror of synced 2025-02-20 22:23:14 +03:00

Changed some tests to be compatible with the new implementation of

multiget region
This commit is contained in:
Asmir Mustafic 2015-01-17 18:37:06 +01:00 committed by Marco Pivetta
parent e73bd9e9bb
commit 3f64f3252b
3 changed files with 9 additions and 36 deletions

View File

@ -181,20 +181,8 @@ class DefaultCacheFactory implements CacheFactory
*/
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 @@ class DefaultCacheFactory implements CacheFactory
$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) {

View File

@ -64,7 +64,6 @@ class DefaultCacheFactoryTest extends OrmTestCase
->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 @@ class DefaultCacheFactoryTest extends OrmTestCase
$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);
}
}

View File

@ -29,7 +29,8 @@ class DefaultCollectionHydratorTest extends OrmFunctionalTestCase
$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 @@ class DefaultCollectionHydratorTest extends OrmFunctionalTestCase
{
$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')));