DDC633Test.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use DateTime;
  4. require_once __DIR__ . '/../../../TestInit.php';
  5. class DDC633Test extends \Doctrine\Tests\OrmFunctionalTestCase
  6. {
  7. protected function setUp()
  8. {
  9. parent::setUp();
  10. try {
  11. $this->_schemaTool->createSchema(array(
  12. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC633Patient'),
  13. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC633Appointment'),
  14. ));
  15. } catch(\Exception $e) {
  16. }
  17. }
  18. /**
  19. * @group DDC-633
  20. * @group DDC-952
  21. * @group DDC-914
  22. */
  23. public function testOneToOneEager()
  24. {
  25. $app = new DDC633Appointment();
  26. $pat = new DDC633Patient();
  27. $app->patient = $pat;
  28. $pat->appointment = $app;
  29. $this->_em->persist($app);
  30. $this->_em->persist($pat);
  31. $this->_em->flush();
  32. $this->_em->clear();
  33. $eagerAppointment = $this->_em->find(__NAMESPACE__ . '\DDC633Appointment', $app->id);
  34. // Eager loading of one to one leads to fetch-join
  35. $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $eagerAppointment->patient);
  36. $this->assertTrue($this->_em->contains($eagerAppointment->patient));
  37. }
  38. /**
  39. * @group DDC-633
  40. * @group DDC-952
  41. */
  42. public function testDQLDeferredEagerLoad()
  43. {
  44. for ($i = 0; $i < 10; $i++) {
  45. $app = new DDC633Appointment();
  46. $pat = new DDC633Patient();
  47. $app->patient = $pat;
  48. $pat->appointment = $app;
  49. $this->_em->persist($app);
  50. $this->_em->persist($pat);
  51. }
  52. $this->_em->flush();
  53. $this->_em->clear();
  54. $appointments = $this->_em->createQuery("SELECT a FROM " . __NAMESPACE__ . "\DDC633Appointment a")->getResult();
  55. foreach ($appointments AS $eagerAppointment) {
  56. $this->assertInstanceOf('Doctrine\ORM\Proxy\Proxy', $eagerAppointment->patient);
  57. $this->assertTrue($eagerAppointment->patient->__isInitialized__, "Proxy should already be initialized due to eager loading!");
  58. }
  59. }
  60. }
  61. /**
  62. * @Entity
  63. */
  64. class DDC633Appointment
  65. {
  66. /** @Id @Column(type="integer") @GeneratedValue */
  67. public $id;
  68. /**
  69. * @OneToOne(targetEntity="DDC633Patient", inversedBy="appointment", fetch="EAGER")
  70. */
  71. public $patient;
  72. }
  73. /**
  74. * @Entity
  75. */
  76. class DDC633Patient
  77. {
  78. /** @Id @Column(type="integer") @GeneratedValue */
  79. public $id;
  80. /**
  81. * @OneToOne(targetEntity="DDC633Appointment", mappedBy="patient")
  82. */
  83. public $appointment;
  84. }