DDC1526Test.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. /**
  4. * @group DDC-1526
  5. */
  6. class DDC1526Test extends \Doctrine\Tests\OrmFunctionalTestCase
  7. {
  8. public function setUp()
  9. {
  10. parent::setUp();
  11. $this->_schemaTool->createSchema(array(
  12. $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1526Menu'),
  13. ));
  14. }
  15. public function testIssue()
  16. {
  17. $parents = array();
  18. for ($i = 0; $i < 9; $i++) {
  19. $entity = new DDC1526Menu;
  20. if (isset ($parents[($i % 3)])) {
  21. $entity->parent = $parents[($i%3)];
  22. }
  23. $this->_em->persist($entity);
  24. $parents[$i] = $entity;
  25. }
  26. $this->_em->flush();
  27. $this->_em->clear();
  28. $dql = "SELECT m, c
  29. FROM " . __NAMESPACE__ . "\DDC1526Menu m
  30. LEFT JOIN m.children c";
  31. $menus = $this->_em->createQuery($dql)->getResult();
  32. // All Children collection now have to be initiailzed
  33. foreach ($menus as $menu) {
  34. $this->assertTrue($menu->children->isInitialized());
  35. }
  36. }
  37. }
  38. /**
  39. * @Entity
  40. */
  41. class DDC1526Menu
  42. {
  43. /**
  44. * @Column(type="integer")
  45. * @Id
  46. * @GeneratedValue
  47. */
  48. public $id;
  49. /**
  50. * @ManyToOne(targetEntity="DDC1526Menu", inversedBy="children")
  51. */
  52. public $parent;
  53. /**
  54. * @OneToMany(targetEntity="DDC1526Menu", mappedBy="parent")
  55. */
  56. public $children;
  57. }