Skip to content

Commit c7cde75

Browse files
author
Zacharias Luiten
committed
#4252 Failing test for cascading refresh to lazy loaded associations
1 parent e1b851f commit c7cde75

File tree

1 file changed

+209
-0
lines changed

1 file changed

+209
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
<?php
2+
3+
namespace Doctrine\Tests\ORM\Functional\Ticket;
4+
5+
use Doctrine\Common\Collections\ArrayCollection;
6+
use Doctrine\ORM\Mapping as ORM;
7+
8+
/**
9+
* @group GH-4252
10+
*/
11+
class GH4252Test extends \Doctrine\Tests\OrmFunctionalTestCase
12+
{
13+
/**
14+
* {@inheritDoc}
15+
*/
16+
protected function setup()
17+
{
18+
parent::setup();
19+
20+
$this->_schemaTool->createSchema(array(
21+
$this->_em->getClassMetadata(__NAMESPACE__ . '\\GH4252City'),
22+
$this->_em->getClassMetadata(__NAMESPACE__ . '\\GH4252Resident'),
23+
$this->_em->getClassMetadata(__NAMESPACE__ . '\\GH4252Address'),
24+
));
25+
}
26+
27+
public function testIssue()
28+
{
29+
$city = new GH4252City([new GH4252Resident([new GH4252Address()])]);
30+
31+
$this->_em->persist($city);
32+
$this->_em->flush();
33+
$this->_em->clear();
34+
35+
/** @var GH4252City $city */
36+
$city = $this->_em->find(__NAMESPACE__ . '\\GH4252City', $city->getId());
37+
$city->setFlag(false);
38+
/** @var GH4252Resident $resident */
39+
$resident = $city->getResidents()->first();
40+
$resident->setFlag(false);
41+
/** @var GH4252Address $address */
42+
$address = $resident->getAddresses()->first();
43+
$address->setFlag(false);
44+
45+
$this->_em->refresh($city);
46+
47+
$resident = $city->getResidents()->first();
48+
$address = $resident->getAddresses()->first();
49+
50+
$this->assertTrue($city->getFlag());
51+
$this->assertTrue($resident->getFlag());
52+
$this->assertTrue($address->getFlag());
53+
}
54+
}
55+
56+
/**
57+
* @Entity
58+
*/
59+
class GH4252City
60+
{
61+
/** @Id @Column(type="integer") @GeneratedValue */
62+
private $id;
63+
64+
/**
65+
* @var bool
66+
* @Column(type="boolean")
67+
*/
68+
private $flag;
69+
70+
/**
71+
* @var GH4252Resident[]|\Doctrine\Common\Collections\Collection
72+
*
73+
* @OneToMany(targetEntity="GH4252Resident", mappedBy="city", cascade={"persist","refresh"})
74+
*/
75+
private $residents;
76+
77+
/** Constructor */
78+
public function __construct(array $residents)
79+
{
80+
$this->residents = new ArrayCollection();
81+
foreach ($residents as $resident) {
82+
$this->residents->add($resident);
83+
$resident->setCity($this);
84+
}
85+
$this->flag = true;
86+
}
87+
88+
public function getId()
89+
{
90+
return $this->id;
91+
}
92+
93+
public function getFlag()
94+
{
95+
return $this->flag;
96+
}
97+
98+
public function setFlag($flag)
99+
{
100+
$this->flag = $flag;
101+
}
102+
103+
public function getResidents()
104+
{
105+
return $this->residents;
106+
}
107+
}
108+
109+
/**
110+
* @Entity
111+
*/
112+
class GH4252Resident
113+
{
114+
/** @Id @Column(type="integer") @GeneratedValue */
115+
private $id;
116+
117+
/**
118+
* @var GH4252City
119+
* @ManyToOne(targetEntity="GH4252City", inversedBy="residents")
120+
*/
121+
private $city;
122+
123+
/**
124+
* @var bool
125+
* @Column(type="boolean")
126+
*/
127+
private $flag;
128+
129+
/**
130+
* @var GH4252Address[]|\Doctrine\Common\Collections\Collection
131+
*
132+
* @ManyToMany(targetEntity="GH4252Address", fetch="EXTRA_LAZY", cascade={"persist","refresh"})
133+
*/
134+
private $addresses;
135+
136+
/** Constructor */
137+
public function __construct(array $addresses)
138+
{
139+
$this->addresses = new ArrayCollection();
140+
foreach ($addresses as $address) {
141+
$this->addresses->add($address);
142+
}
143+
$this->flag = true;
144+
}
145+
146+
public function getId()
147+
{
148+
return $this->id;
149+
}
150+
151+
public function getCity()
152+
{
153+
return $this->city;
154+
}
155+
156+
public function setCity(GH4252City $city)
157+
{
158+
$this->city = $city;
159+
}
160+
161+
public function getFlag()
162+
{
163+
return $this->flag;
164+
}
165+
166+
public function setFlag($flag)
167+
{
168+
$this->flag = $flag;
169+
}
170+
171+
public function getAddresses()
172+
{
173+
return $this->addresses;
174+
}
175+
}
176+
177+
/** @Entity */
178+
class GH4252Address
179+
{
180+
/** @Id @Column(type="integer") @GeneratedValue */
181+
private $id;
182+
183+
/**
184+
* @var bool
185+
* @Column(type="boolean")
186+
*/
187+
private $flag;
188+
189+
/** Constructor */
190+
public function __construct()
191+
{
192+
$this->flag = true;
193+
}
194+
195+
public function getId()
196+
{
197+
return $this->id;
198+
}
199+
200+
public function getFlag()
201+
{
202+
return $this->flag;
203+
}
204+
205+
public function setFlag($flag)
206+
{
207+
$this->flag = $flag;
208+
}
209+
}

0 commit comments

Comments
 (0)