1
0
mirror of synced 2025-01-31 20:41:44 +03:00

ClassMetadataFactory should support fallback (event-based) logic for hooking into failed ClassMetadata loading

This commit is contained in:
Marco Pivetta 2014-11-11 15:50:13 +01:00
parent d66356542d
commit efd4500e6b

View File

@ -2,6 +2,8 @@
namespace Doctrine\Tests\ORM\Mapping; namespace Doctrine\Tests\ORM\Mapping;
use Doctrine\ORM\Event\OnClassMetadataNotFoundEventArgs;
use Doctrine\ORM\Events;
use Doctrine\Tests\Mocks\MetadataDriverMock; use Doctrine\Tests\Mocks\MetadataDriverMock;
use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Mocks\EntityManagerMock;
use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\ConnectionMock;
@ -322,6 +324,35 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals('group-id', $groups['joinTable']['inverseJoinColumns'][0]['referencedColumnName']); $this->assertEquals('group-id', $groups['joinTable']['inverseJoinColumns'][0]['referencedColumnName']);
} }
public function testFallbackLoadingCausesEventTriggeringThatCanModifyFetchedMetadata()
{
$test = $this;
/* @var $metadata \Doctrine\Common\Persistence\Mapping\ClassMetadata */
$metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$cmf = new ClassMetadataFactory();
$mockDriver = new MetadataDriverMock();
$em = $this->_createEntityManager($mockDriver);
$listener = $this->getMock('stdClass', array('onClassMetadataNotFound'));
$eventManager = $em->getEventManager();
$cmf->setEntityManager($em);
$listener
->expects($this->any())
->method('onClassMetadataNotFound')
->will($this->returnCallback(function (OnClassMetadataNotFoundEventArgs $args) use ($metadata, $em, $test) {
$test->assertNull($args->getFoundMetadata());
$test->assertSame('Foo', $args->getClassName());
$test->assertSame($em, $args->getEntityManager());
$args->setFoundMetadata($metadata);
}));
$eventManager->addEventListener(array(Events::onClassMetadataNotFound), $listener);
$this->assertSame($metadata, $cmf->getMetadataFor('Foo'));
}
/** /**
* @group DDC-3427 * @group DDC-3427
*/ */