DDC1383Test.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\ORM\UnitOfWork;
  4. require_once __DIR__ . '/../../../TestInit.php';
  5. /**
  6. * @group DDC-1383
  7. */
  8. class DDC1383Test extends \Doctrine\Tests\OrmFunctionalTestCase
  9. {
  10. protected function setUp()
  11. {
  12. parent::setUp();
  13. try {
  14. $this->_schemaTool->createSchema(array(
  15. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1383AbstractEntity'),
  16. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1383Entity'),
  17. ));
  18. } catch(\Exception $ignored) {}
  19. }
  20. public function testFailingCase()
  21. {
  22. $parent = new DDC1383Entity();
  23. $child = new DDC1383Entity();
  24. $child->setReference($parent);
  25. $this->_em->persist($parent);
  26. $this->_em->persist($child);
  27. $id = $child->getId();
  28. $this->_em->flush();
  29. $this->_em->clear();
  30. // Try merging the parent entity
  31. $child = $this->_em->merge($child);
  32. $parent = $child->getReference();
  33. // Parent is not instance of the abstract class
  34. self::assertTrue($parent instanceof DDC1383AbstractEntity,
  35. "Entity class is " . get_class($parent) . ', "DDC1383AbstractEntity" was expected');
  36. // Parent is NOT instance of entity
  37. self::assertTrue($parent instanceof DDC1383Entity,
  38. "Entity class is " . get_class($parent) . ', "DDC1383Entity" was expected');
  39. }
  40. }
  41. /**
  42. * @Entity
  43. * @InheritanceType("JOINED")
  44. * @DiscriminatorColumn(name="discr", type="integer")
  45. * @DiscriminatorMap({1 = "DDC1383Entity"})
  46. */
  47. abstract class DDC1383AbstractEntity
  48. {
  49. /**
  50. * @Id
  51. * @Column(type="integer")
  52. * @GeneratedValue
  53. */
  54. protected $id;
  55. public function getId()
  56. {
  57. return $this->id;
  58. }
  59. public function setId($id)
  60. {
  61. $this->id = $id;
  62. }
  63. }
  64. /**
  65. * @Entity
  66. */
  67. class DDC1383Entity extends DDC1383AbstractEntity
  68. {
  69. /**
  70. * @ManyToOne(targetEntity="DDC1383AbstractEntity")
  71. */
  72. protected $reference;
  73. public function getReference()
  74. {
  75. return $this->reference;
  76. }
  77. public function setReference(DDC1383AbstractEntity $reference)
  78. {
  79. $this->reference = $reference;
  80. }
  81. }