Commit 7542482e authored by beberlei's avatar beberlei

[2.0] DDC-113 - Added test-case that shows it works.

parent fade63a2
...@@ -11,7 +11,8 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -11,7 +11,8 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
try { try {
$this->_schemaTool->createSchema(array( $this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity'), $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) { } catch (\Exception $e) {
// Swallow all exceptions. We do not test the schema tool here. // Swallow all exceptions. We do not test the schema tool here.
...@@ -79,6 +80,25 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase ...@@ -79,6 +80,25 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
$reference->getId(); // trigger proxy load $reference->getId(); // trigger proxy load
$this->assertTrue($reference->postLoadCallbackInvoked); $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 */ /** @Entity @HasLifecycleCallbacks */
...@@ -116,10 +136,16 @@ class LifecycleCallbackTestEntity ...@@ -116,10 +136,16 @@ class LifecycleCallbackTestEntity
*/ */
private $id; private $id;
/** /**
* @Column(type="string") * @Column(type="string", nullable=true)
*/ */
public $value; public $value;
/**
* @ManyToOne(targetEntity="LifecycleCallbackCascader")
* @JoinColumn(name="cascader_id", referencedColumnName="id")
*/
public $cascader;
public function getId() { public function getId() {
return $this->id; return $this->id;
} }
...@@ -143,4 +169,27 @@ class LifecycleCallbackTestEntity ...@@ -143,4 +169,27 @@ class LifecycleCallbackTestEntity
public function doStuffOnPreUpdate() { public function doStuffOnPreUpdate() {
$this->value = 'changed from preUpdate callback!'; $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();
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment