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