1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Annotation as ORM; |
8
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
9
|
|
|
|
10
|
|
|
final class GH7458Test extends OrmFunctionalTestCase |
11
|
|
|
{ |
12
|
|
|
protected function setUp() : void |
13
|
|
|
{ |
14
|
|
|
parent::setup(); |
15
|
|
|
|
16
|
|
|
$this->setUpEntitySchema( |
17
|
|
|
[ |
18
|
|
|
GH7458Order::class, |
19
|
|
|
GH7458Item::class, |
20
|
|
|
] |
21
|
|
|
); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @group 7458 |
26
|
|
|
*/ |
27
|
|
|
public function testManagedRelations() : void |
28
|
|
|
{ |
29
|
|
|
$order = new GH7458Order(); |
30
|
|
|
$item = new GH7458Item(); |
31
|
|
|
$order->items = [$item]; |
32
|
|
|
$item->order = $order; |
33
|
|
|
$item->description = uniqid(); |
|
|
|
|
34
|
|
|
|
35
|
|
|
$this->em->persist($order); |
36
|
|
|
$this->em->persist($item); |
37
|
|
|
$this->em->flush(); |
38
|
|
|
$this->em->clear(); |
39
|
|
|
|
40
|
|
|
// Target properties for item |
41
|
|
|
$order = null; |
|
|
|
|
42
|
|
|
$description = uniqid(); |
|
|
|
|
43
|
|
|
|
44
|
|
|
// Load instance into unit of work and modify properties |
45
|
|
|
$queriedItem1 = $this->em->getUnitOfWork()->getEntityPersister(GH7458Item::class)->load(['id' => $item->id]); |
|
|
|
|
46
|
|
|
$queriedItem1->order = $order; |
|
|
|
|
47
|
|
|
$queriedItem1->description = $description; |
48
|
|
|
|
49
|
|
|
// Load instance from unit of work cache |
50
|
|
|
$queriedItem2 = $this->em->getUnitOfWork()->getEntityPersister(GH7458Item::class)->load(['id' => $item->id]); |
51
|
|
|
|
52
|
|
|
// Should retrieve cached instance without re-hydrating properties |
53
|
|
|
self::assertSame($queriedItem1, $queriedItem2); |
54
|
|
|
self::assertSame($order, $queriedItem2->order); |
55
|
|
|
self::assertSame($description, $queriedItem2->description); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @ORM\Entity |
61
|
|
|
*/ |
62
|
|
|
class GH7458Order |
63
|
|
|
{ |
64
|
|
|
/** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue */ |
65
|
|
|
public $id; |
66
|
|
|
/** @ORM\OneToMany(targetEntity=GH7458Item::class, mappedBy="order", fetch="EAGER") */ |
67
|
|
|
public $items; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @ORM\Entity |
72
|
|
|
*/ |
73
|
|
|
class GH7458Item |
74
|
|
|
{ |
75
|
|
|
/** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue */ |
76
|
|
|
public $id; |
77
|
|
|
/** @ORM\Column(type="string") */ |
78
|
|
|
public $description; |
79
|
|
|
/** @ORM\ManyToOne(targetEntity=GH7458Order::class, inversedBy="items", fetch="EAGER") */ |
80
|
|
|
public $order; |
81
|
|
|
} |
82
|
|
|
|