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
|
|
|
$driver1 = new DDC6470Driver('Bar'); |
30
|
|
|
|
31
|
|
|
$this->_em->persist($driver1); |
32
|
|
|
$this->_em->flush(); |
33
|
|
|
$this->_em->clear(); |
34
|
|
|
|
35
|
|
|
|
36
|
|
|
$this->assertTrue($this->_em->getCache()->containsEntity(DDC6470User::class, ['id' => $driver1->getUserProfile()->getId()])); |
37
|
|
|
$queryCount = $this->getCurrentQueryCount(); |
38
|
|
|
$driver3 = $this->_em->createQueryBuilder() |
39
|
|
|
->from(DDC6470Driver::class, 'd') |
40
|
|
|
->select('d') |
41
|
|
|
->where('d.id = :id') |
42
|
|
|
->setParameter('id', $driver1->getId()) |
43
|
|
|
->setCacheable(true) |
44
|
|
|
->getQuery() |
45
|
|
|
->getOneOrNullResult(); |
46
|
|
|
$this->assertEquals($queryCount+1, $this->getCurrentQueryCount()); |
47
|
|
|
$this->assertInstanceOf(DDC6470Driver::class, $driver3); |
48
|
|
|
$this->assertInstanceOf(DDC6470User::class, $driver3->getUserProfile()); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @Entity |
54
|
|
|
* @Table(name="ddc6470_drivers") |
55
|
|
|
* @Cache("NONSTRICT_READ_WRITE") |
56
|
|
|
*/ |
57
|
|
|
class DDC6470Driver |
58
|
|
|
{ |
59
|
|
|
/** |
60
|
|
|
* @Id |
61
|
|
|
* @GeneratedValue |
62
|
|
|
* @Column(type="integer") |
63
|
|
|
*/ |
64
|
|
|
protected $id; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Column(type="string") |
68
|
|
|
* @var string |
69
|
|
|
*/ |
70
|
|
|
protected $name; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @Cache("NONSTRICT_READ_WRITE") |
74
|
|
|
* @OneToOne(targetEntity="DDC6470User", mappedBy="user", cascade={"persist"}) |
75
|
|
|
*/ |
76
|
|
|
protected $userProfile; |
77
|
|
|
|
78
|
|
|
public function __construct($name) |
79
|
|
|
{ |
80
|
|
|
$this->name = $name; |
81
|
|
|
$this->userProfile = new DDC6470User('Foo', $this); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return integer |
86
|
|
|
*/ |
87
|
|
|
public function getId() |
88
|
|
|
{ |
89
|
|
|
return $this->id; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @param string $name |
94
|
|
|
*/ |
95
|
|
|
public function setName($name) |
96
|
|
|
{ |
97
|
|
|
$this->name = $name; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @return string |
102
|
|
|
*/ |
103
|
|
|
public function getName() |
104
|
|
|
{ |
105
|
|
|
return $this->name; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param \Entities\User $userProfile |
|
|
|
|
110
|
|
|
*/ |
111
|
|
|
public function setUserProfile($userProfile) |
112
|
|
|
{ |
113
|
|
|
$this->userProfile = $userProfile; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return \Entities\User |
118
|
|
|
*/ |
119
|
|
|
public function getUserProfile() |
120
|
|
|
{ |
121
|
|
|
return $this->userProfile; |
|
|
|
|
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @Entity |
127
|
|
|
* @Table(name="ddc6470_users") |
128
|
|
|
* @Cache("NONSTRICT_READ_WRITE") |
129
|
|
|
*/ |
130
|
|
|
class DDC6470User |
131
|
|
|
{ |
132
|
|
|
/** |
133
|
|
|
* @Id |
134
|
|
|
* @GeneratedValue |
135
|
|
|
* @Column(type="integer") |
136
|
|
|
*/ |
137
|
|
|
protected $id; |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @Column(type="string") |
141
|
|
|
* @var string |
142
|
|
|
*/ |
143
|
|
|
protected $name; |
144
|
|
|
/** |
145
|
|
|
* |
146
|
|
|
* @OneToOne(targetEntity="DDC6470Driver", inversedBy="userProfile") |
147
|
|
|
* @JoinColumn(name="user_id", referencedColumnName="id", onDelete="cascade") |
148
|
|
|
* @Cache(usage="READ_ONLY") |
149
|
|
|
*/ |
150
|
|
|
protected $user; |
151
|
|
|
|
152
|
|
|
public function __construct($name, DDC6470Driver $user) |
153
|
|
|
{ |
154
|
|
|
$this->name = $name; |
155
|
|
|
$this->user = $user; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @return integer |
160
|
|
|
*/ |
161
|
|
|
public function getId() |
162
|
|
|
{ |
163
|
|
|
return $this->id; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param string $name |
168
|
|
|
*/ |
169
|
|
|
public function setName($name) |
170
|
|
|
{ |
171
|
|
|
$this->name = $name; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @return string |
176
|
|
|
*/ |
177
|
|
|
public function getName() |
178
|
|
|
{ |
179
|
|
|
return $this->name; |
180
|
|
|
} |
181
|
|
|
} |
182
|
|
|
|