2013-09-19 16:16:33 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
|
|
|
use Doctrine\Common\EventSubscriber;
|
|
|
|
use Doctrine\ORM\Event\PreFlushEventArgs;
|
|
|
|
|
|
|
|
/**
|
2013-09-19 17:16:51 +04:00
|
|
|
* @group DDC-2692
|
2013-09-19 16:16:33 +04:00
|
|
|
*/
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-09-19 17:16:51 +04:00
|
|
|
public function testIsListenerCalledOnlyOnceOnPreFlush()
|
2013-09-19 16:16:33 +04:00
|
|
|
{
|
2013-09-20 11:20:58 +04:00
|
|
|
$listener = $this->getMock('Doctrine\Tests\ORM\Functional\Ticket\DDC2692Listener', array('preFlush'));
|
2013-09-19 16:16:33 +04:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
2013-09-20 11:20:58 +04:00
|
|
|
class DDC2692Listener implements EventSubscriber {
|
2013-09-19 16:16:33 +04:00
|
|
|
|
|
|
|
public function getSubscribedEvents() {
|
|
|
|
return array(\Doctrine\ORM\Events::preFlush);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function preFlush(PreFlushEventArgs $args) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|