1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @group DDC-1925 |
9
|
|
|
* @group DDC-1210 |
10
|
|
|
*/ |
11
|
|
|
class DDC1925Test extends \Doctrine\Tests\OrmFunctionalTestCase |
12
|
|
|
{ |
13
|
|
|
public function testIssue() |
14
|
|
|
{ |
15
|
|
|
$this->_schemaTool->createSchema( |
16
|
|
|
[ |
17
|
|
|
$this->_em->getClassMetadata(DDC1925User::class), |
18
|
|
|
$this->_em->getClassMetadata(DDC1925Product::class), |
19
|
|
|
] |
20
|
|
|
); |
21
|
|
|
|
22
|
|
|
$user = new DDC1925User(); |
23
|
|
|
$user->setTitle("Test User"); |
24
|
|
|
|
25
|
|
|
$product = new DDC1925Product(); |
26
|
|
|
$product->setTitle("Test product"); |
27
|
|
|
|
28
|
|
|
$this->_em->persist($user); |
29
|
|
|
$this->_em->persist($product); |
30
|
|
|
$this->_em->flush(); |
31
|
|
|
|
32
|
|
|
$product->addBuyer($user); |
33
|
|
|
|
34
|
|
|
$this->_em->getUnitOfWork() |
35
|
|
|
->computeChangeSets(); |
36
|
|
|
|
37
|
|
|
$this->_em->persist($product); |
38
|
|
|
$this->_em->flush(); |
39
|
|
|
$this->_em->clear(); |
40
|
|
|
|
41
|
|
|
/** @var DDC1925Product $persistedProduct */ |
42
|
|
|
$persistedProduct = $this->_em->find(DDC1925Product::class, $product->getId()); |
43
|
|
|
|
44
|
|
|
self::assertEquals($user, $persistedProduct->getBuyers()->first()); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @Table |
50
|
|
|
* @Entity |
51
|
|
|
*/ |
52
|
|
|
class DDC1925Product |
53
|
|
|
{ |
54
|
|
|
/** |
55
|
|
|
* @var int $id |
56
|
|
|
* |
57
|
|
|
* @Column(name="id", type="integer") |
58
|
|
|
* @Id |
59
|
|
|
* @GeneratedValue(strategy="AUTO") |
60
|
|
|
*/ |
61
|
|
|
private $id; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var string $title |
65
|
|
|
* |
66
|
|
|
* @Column(name="title", type="string", length=255) |
67
|
|
|
*/ |
68
|
|
|
private $title; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @ManyToMany(targetEntity="DDC1925User") |
72
|
|
|
* @JoinTable( |
73
|
|
|
* name="user_purchases", |
74
|
|
|
* joinColumns={@JoinColumn(name="product_id", referencedColumnName="id")}, |
75
|
|
|
* inverseJoinColumns={@JoinColumn(name="user_id", referencedColumnName="id")} |
76
|
|
|
* ) |
77
|
|
|
*/ |
78
|
|
|
private $buyers; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Default constructor |
82
|
|
|
*/ |
83
|
|
|
public function __construct() |
84
|
|
|
{ |
85
|
|
|
$this->buyers = new ArrayCollection(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return int |
90
|
|
|
*/ |
91
|
|
|
public function getId() |
92
|
|
|
{ |
93
|
|
|
return $this->id; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param string $title |
98
|
|
|
*/ |
99
|
|
|
public function setTitle($title) |
100
|
|
|
{ |
101
|
|
|
$this->title = $title; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Get title |
106
|
|
|
* |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getTitle() |
110
|
|
|
{ |
111
|
|
|
return $this->title; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return ArrayCollection |
116
|
|
|
*/ |
117
|
|
|
public function getBuyers() |
118
|
|
|
{ |
119
|
|
|
return $this->buyers; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param DDC1925User $buyer |
124
|
|
|
*/ |
125
|
|
|
public function addBuyer(DDC1925User $buyer) |
126
|
|
|
{ |
127
|
|
|
$this->buyers[] = $buyer; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @Table |
133
|
|
|
* @Entity |
134
|
|
|
*/ |
135
|
|
|
class DDC1925User |
136
|
|
|
{ |
137
|
|
|
/** |
138
|
|
|
* @var int |
139
|
|
|
* |
140
|
|
|
* @Column(name="id", type="integer") |
141
|
|
|
* @Id |
142
|
|
|
* @GeneratedValue(strategy="AUTO") |
143
|
|
|
*/ |
144
|
|
|
private $id; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @var string |
148
|
|
|
* |
149
|
|
|
* @Column(name="title", type="string", length=255) |
150
|
|
|
*/ |
151
|
|
|
private $title; |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Get id |
155
|
|
|
* |
156
|
|
|
* @return int |
157
|
|
|
*/ |
158
|
|
|
public function getId() |
159
|
|
|
{ |
160
|
|
|
return $this->id; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Set title |
165
|
|
|
* |
166
|
|
|
* @param string $title |
167
|
|
|
*/ |
168
|
|
|
public function setTitle($title) |
169
|
|
|
{ |
170
|
|
|
$this->title = $title; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get title |
175
|
|
|
* |
176
|
|
|
* @return string |
177
|
|
|
*/ |
178
|
|
|
public function getTitle() |
179
|
|
|
{ |
180
|
|
|
return $this->title; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|