DDC1392Test.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\ORM\UnitOfWork;
  4. require_once __DIR__ . '/../../../TestInit.php';
  5. /**
  6. * @group DDC-1392
  7. */
  8. class DDC1392Test 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__ . '\DDC1392File'),
  16. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1392Picture'),
  17. ));
  18. } catch (\Exception $ignored) {
  19. }
  20. }
  21. public function testFailingCase()
  22. {
  23. $file = new DDC1392File;
  24. $picture = new DDC1392Picture;
  25. $picture->setFile($file);
  26. $em = $this->_em;
  27. $em->persist($picture);
  28. $em->flush();
  29. $em->clear();
  30. $fileId = $file->getFileId();
  31. $pictureId = $picture->getPictureId();
  32. $this->assertTrue($fileId > 0);
  33. $picture = $em->find(__NAMESPACE__ . '\DDC1392Picture', $pictureId);
  34. $this->assertEquals(UnitOfWork::STATE_MANAGED, $em->getUnitOfWork()->getEntityState($picture->getFile()), "Lazy Proxy should be marked MANAGED.");
  35. $file = $picture->getFile();
  36. // With this activated there will be no problem
  37. //$file->__load();
  38. $picture->setFile(null);
  39. $em->clear();
  40. $em->merge($file);
  41. $em->flush();
  42. $q = $this->_em->createQuery("SELECT COUNT(e) FROM " . __NAMESPACE__ . '\DDC1392File e');
  43. $result = $q->getSingleScalarResult();
  44. self::assertEquals(1, $result);
  45. }
  46. }
  47. /**
  48. * @Entity
  49. */
  50. class DDC1392Picture
  51. {
  52. /**
  53. * @Column(name="picture_id", type="integer")
  54. * @Id @GeneratedValue
  55. */
  56. private $pictureId;
  57. /**
  58. * @ManyToOne(targetEntity="DDC1392File", cascade={"persist", "remove"})
  59. * @JoinColumn(name="file_id", referencedColumnName="file_id")
  60. */
  61. private $file;
  62. /**
  63. * Get pictureId
  64. */
  65. public function getPictureId()
  66. {
  67. return $this->pictureId;
  68. }
  69. /**
  70. * Set file
  71. */
  72. public function setFile($value = null)
  73. {
  74. $this->file = $value;
  75. }
  76. /**
  77. * Get file
  78. */
  79. public function getFile()
  80. {
  81. return $this->file;
  82. }
  83. }
  84. /**
  85. * @Entity
  86. */
  87. class DDC1392File
  88. {
  89. /**
  90. * @Column(name="file_id", type="integer")
  91. * @Id
  92. * @GeneratedValue(strategy="AUTO")
  93. */
  94. public $fileId;
  95. /**
  96. * Get fileId
  97. */
  98. public function getFileId()
  99. {
  100. return $this->fileId;
  101. }
  102. }