DDC1080Test.php 6.2 KB

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