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