DDC1458Test.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Tests\Models\CMS\CmsUser;
  5. use Doctrine\Tests\Models\CMS\CmsGroup;
  6. require_once __DIR__ . '/../../../TestInit.php';
  7. class DDC1258Test extends \Doctrine\Tests\OrmFunctionalTestCase
  8. {
  9. public function setUp()
  10. {
  11. parent::setUp();
  12. $this->_schemaTool->createSchema(array(
  13. $this->_em->getClassMetadata(__NAMESPACE__ . '\TestEntity'),
  14. $this->_em->getClassMetadata(__NAMESPACE__ . '\TestAdditionalEntity')
  15. ));
  16. }
  17. public function testIssue()
  18. {
  19. $testEntity = new TestEntity();
  20. $testEntity->setValue(3);
  21. $testEntity->setAdditional(new TestAdditionalEntity());
  22. $this->_em->persist($testEntity);
  23. $this->_em->flush();
  24. $this->_em->clear();
  25. // So here the value is 3
  26. $this->assertEquals(3, $testEntity->getValue());
  27. $test = $this->_em->getRepository(__NAMESPACE__ . '\TestEntity')->find(1);
  28. // New value is set
  29. $test->setValue(5);
  30. // So here the value is 5
  31. $this->assertEquals(5, $test->getValue());
  32. // Get the additional entity
  33. $additional = $test->getAdditional();
  34. // Still 5..
  35. $this->assertEquals(5, $test->getValue());
  36. // Force the proxy to load
  37. $additional->getBool();
  38. // The value should still be 5
  39. $this->assertEquals(5, $test->getValue());
  40. }
  41. }
  42. /**
  43. * @Entity
  44. */
  45. class TestEntity
  46. {
  47. /**
  48. * @Id
  49. * @Column(type="integer")
  50. * @GeneratedValue(strategy="AUTO")
  51. */
  52. protected $id;
  53. /**
  54. * @Column(type="integer")
  55. */
  56. protected $value;
  57. /**
  58. * @OneToOne(targetEntity="TestAdditionalEntity", inversedBy="entity", orphanRemoval=true, cascade={"persist", "remove"})
  59. */
  60. protected $additional;
  61. public function getValue()
  62. {
  63. return $this->value;
  64. }
  65. public function setValue($value)
  66. {
  67. $this->value = $value;
  68. }
  69. public function getAdditional()
  70. {
  71. return $this->additional;
  72. }
  73. public function setAdditional($additional)
  74. {
  75. $this->additional = $additional;
  76. }
  77. }
  78. /**
  79. * @Entity
  80. */
  81. class TestAdditionalEntity
  82. {
  83. /**
  84. * @Id
  85. * @Column(type="integer")
  86. * @GeneratedValue(strategy="AUTO")
  87. */
  88. protected $id;
  89. /**
  90. * @OneToOne(targetEntity="TestEntity", mappedBy="additional")
  91. */
  92. protected $entity;
  93. /**
  94. * @Column(type="boolean")
  95. */
  96. protected $bool;
  97. public function __construct()
  98. {
  99. $this->bool = false;
  100. }
  101. public function getBool()
  102. {
  103. return $this->bool;
  104. }
  105. public function setBool($bool)
  106. {
  107. $this->bool = $bool;
  108. }
  109. }