DDC279Test.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. require_once __DIR__ . '/../../../TestInit.php';
  4. class DDC279Test extends \Doctrine\Tests\OrmFunctionalTestCase
  5. {
  6. protected function setUp()
  7. {
  8. parent::setUp();
  9. $this->_schemaTool->createSchema(array(
  10. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityXAbstract'),
  11. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityX'),
  12. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityY'),
  13. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityZ'),
  14. ));
  15. }
  16. /**
  17. * @group DDC-279
  18. */
  19. public function testDDC279()
  20. {
  21. $x = new DDC279EntityX();
  22. $y = new DDC279EntityY();
  23. $z = new DDC279EntityZ();
  24. $x->data = 'X';
  25. $y->data = 'Y';
  26. $z->data = 'Z';
  27. $x->y = $y;
  28. $y->z = $z;
  29. $this->_em->persist($x);
  30. $this->_em->persist($y);
  31. $this->_em->persist($z);
  32. $this->_em->flush();
  33. $this->_em->clear();
  34. $query = $this->_em->createQuery(
  35. 'SELECT x, y, z FROM Doctrine\Tests\ORM\Functional\Ticket\DDC279EntityX x '.
  36. 'INNER JOIN x.y y INNER JOIN y.z z WHERE x.id = ?1'
  37. )->setParameter(1, $x->id);
  38. $result = $query->getResult();
  39. $expected1 = 'Y';
  40. $expected2 = 'Z';
  41. $this->assertEquals(1, count($result));
  42. $this->assertEquals($expected1, $result[0]->y->data);
  43. $this->assertEquals($expected2, $result[0]->y->z->data);
  44. }
  45. }
  46. /**
  47. * @Entity
  48. * @InheritanceType("JOINED")
  49. * @DiscriminatorColumn(name="discr", type="string")
  50. * @DiscriminatorMap({"DDC279EntityX" = "DDC279EntityX"})
  51. */
  52. abstract class DDC279EntityXAbstract
  53. {
  54. /**
  55. * @Id
  56. * @GeneratedValue
  57. * @Column(name="id", type="integer")
  58. */
  59. public $id;
  60. /**
  61. * @column(type="string")
  62. */
  63. public $data;
  64. }
  65. /**
  66. * @Entity
  67. */
  68. class DDC279EntityX extends DDC279EntityXAbstract
  69. {
  70. /**
  71. * @OneToOne(targetEntity="DDC279EntityY")
  72. * @JoinColumn(name="y_id", referencedColumnName="id")
  73. */
  74. public $y;
  75. }
  76. /**
  77. * @Entity
  78. */
  79. class DDC279EntityY
  80. {
  81. /**
  82. * @Id @GeneratedValue
  83. * @Column(name="id", type="integer")
  84. */
  85. public $id;
  86. /**
  87. * @column(type="string")
  88. */
  89. public $data;
  90. /**
  91. * @OneToOne(targetEntity="DDC279EntityZ")
  92. * @JoinColumn(name="z_id", referencedColumnName="id")
  93. */
  94. public $z;
  95. }
  96. /**
  97. * @Entity
  98. */
  99. class DDC279EntityZ
  100. {
  101. /**
  102. * @Id @GeneratedValue
  103. * @Column(name="id", type="integer")
  104. */
  105. public $id;
  106. /**
  107. * @column(type="string")
  108. */
  109. public $data;
  110. }