1
0
mirror of synced 2025-03-21 15:33:51 +03:00

#1001 DDC-3005 - Testing HydrationCompleteHandler with multiple deferred entities postLoads

This commit is contained in:
Marco Pivetta 2015-01-13 00:45:07 +01:00
parent 948d6c2b9f
commit 29d4d342bd

View File

@ -60,6 +60,8 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase
/** /**
* @dataProvider testGetValidListenerInvocationFlags * @dataProvider testGetValidListenerInvocationFlags
*
* @param int $listenersFlag
*/ */
public function testDefersPostLoadOfEntity($listenersFlag) public function testDefersPostLoadOfEntity($listenersFlag)
{ {
@ -93,6 +95,48 @@ class HydrationCompleteHandlerTest extends PHPUnit_Framework_TestCase
$this->handler->hydrationComplete(); $this->handler->hydrationComplete();
} }
/**
* @dataProvider testGetValidListenerInvocationFlags
*
* @param int $listenersFlag
*/
public function testDefersMultiplePostLoadOfEntity($listenersFlag)
{
/* @var $metadata1 \Doctrine\ORM\Mapping\ClassMetadata */
/* @var $metadata2 \Doctrine\ORM\Mapping\ClassMetadata */
$metadata1 = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false);
$metadata2 = $this->getMock('Doctrine\ORM\Mapping\ClassMetadata', array(), array(), '', false);
$entity1 = new stdClass();
$entity2 = new stdClass();
$entityManager = $this->entityManager;
$this
->listenersInvoker
->expects($this->any())
->method('getSubscribedSystems')
->with($this->logicalOr($metadata1, $metadata2))
->will($this->returnValue($listenersFlag));
$this->handler->deferPostLoadInvoking($metadata1, $entity1);
$this->handler->deferPostLoadInvoking($metadata2, $entity2);
$this
->listenersInvoker
->expects($this->exactly(2))
->method('invoke')
->with(
$this->logicalOr($metadata1, $metadata2),
Events::postLoad,
$this->logicalOr($entity1, $entity2),
$this->callback(function (LifecycleEventArgs $args) use ($entityManager, $entity1, $entity2) {
return in_array($args->getEntity(), array($entity1, $entity2), true)
&& $entityManager === $args->getObjectManager();
}),
$listenersFlag
);
$this->handler->hydrationComplete();
}
public function testSkipsDeferredPostLoadOfMetadataWithNoInvokedListeners() public function testSkipsDeferredPostLoadOfMetadataWithNoInvokedListeners()
{ {