DDC1509Test.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\ORM\UnitOfWork;
  4. /**
  5. * @group DDC-1509
  6. */
  7. class DDC1509Test extends \Doctrine\Tests\OrmFunctionalTestCase
  8. {
  9. protected function setUp()
  10. {
  11. parent::setUp();
  12. try {
  13. $this->_schemaTool->createSchema(array(
  14. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509AbstractFile'),
  15. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509File'),
  16. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1509Picture'),
  17. ));
  18. } catch (\Exception $ignored) {
  19. }
  20. }
  21. public function testFailingCase()
  22. {
  23. $file = new DDC1509File;
  24. $thumbnail = new DDC1509File;
  25. $picture = new DDC1509Picture;
  26. $picture->setFile($file);
  27. $picture->setThumbnail($thumbnail);
  28. /* @var $em \Doctrine\ORM\EntityManager */
  29. $em = $this->_em;
  30. $em->persist($picture);
  31. $em->flush();
  32. $em->clear();
  33. $id = $picture->getPictureId();
  34. $pic = $em->merge($picture);
  35. /* @var $pic DDC1509Picture */
  36. $this->assertNotNull($pic->getThumbnail());
  37. $this->assertNotNull($pic->getFile());
  38. }
  39. }
  40. /**
  41. * @Entity
  42. */
  43. class DDC1509Picture
  44. {
  45. /**
  46. * @Column(type="integer")
  47. * @Id
  48. * @GeneratedValue(strategy="AUTO")
  49. */
  50. private $id;
  51. /**
  52. * @ManyToOne(targetEntity="DDC1509AbstractFile", cascade={"persist", "remove"})
  53. */
  54. private $thumbnail;
  55. /**
  56. * @ManyToOne(targetEntity="DDC1509AbstractFile", cascade={"persist", "remove"})
  57. */
  58. private $file;
  59. /**
  60. * Get pictureId
  61. */
  62. public function getPictureId()
  63. {
  64. return $this->id;
  65. }
  66. /**
  67. * Set file
  68. */
  69. public function setFile($value = null)
  70. {
  71. $this->file = $value;
  72. }
  73. /**
  74. * Get file
  75. */
  76. public function getFile()
  77. {
  78. return $this->file;
  79. }
  80. public function getThumbnail()
  81. {
  82. return $this->thumbnail;
  83. }
  84. public function setThumbnail($thumbnail)
  85. {
  86. $this->thumbnail = $thumbnail;
  87. }
  88. }
  89. /**
  90. * @Entity
  91. * @InheritanceType("SINGLE_TABLE")
  92. * @DiscriminatorColumn(name="discr", type="string")
  93. * @DiscriminatorMap({"file" = "DDC1509File"})
  94. */
  95. class DDC1509AbstractFile
  96. {
  97. /**
  98. * @Column(type="integer")
  99. * @Id
  100. * @GeneratedValue(strategy="AUTO")
  101. */
  102. public $id;
  103. /**
  104. * Get fileId
  105. */
  106. public function getFileId()
  107. {
  108. return $this->id;
  109. }
  110. }
  111. /**
  112. * @Entity
  113. */
  114. class DDC1509File extends DDC1509AbstractFile
  115. {
  116. }