Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / Ticket / DDC1080Test.php
1 <?php
2
3 namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5 require_once __DIR__ . '/../../../TestInit.php';
6
7 /**
8  * @group DDC-1080
9  */
10 class DDC1080Test extends \Doctrine\Tests\OrmFunctionalTestCase
11 {
12     public function testHydration()
13     {
14         $this->_schemaTool->createSchema(array(
15             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080Foo'),
16             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080Bar'),
17             $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080FooBar'),
18         ));
19
20         $foo1 = new DDC1080Foo();
21         $foo1->setFooTitle('foo title 1');
22         $foo2 = new DDC1080Foo();
23         $foo2->setFooTitle('foo title 2');
24
25         $bar1 = new DDC1080Bar();
26         $bar1->setBarTitle('bar title 1');
27         $bar2 = new DDC1080Bar();
28         $bar2->setBarTitle('bar title 2');
29         $bar3 = new DDC1080Bar();
30         $bar3->setBarTitle('bar title 3');
31
32         $foobar1 = new DDC1080FooBar();
33         $foobar1->setFoo($foo1);
34         $foobar1->setBar($bar1);
35         $foobar1->setOrderNr(0);
36
37         $foobar2 = new DDC1080FooBar();
38         $foobar2->setFoo($foo1);
39         $foobar2->setBar($bar2);
40         $foobar2->setOrderNr(0);
41
42         $foobar3 = new DDC1080FooBar();
43         $foobar3->setFoo($foo1);
44         $foobar3->setBar($bar3);
45         $foobar3->setOrderNr(0);
46
47         $this->_em->persist($foo1);
48         $this->_em->persist($foo2);
49         $this->_em->persist($bar1);
50         $this->_em->persist($bar2);
51         $this->_em->persist($bar3);
52         $this->_em->flush();
53
54         $this->_em->persist($foobar1);
55         $this->_em->persist($foobar2);
56         $this->_em->persist($foobar3);
57         $this->_em->flush();
58         $this->_em->clear();
59
60         $foo = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC1080Foo', $foo1->getFooId());
61         $fooBars = $foo->getFooBars();
62
63         $this->assertEquals(3, count($fooBars), "Should return three foobars.");
64     }
65 }
66
67
68 /**
69  * @Entity
70  * @Table(name="foo")
71  */
72 class DDC1080Foo
73 {
74
75     /**
76      * @Id
77      * @Column(name="fooID", type="integer")
78      * @GeneratedValue(strategy="AUTO")
79      */
80     protected $_fooID;
81     /**
82      * @Column(name="fooTitle", type="string")
83      */
84     protected $_fooTitle;
85     /**
86      * @OneToMany(targetEntity="DDC1080FooBar", mappedBy="_foo",
87      * cascade={"persist"})
88      * @OrderBy({"_orderNr"="ASC"})
89      */
90     protected $_fooBars;
91
92     public function __construct()
93     {
94         $this->_fooBars = new \Doctrine\Common\Collections\ArrayCollection();
95     }
96
97     /**
98      * @return the $fooID
99      */
100     public function getFooID()
101     {
102         return $this->_fooID;
103     }
104
105     /**
106      * @return the $fooTitle
107      */
108     public function getFooTitle()
109     {
110         return $this->_fooTitle;
111     }
112
113     /**
114      * @return the $fooBars
115      */
116     public function getFooBars()
117     {
118         return $this->_fooBars;
119     }
120
121     /**
122      * @param field_type $fooID
123      */
124     public function setFooID($fooID)
125     {
126         $this->_fooID = $fooID;
127     }
128
129     /**
130      * @param field_type $fooTitle
131      */
132     public function setFooTitle($fooTitle)
133     {
134         $this->_fooTitle = $fooTitle;
135     }
136
137     /**
138      * @param field_type $fooBars
139      */
140     public function setFooBars($fooBars)
141     {
142         $this->_fooBars = $fooBars;
143     }
144
145 }
146 /**
147  * @Entity
148  * @Table(name="bar")
149  */
150 class DDC1080Bar
151 {
152
153     /**
154      * @Id
155      * @Column(name="barID", type="integer")
156      * @GeneratedValue(strategy="AUTO")
157      */
158     protected $_barID;
159     /**
160      * @Column(name="barTitle", type="string")
161      */
162     protected $_barTitle;
163     /**
164      * @OneToMany(targetEntity="DDC1080FooBar", mappedBy="_bar",
165      * cascade={"persist"})
166      * @OrderBy({"_orderNr"="ASC"})
167      */
168     protected $_fooBars;
169
170     public function __construct()
171     {
172         $this->_fooBars = new \Doctrine\Common\Collections\ArrayCollection();
173     }
174
175     /**
176      * @return the $barID
177      */
178     public function getBarID()
179     {
180         return $this->_barID;
181     }
182
183     /**
184      * @return the $barTitle
185      */
186     public function getBarTitle()
187     {
188         return $this->_barTitle;
189     }
190
191     /**
192      * @return the $fooBars
193      */
194     public function getFooBars()
195     {
196         return $this->_fooBars;
197     }
198
199     /**
200      * @param field_type $barID
201      */
202     public function setBarID($barID)
203     {
204         $this->_barID = $barID;
205     }
206
207     /**
208      * @param field_type $barTitle
209      */
210     public function setBarTitle($barTitle)
211     {
212         $this->_barTitle = $barTitle;
213     }
214
215     /**
216      * @param field_type $fooBars
217      */
218     public function setFooBars($fooBars)
219     {
220         $this->_fooBars = $fooBars;
221     }
222
223 }
224
225 /**
226  * @Table(name="fooBar")
227  * @Entity
228  */
229 class DDC1080FooBar
230 {
231
232     /**
233      * @ManyToOne(targetEntity="DDC1080Foo")
234      * @JoinColumn(name="fooID", referencedColumnName="fooID")
235      * @Id
236      */
237     protected $_foo = null;
238     /**
239      * @ManyToOne(targetEntity="DDC1080Bar")
240      * @JoinColumn(name="barID", referencedColumnName="barID")
241      * @Id
242      */
243     protected $_bar = null;
244     /**
245      * @var integer orderNr
246      * @Column(name="orderNr", type="integer", nullable=false)
247      */
248     protected $_orderNr = null;
249
250     /**
251      * Retrieve the foo property
252      *
253      * @return DDC1080Foo
254      */
255     public function getFoo()
256     {
257         return $this->_foo;
258     }
259
260     /**
261      * Set the foo property
262      *
263      * @param DDC1080Foo $foo
264      * @return DDC1080FooBar
265      */
266     public function setFoo($foo)
267     {
268         $this->_foo = $foo;
269         return $this;
270     }
271
272     /**
273      * Retrieve the bar property
274      *
275      * @return DDC1080Bar
276      */
277     public function getBar()
278     {
279         return $this->_bar;
280     }
281
282     /**
283      * Set the bar property
284      *
285      * @param DDC1080Bar $bar
286      * @return DDC1080FooBar
287      */
288     public function setBar($bar)
289     {
290         $this->_bar = $bar;
291         return $this;
292     }
293
294     /**
295      * Retrieve the orderNr property
296      *
297      * @return integer|null
298      */
299     public function getOrderNr()
300     {
301         return $this->_orderNr;
302     }
303
304     /**
305      * Set the orderNr property
306      *
307      * @param integer|null $orderNr
308      * @return DDC1080FooBar
309      */
310     public function setOrderNr($orderNr)
311     {
312         $this->_orderNr = $orderNr;
313         return $this;
314     }
315
316 }
317