[2.0] DDC-113 - Added test-case that shows it works.
This commit is contained in:
parent
fade63a29c
commit
7542482ea7
1 changed files with 51 additions and 2 deletions
|
@ -11,7 +11,8 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||
try {
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity'),
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestUser')
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestUser'),
|
||||
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackCascader'),
|
||||
));
|
||||
} catch (\Exception $e) {
|
||||
// Swallow all exceptions. We do not test the schema tool here.
|
||||
|
@ -79,6 +80,25 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||
$reference->getId(); // trigger proxy load
|
||||
$this->assertTrue($reference->postLoadCallbackInvoked);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-113
|
||||
*/
|
||||
public function testCascadedEntitiesCallsPrePersist()
|
||||
{
|
||||
$e1 = new LifecycleCallbackTestEntity;
|
||||
$e2 = new LifecycleCallbackTestEntity;
|
||||
|
||||
$c = new LifecycleCallbackCascader();
|
||||
$c->entities[] = $e1;
|
||||
$c->entities[] = $e2;
|
||||
|
||||
$this->_em->persist($c);
|
||||
$this->_em->flush();
|
||||
|
||||
$this->assertTrue($e1->prePersistCallbackInvoked);
|
||||
$this->assertTrue($e2->prePersistCallbackInvoked);
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity @HasLifecycleCallbacks */
|
||||
|
@ -116,10 +136,16 @@ class LifecycleCallbackTestEntity
|
|||
*/
|
||||
private $id;
|
||||
/**
|
||||
* @Column(type="string")
|
||||
* @Column(type="string", nullable=true)
|
||||
*/
|
||||
public $value;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="LifecycleCallbackCascader")
|
||||
* @JoinColumn(name="cascader_id", referencedColumnName="id")
|
||||
*/
|
||||
public $cascader;
|
||||
|
||||
public function getId() {
|
||||
return $this->id;
|
||||
}
|
||||
|
@ -143,4 +169,27 @@ class LifecycleCallbackTestEntity
|
|||
public function doStuffOnPreUpdate() {
|
||||
$this->value = 'changed from preUpdate callback!';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="lc_cb_test_cascade")
|
||||
*/
|
||||
class LifecycleCallbackCascader
|
||||
{
|
||||
/**
|
||||
* @Id @Column(type="integer")
|
||||
* @GeneratedValue(strategy="AUTO")
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @OneToMany(targetEntity="LifecycleCallbackTestEntity", mappedBy="product", cascade={"persist"})
|
||||
*/
|
||||
public $entities;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->entities = new \Doctrine\Common\Collections\ArrayCollection();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue