DDC1238Test.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Tests\Models\CMS\CmsEmployee;
  5. require_once __DIR__ . '/../../../TestInit.php';
  6. /**
  7. * @group DDC-1238
  8. */
  9. class DDC1238Test extends \Doctrine\Tests\OrmFunctionalTestCase
  10. {
  11. public function setUp()
  12. {
  13. parent::setUp();
  14. try {
  15. $this->_schemaTool->createSchema(array(
  16. $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1238User'),
  17. ));
  18. } catch(\Exception $e) {
  19. }
  20. }
  21. public function testIssue()
  22. {
  23. $user = new DDC1238User;
  24. $user->setName("test");
  25. $this->_em->persist($user);
  26. $this->_em->flush();
  27. $this->_em->clear();
  28. $userId = $user->getId();
  29. $this->_em->clear();
  30. $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId);
  31. $this->_em->clear();
  32. $userId2 = $user->getId();
  33. $this->assertEquals($userId, $userId2, "This proxy can still be initialized.");
  34. }
  35. public function testIssueProxyClear()
  36. {
  37. $user = new DDC1238User;
  38. $user->setName("test");
  39. $this->_em->persist($user);
  40. $this->_em->flush();
  41. $this->_em->clear();
  42. $userId = $user->getId();
  43. $this->_em->clear();
  44. $user = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId);
  45. $this->_em->clear();
  46. $user2 = $this->_em->getReference(__NAMESPACE__ . '\\DDC1238User', $userId);
  47. $this->assertNull($user->getId(), "Now this is null, we already have a user instance of that type");
  48. }
  49. }
  50. /**
  51. * @Entity
  52. */
  53. class DDC1238User
  54. {
  55. /** @Id @GeneratedValue @Column(type="integer") */
  56. private $id;
  57. /**
  58. * @Column
  59. * @var string
  60. */
  61. private $name;
  62. public function getId()
  63. {
  64. return $this->id;
  65. }
  66. public function getName()
  67. {
  68. return $this->name;
  69. }
  70. public function setName($name)
  71. {
  72. $this->name = $name;
  73. }
  74. }