forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GH10868Test.php
192 lines (164 loc) · 3.97 KB
/
GH10868Test.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Tests\OrmFunctionalTestCase;
class GH10868Test extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
$this->setUpEntitySchema([
GH10868Shop::class,
GH10868Offer::class,
GH10868Order::class,
GH10868OrderProduct::class,
]);
}
public function testReferenceAndLazyLoadProxyAreTheSame(): void
{
$shop = new GH10868Shop();
$offer = new GH10868Offer($shop, 1);
$order = new GH10868Order();
$orderProduct = new GH10868OrderProduct();
$orderProduct->order = $order;
$orderProduct->productOffer = $offer;
$order->shop = $shop;
$order->orderProducts->add($orderProduct);
$this->_em->persist($shop);
$this->_em->persist($offer);
$this->_em->persist($order);
$this->_em->persist($orderProduct);
$this->_em->flush();
$this->_em->clear();
$order->orderProducts->count();
$reference = $this->_em->getReference(GH10868Offer::class, [
'shop' => $shop->id,
'id' => $offer->id,
]);
$orderProductFromOrder = $order->orderProducts->first();
self::assertSame($reference, $orderProductFromOrder->productOffer);
}
}
/**
* @ORM\Entity
*/
class GH10868Order
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @var ?int
*/
public $id;
/**
* @ORM\ManyToOne(targetEntity="GH10868Shop")
* @ORM\JoinColumn(name="shop_id", referencedColumnName="id", nullable=false)
*
* @var GH10868Shop
*/
public $shop;
/**
* @ORM\OneToMany(targetEntity="GH10868OrderProduct", mappedBy="order")
*
* @var GH10868OrderProduct
*/
public $orderProducts;
public function __construct()
{
$this->orderProducts = new ArrayCollection();
}
}
/**
* @ORM\Entity
*/
class GH10868OrderProduct
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*
* @var int
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="GH10868Order", inversedBy="orderProducts", fetch="EXTRA_LAZY")
* @ORM\JoinColumn(name="order_id", referencedColumnName="id")
*
* @var GH10868Order
*/
public $order;
/**
* @ORM\ManyToOne(targetEntity="GH10868Shop")
* @ORM\JoinColumn(name="shop_id", referencedColumnName="id")
*
* @var GH10868Shop
*/
public $shop;
/**
* @ORM\ManyToOne(targetEntity="GH10868Offer", fetch="EXTRA_LAZY")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="productoffer_id", referencedColumnName="id"),
* @ORM\JoinColumn(name="shop_id", referencedColumnName="shop_id")
* })
*
* @var GH10868Offer
*/
public $productOffer;
}
/**
* @ORM\Entity
*/
class GH10868Offer
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
* @ORM\Column(type="bigint")
*
* @var ?int
*/
public $id;
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
* @ORM\ManyToOne(targetEntity="GH10868Shop")
* @ORM\JoinColumn(name="shop_id", referencedColumnName="id")
*
* @var GH10868Shop
*/
protected $shop;
protected $name = 'Test';
public function __construct(GH10868Shop $shop = null, int $id = null)
{
$this->shop = $shop;
$this->id = $id;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): GH10868Offer
{
$this->name = $name;
return $this;
}
}
/**
* @ORM\Entity
*/
class GH10868Shop
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*
* @var ?int
*/
public $id;
}