ClassMetadataFactory
should support fallback (event-based) logic for hooking into failed ClassMetadata
loading
This commit is contained in:
parent
d66356542d
commit
efd4500e6b
@ -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
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user