1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Tools\ToolsException; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
*/ |
9
|
|
|
class DDC6470Test extends \Doctrine\Tests\OrmFunctionalTestCase |
10
|
|
|
{ |
11
|
|
|
public function setUp() |
12
|
|
|
{ |
13
|
|
|
$this->enableSecondLevelCache(); |
14
|
|
|
parent::setUp(); |
15
|
|
|
|
16
|
|
|
try { |
17
|
|
|
$this->_schemaTool->createSchema( |
18
|
|
|
[ |
19
|
|
|
$this->_em->getClassMetadata(DDC6470User::class), |
20
|
|
|
$this->_em->getClassMetadata(DDC6470Driver::class), |
21
|
|
|
] |
22
|
|
|
); |
23
|
|
|
} catch (ToolsException $exc) { |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testIssue() |
28
|
|
|
{ |
29
|
|
|
$user1 = new DDC6470User('Foo'); |
30
|
|
|
$driver1 = new DDC6470Driver('Bar' , $user1); |
31
|
|
|
|
32
|
|
|
$this->_em->persist($user1); |
33
|
|
|
$this->_em->persist($driver1); |
34
|
|
|
$this->_em->flush(); |
35
|
|
|
$this->_em->clear(); |
36
|
|
|
|
37
|
|
|
$this->assertTrue($this->_em->getCache()->containsEntity(DDC6470User::class, ['id' => $user1->getId()])); |
38
|
|
|
$this->assertTrue($this->_em->getCache()->containsEntity(DDC6470Driver::class, ['id' => $driver1->getId()])); |
39
|
|
|
|
40
|
|
|
$queryCount = $this->getCurrentQueryCount(); |
41
|
|
|
$driver2 = $this->_em->find(DDC6470Driver::class, $driver1->getId()); |
42
|
|
|
|
43
|
|
|
$this->assertEquals($queryCount, $this->getCurrentQueryCount()); |
44
|
|
|
$this->assertInstanceOf(DDC6470Driver::class, $driver2); |
45
|
|
|
$this->assertInstanceOf(DDC6470User::class, $driver2->getUserProfile()); |
46
|
|
|
|
47
|
|
|
$driver2->setName('Franta'); |
48
|
|
|
|
49
|
|
|
$this->_em->flush(); |
50
|
|
|
$this->_em->clear(); |
51
|
|
|
|
52
|
|
|
$this->assertTrue($this->_em->getCache()->containsEntity(DDC6470User::class, ['id' => $user1->getId()])); |
53
|
|
|
$this->assertTrue($this->_em->getCache()->containsEntity(DDC6470Driver::class, ['id' => $driver1->getId()])); |
54
|
|
|
|
55
|
|
|
$queryCount = $this->getCurrentQueryCount(); |
56
|
|
|
$driver3 = $this->_em->createQueryBuilder() |
57
|
|
|
->from(DDC6470Driver::class, 'd') |
58
|
|
|
->select('d') |
59
|
|
|
->where('d.id = :id') |
60
|
|
|
->setParameter('id', $driver1->getId()) |
61
|
|
|
->getQuery() |
62
|
|
|
->getOneOrNullResult(); |
63
|
|
|
|
64
|
|
|
$this->assertEquals($queryCount, $this->getCurrentQueryCount()); |
65
|
|
|
$this->assertInstanceOf(DDC6470Driver::class, $driver3); |
66
|
|
|
$this->assertInstanceOf(DDC6470User::class, $driver3->getUserProfile()); |
67
|
|
|
$this->assertEquals('Franta', $driver3->getName()); |
68
|
|
|
$this->assertEquals('Foo', $driver3->getUserProfile()->getName()); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Entity |
74
|
|
|
* @Table(name="ddc6470_drivers") |
75
|
|
|
* @Cache("NONSTRICT_READ_WRITE") |
76
|
|
|
*/ |
77
|
|
|
class DDC6470Driver |
78
|
|
|
{ |
79
|
|
|
/** |
80
|
|
|
* @Id |
81
|
|
|
* @GeneratedValue |
82
|
|
|
* @Column(type="integer") |
83
|
|
|
*/ |
84
|
|
|
protected $id; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Column(type="string") |
88
|
|
|
* @var string |
89
|
|
|
*/ |
90
|
|
|
protected $name; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @Cache() |
94
|
|
|
* @OneToOne(targetEntity="DDC6470User") |
95
|
|
|
* @var User |
96
|
|
|
*/ |
97
|
|
|
protected $userProfile; |
98
|
|
|
|
99
|
|
|
public function __construct($name, $userProfile = null) |
100
|
|
|
{ |
101
|
|
|
$this->name = $name; |
102
|
|
|
$this->userProfile = $userProfile; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @return integer |
107
|
|
|
*/ |
108
|
|
|
public function getId() |
109
|
|
|
{ |
110
|
|
|
return $this->id; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $name |
115
|
|
|
*/ |
116
|
|
|
public function setName($name) |
117
|
|
|
{ |
118
|
|
|
$this->name = $name; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @return string |
123
|
|
|
*/ |
124
|
|
|
public function getName() |
125
|
|
|
{ |
126
|
|
|
return $this->name; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @param \Entities\User $userProfile |
131
|
|
|
*/ |
132
|
|
|
public function setUserProfile($userProfile) |
133
|
|
|
{ |
134
|
|
|
$this->userProfile = $userProfile; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return \Entities\User |
139
|
|
|
*/ |
140
|
|
|
public function getUserProfile() |
141
|
|
|
{ |
142
|
|
|
return $this->userProfile; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @Entity |
149
|
|
|
* @Table(name="ddc6470_users") |
150
|
|
|
* @Cache("NONSTRICT_READ_WRITE") |
151
|
|
|
*/ |
152
|
|
|
class DDC6470User |
153
|
|
|
{ |
154
|
|
|
/** |
155
|
|
|
* @Id |
156
|
|
|
* @GeneratedValue |
157
|
|
|
* @Column(type="integer") |
158
|
|
|
*/ |
159
|
|
|
protected $id; |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @Column(type="string") |
163
|
|
|
* @var string |
164
|
|
|
*/ |
165
|
|
|
protected $name; |
166
|
|
|
|
167
|
|
|
public function __construct($name) |
168
|
|
|
{ |
169
|
|
|
$this->name = $name; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @return integer |
174
|
|
|
*/ |
175
|
|
|
public function getId() |
176
|
|
|
{ |
177
|
|
|
return $this->id; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @param string $name |
182
|
|
|
*/ |
183
|
|
|
public function setName($name) |
184
|
|
|
{ |
185
|
|
|
$this->name = $name; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @return string |
190
|
|
|
*/ |
191
|
|
|
public function getName() |
192
|
|
|
{ |
193
|
|
|
return $this->name; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
} |
197
|
|
|
|