X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FFunctional%2FTicket%2FDDC1654Test.php;fp=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FFunctional%2FTicket%2FDDC1654Test.php;h=016961935a1e3abfed3f3cd4c4232fb45e71a382;hb=8b04b2d11798dee4f3e1358e4f43e97a6df851f6;hp=0000000000000000000000000000000000000000;hpb=73568cf05a785a45f94ca3f2351d9e07bf917958;p=zf2.biz%2Fgalerie.git diff --git a/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1654Test.php b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1654Test.php new file mode 100644 index 0000000..0169619 --- /dev/null +++ b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1654Test.php @@ -0,0 +1,103 @@ +setUpEntitySchema(array( + __NAMESPACE__ . '\\DDC1654Post', + __NAMESPACE__ . '\\DDC1654Comment', + )); + } + + public function testManyToManyRemoveFromCollectionOrphanRemoval() + { + $post = new DDC1654Post(); + $post->comments[] = new DDC1654Comment(); + $post->comments[] = new DDC1654Comment(); + + $this->_em->persist($post); + $this->_em->flush(); + + $post->comments->remove(0); + $post->comments->remove(1); + + $this->_em->flush(); + $this->_em->clear(); + + $comments = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1654Comment')->findAll(); + $this->assertEquals(0, count($comments)); + } + + public function testManyToManyRemoveElementFromCollectionOrphanRemoval() + { + $post = new DDC1654Post(); + $post->comments[] = new DDC1654Comment(); + $post->comments[] = new DDC1654Comment(); + + $this->_em->persist($post); + $this->_em->flush(); + + $post->comments->removeElement($post->comments[0]); + $post->comments->removeElement($post->comments[1]); + + $this->_em->flush(); + $this->_em->clear(); + + $comments = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1654Comment')->findAll(); + $this->assertEquals(0, count($comments)); + } + + public function testManyToManyClearCollectionOrphanRemoval() + { + $post = new DDC1654Post(); + $post->comments[] = new DDC1654Comment(); + $post->comments[] = new DDC1654Comment(); + + $this->_em->persist($post); + $this->_em->flush(); + + $post->comments->clear(); + + $this->_em->flush(); + $this->_em->clear(); + + $comments = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1654Comment')->findAll(); + $this->assertEquals(0, count($comments)); + + } +} + +/** + * @Entity + */ +class DDC1654Post +{ + /** + * @Id @Column(type="integer") @GeneratedValue + */ + public $id; + + /** + * @ManyToMany(targetEntity="DDC1654Comment", orphanRemoval=true, + * cascade={"persist"}) + */ + public $comments = array(); +} + +/** + * @Entity + */ +class DDC1654Comment +{ + /** + * @Id @Column(type="integer") @GeneratedValue + */ + public $id; +}