Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1654Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 /**
6  * @group DDC-1654
7  */
8 class DDC1654Test extends \Doctrine\Tests\OrmFunctionalTestCase
9 {
10     public function setUp()
11     {
12         parent::setUp();
13         $this->setUpEntitySchema(array(
14             __NAMESPACE__ . '\\DDC1654Post',
15             __NAMESPACE__ . '\\DDC1654Comment',
16         ));
17     }
18
19     public function testManyToManyRemoveFromCollectionOrphanRemoval()
20     {
21         $post = new DDC1654Post();
22         $post->comments[] = new DDC1654Comment();
23         $post->comments[] = new DDC1654Comment();
24
25         $this->_em->persist($post);
26         $this->_em->flush();
27
28         $post->comments->remove(0);
29         $post->comments->remove(1);
30
31         $this->_em->flush();
32         $this->_em->clear();
33
34         $comments = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1654Comment')->findAll();
35         $this->assertEquals(0, count($comments));
36     }
37
38     public function testManyToManyRemoveElementFromCollectionOrphanRemoval()
39     {
40         $post = new DDC1654Post();
41         $post->comments[] = new DDC1654Comment();
42         $post->comments[] = new DDC1654Comment();
43
44         $this->_em->persist($post);
45         $this->_em->flush();
46
47         $post->comments->removeElement($post->comments[0]);
48         $post->comments->removeElement($post->comments[1]);
49
50         $this->_em->flush();
51         $this->_em->clear();
52
53         $comments = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1654Comment')->findAll();
54         $this->assertEquals(0, count($comments));
55     }
56
57     public function testManyToManyClearCollectionOrphanRemoval()
58     {
59         $post = new DDC1654Post();
60         $post->comments[] = new DDC1654Comment();
61         $post->comments[] = new DDC1654Comment();
62
63         $this->_em->persist($post);
64         $this->_em->flush();
65
66         $post->comments->clear();
67
68         $this->_em->flush();
69         $this->_em->clear();
70
71         $comments = $this->_em->getRepository(__NAMESPACE__ . '\\DDC1654Comment')->findAll();
72         $this->assertEquals(0, count($comments));
73
74     }
75 }
76
77 /**
78  * @Entity
79  */
80 class DDC1654Post
81 {
82     /**
83      * @Id @Column(type="integer") @GeneratedValue
84      */
85     public $id;
86
87     /**
88      * @ManyToMany(targetEntity="DDC1654Comment", orphanRemoval=true,
89      * cascade={"persist"})
90      */
91     public $comments = array();
92 }
93
94 /**
95  * @Entity
96  */
97 class DDC1654Comment
98 {
99     /**
100      * @Id @Column(type="integer") @GeneratedValue
101      */
102     public $id;
103 }