test event listeners lifecycle callback
This commit is contained in:
parent
256cecbefa
commit
69bfc71b6a
@ -15,9 +15,6 @@ namespace Doctrine\Tests\Models\Company;
|
||||
* "manager" = "CompanyManager",
|
||||
* "employee" = "CompanyEmployee"
|
||||
* })
|
||||
* @EntityListeners(callbacks = {
|
||||
* @LifecycleCallback(\Doctrine\ORM\Events::prePersist, method = "prePersistHandler")
|
||||
* })
|
||||
*
|
||||
* @NamedNativeQueries({
|
||||
* @NamedNativeQuery(
|
||||
@ -82,8 +79,6 @@ class CompanyPerson
|
||||
*/
|
||||
private $friends;
|
||||
|
||||
public $prePersistHandlerCalls = array();
|
||||
|
||||
public function __construct() {
|
||||
$this->friends = new \Doctrine\Common\Collections\ArrayCollection;
|
||||
}
|
||||
@ -122,12 +117,6 @@ class CompanyPerson
|
||||
}
|
||||
}
|
||||
|
||||
public function prePersistHandler($event)
|
||||
{
|
||||
$this->prePersistHandlerCalls[] = $event;
|
||||
}
|
||||
|
||||
|
||||
public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata)
|
||||
{
|
||||
|
||||
|
@ -11,6 +11,7 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
parent::setUp();
|
||||
try {
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\EntityListenersLifecycleCallback'),
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackEventArgEntity'),
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity'),
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestUser'),
|
||||
@ -259,16 +260,22 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
*/
|
||||
public function testEventListenersLifecycleCallback()
|
||||
{
|
||||
$e = new \Doctrine\Tests\Models\Company\CompanyPerson;
|
||||
$e->setName('Fabio B. Silva');
|
||||
$e = new EntityListenersLifecycleCallback;
|
||||
$e->value = 'foo';
|
||||
|
||||
$this->_em->persist($e);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertCount(1, $e->prePersistHandlerCalls);
|
||||
$this->assertCount(2, $e->calls);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Doctrine\ORM\Event\LifecycleEventArgs',
|
||||
$e->prePersistHandlerCalls[0]
|
||||
$e->calls['prePersistHandler']
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Doctrine\ORM\Event\LifecycleEventArgs',
|
||||
$e->calls['postPersistHandler']
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -400,6 +407,34 @@ class LifecycleListenerPreUpdate
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @EntityListeners(callbacks = {
|
||||
* @LifecycleCallback(\Doctrine\ORM\Events::prePersist, method = "prePersistHandler"),
|
||||
* @LifecycleCallback(\Doctrine\ORM\Events::postPersist, method = "postPersistHandler"),
|
||||
* })
|
||||
*/
|
||||
class EntityListenersLifecycleCallback
|
||||
{
|
||||
/** @Id @Column(type="integer") @GeneratedValue */
|
||||
public $id;
|
||||
|
||||
/** @Column() */
|
||||
public $value;
|
||||
|
||||
public $calls = array();
|
||||
|
||||
public function prePersistHandler($event)
|
||||
{
|
||||
$this->calls[__FUNCTION__] = $event;
|
||||
}
|
||||
|
||||
public function postPersistHandler(\Doctrine\ORM\Event\LifecycleEventArgs $event)
|
||||
{
|
||||
$this->calls[__FUNCTION__] = $event;
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity @HasLifecycleCallbacks */
|
||||
class LifecycleCallbackEventArgEntity
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user