DDC1514Test.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\UnitOfWork;
  5. require_once __DIR__ . '/../../../TestInit.php';
  6. /**
  7. * @group DDC-1514
  8. */
  9. class DDC1514Test extends \Doctrine\Tests\OrmFunctionalTestCase
  10. {
  11. protected function setUp()
  12. {
  13. parent::setUp();
  14. try {
  15. $this->_schemaTool->createSchema(array(
  16. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityA'),
  17. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityB'),
  18. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1514EntityC'),
  19. ));
  20. } catch (\Exception $ignored) {
  21. }
  22. }
  23. public function testIssue()
  24. {
  25. $a1 = new DDC1514EntityA();
  26. $a1->title = "foo";
  27. $a2 = new DDC1514EntityA();
  28. $a2->title = "bar";
  29. $b1 = new DDC1514EntityB();
  30. $b1->entityAFrom = $a1;
  31. $b1->entityATo = $a2;
  32. $b2 = new DDC1514EntityB();
  33. $b2->entityAFrom = $a2;
  34. $b2->entityATo = $a1;
  35. $c = new DDC1514EntityC();
  36. $c->title = "baz";
  37. $a2->entityC = $c;
  38. $this->_em->persist($a1);
  39. $this->_em->persist($a2);
  40. $this->_em->persist($b1);
  41. $this->_em->persist($b2);
  42. $this->_em->persist($c);
  43. $this->_em->flush();
  44. $this->_em->clear();
  45. $dql = "SELECT a, b, ba, c FROM " . __NAMESPACE__ . "\DDC1514EntityA AS a LEFT JOIN a.entitiesB AS b LEFT JOIN b.entityATo AS ba LEFT JOIN a.entityC AS c";
  46. $results = $this->_em->createQuery($dql)->getResult();
  47. $this->assertInternalType('array', $results);
  48. $this->assertTrue(count($results) >= 1, "At least one result expected in array");
  49. $this->assertEquals($c->title, $results[1]->entityC->title);
  50. }
  51. }
  52. /**
  53. * @Entity
  54. */
  55. class DDC1514EntityA
  56. {
  57. /** @Id @Column(type="integer") @GeneratedValue */
  58. public $id;
  59. /** @Column */
  60. public $title;
  61. /** @ManyToMany(targetEntity="DDC1514EntityB", mappedBy="entityAFrom") */
  62. public $entitiesB;
  63. /** @ManyToOne(targetEntity="DDC1514EntityC") */
  64. public $entityC;
  65. public function __construct()
  66. {
  67. $this->entitiesB = new ArrayCollection();
  68. }
  69. }
  70. /**
  71. * @Entity
  72. */
  73. class DDC1514EntityB
  74. {
  75. /** @Id @Column(type="integer") @GeneratedValue */
  76. public $id;
  77. /**
  78. * @ManyToOne(targetEntity="DDC1514EntityA", inversedBy="entitiesB")
  79. */
  80. public $entityAFrom;
  81. /**
  82. * @ManyToOne(targetEntity="DDC1514EntityA")
  83. */
  84. public $entityATo;
  85. }
  86. /**
  87. * @Entity
  88. */
  89. class DDC1514EntityC
  90. {
  91. /** @Id @Column(type="integer") @GeneratedValue */
  92. public $id;
  93. /** @Column */
  94. public $title;
  95. }