diff --git a/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php b/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php index 586b2da2c..cba424b06 100644 --- a/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php +++ b/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php @@ -208,7 +208,7 @@ public function getMetadataFor($className) try { if ($this->cacheDriver) { - if (($cached = $this->cacheDriver->fetch($realClassName . $this->cacheSalt)) !== false) { + if (($cached = $this->cacheDriver->fetch($realClassName . $this->cacheSalt)) instanceof ClassMetadata) { $this->loadedMetadata[$realClassName] = $cached; $this->wakeupReflection($cached, $this->getReflectionService()); diff --git a/tests/Doctrine/Tests/Common/Persistence/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/Common/Persistence/Mapping/ClassMetadataFactoryTest.php index 0b0a3e4af..ddcdce480 100644 --- a/tests/Doctrine/Tests/Common/Persistence/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/Common/Persistence/Mapping/ClassMetadataFactoryTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\Common\Persistence\Mapping; +use Doctrine\Common\Cache\Cache; use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Common\Persistence\Mapping\MappingException; use Doctrine\Tests\DoctrineTestCase; @@ -10,6 +11,9 @@ use Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory; use Doctrine\Common\Cache\ArrayCache; +/** + * @covers \Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory + */ class ClassMetadataFactoryTest extends DoctrineTestCase { /** @@ -130,6 +134,30 @@ public function testWillFailOnFallbackFailureWithNotLoadedMetadata() $this->cmf->getMetadataFor('Foo'); } + + /** + * @group 717 + */ + public function testWillIgnoreCacheEntriesThatAreNotMetadataInstances() + { + /* @var $cacheDriver Cache|\PHPUnit_Framework_MockObject_MockObject */ + $cacheDriver = $this->createMock(Cache::class); + + $this->cmf->setCacheDriver($cacheDriver); + + $cacheDriver->expects(self::once())->method('fetch')->with('Foo$CLASSMETADATA')->willReturn(new \stdClass()); + + /* @var $metadata ClassMetadata */ + $metadata = $this->createMock(ClassMetadata::class); + + $fallbackCallback = $this->getMockBuilder(\stdClass::class)->setMethods(['__invoke'])->getMock(); + + $fallbackCallback->expects(self::any())->method('__invoke')->willReturn($metadata); + + $this->cmf->fallbackCallback = $fallbackCallback; + + self::assertSame($metadata, $this->cmf->getMetadataFor('Foo')); + } } class TestClassMetadataFactory extends AbstractClassMetadataFactory