1
0
mirror of synced 2024-12-13 06:46:03 +03:00

Merge pull request #794 from stefankleff/patch-1

Multiple invokation of listeners on PreFlush event
This commit is contained in:
Benjamin Eberlei 2014-01-02 13:16:21 -08:00
commit 3a8aaea14a
2 changed files with 64 additions and 1 deletions

View File

@ -548,7 +548,7 @@ class UnitOfWork implements PropertyChangedListener
$class = $this->em->getClassMetadata(get_class($entity)); $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) { if ($invoke !== ListenersInvoker::INVOKE_NONE) {
$this->listenersInvoker->invoke($class, Events::preFlush, $entity, new PreFlushEventArgs($this->em), $invoke); $this->listenersInvoker->invoke($class, Events::preFlush, $entity, new PreFlushEventArgs($this->em), $invoke);

View 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) {
}
}