added test for PreFlush lifetime event
This commit is contained in:
parent
66e2a9260e
commit
20ed8869e4
@ -43,6 +43,29 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals('changed from preUpdate callback!', $result[0]->value);
|
||||
}
|
||||
|
||||
public function testPreFlushCallbacksAreInvoked()
|
||||
{
|
||||
$entity = new LifecycleCallbackTestEntity;
|
||||
$entity->value = 'hello';
|
||||
$this->_em->persist($entity);
|
||||
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertTrue($entity->prePersistCallbackInvoked);
|
||||
$this->assertTrue($entity->preFlushCallbackInvoked);
|
||||
|
||||
$entity->preFlushCallbackInvoked = false;
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertTrue($entity->preFlushCallbackInvoked);
|
||||
|
||||
$entity->value = 'bye';
|
||||
$entity->preFlushCallbackInvoked = false;
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertTrue($entity->preFlushCallbackInvoked);
|
||||
}
|
||||
|
||||
public function testChangesDontGetLost()
|
||||
{
|
||||
$user = new LifecycleCallbackTestUser;
|
||||
@ -190,6 +213,8 @@ class LifecycleCallbackTestEntity
|
||||
public $postPersistCallbackInvoked = false;
|
||||
public $postLoadCallbackInvoked = false;
|
||||
|
||||
public $preFlushCallbackInvoked = false;
|
||||
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
@ -233,6 +258,11 @@ class LifecycleCallbackTestEntity
|
||||
public function doStuffOnPreUpdate() {
|
||||
$this->value = 'changed from preUpdate callback!';
|
||||
}
|
||||
|
||||
/** @PreFlush */
|
||||
public function doStuffOnPreFlush() {
|
||||
$this->preFlushCallbackInvoked = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user