Merge pull request #794 from stefankleff/patch-1
Multiple invokation of listeners on PreFlush event
This commit is contained in:
commit
3a8aaea14a
@ -548,7 +548,7 @@ class UnitOfWork implements PropertyChangedListener
|
||||
$class = $this->em->getClassMetadata(get_class($entity));
|
||||
}
|
||||
|
||||
$invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::preFlush);
|
||||
$invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::preFlush) & ~ListenersInvoker::INVOKE_MANAGER;
|
||||
|
||||
if ($invoke !== ListenersInvoker::INVOKE_NONE) {
|
||||
$this->listenersInvoker->invoke($class, Events::preFlush, $entity, new PreFlushEventArgs($this->em), $invoke);
|
||||
|
63
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php
Normal file
63
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2692Test.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\EventSubscriber;
|
||||
use Doctrine\ORM\Event\PreFlushEventArgs;
|
||||
|
||||
/**
|
||||
* @group DDC-2692
|
||||
*/
|
||||
class DDC2692Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
protected function setup()
|
||||
{
|
||||
parent::setup();
|
||||
|
||||
try {
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2692Foo'),
|
||||
));
|
||||
} catch(\Exception $e) {
|
||||
return;
|
||||
}
|
||||
$this->_em->clear();
|
||||
}
|
||||
|
||||
public function testIsListenerCalledOnlyOnceOnPreFlush()
|
||||
{
|
||||
$listener = $this->getMock('Doctrine\Tests\ORM\Functional\Ticket\DDC2692Listener', array('preFlush'));
|
||||
$listener->expects($this->once())->method('preFlush');
|
||||
|
||||
$this->_em->getEventManager()->addEventSubscriber($listener);
|
||||
|
||||
$this->_em->persist(new DDC2692Foo);
|
||||
$this->_em->persist(new DDC2692Foo);
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @Entity @Table(name="ddc_2692_foo")
|
||||
*/
|
||||
class DDC2692Foo
|
||||
{
|
||||
/** @Id @Column(type="integer") @GeneratedValue */
|
||||
public $id;
|
||||
}
|
||||
|
||||
class DDC2692Listener implements EventSubscriber {
|
||||
|
||||
public function getSubscribedEvents() {
|
||||
return array(\Doctrine\ORM\Events::preFlush);
|
||||
}
|
||||
|
||||
public function preFlush(PreFlushEventArgs $args) {
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user