1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @group 6776 |
9
|
|
|
*/ |
10
|
|
|
class GH6776Test extends OrmFunctionalTestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* {@inheritDoc} |
14
|
|
|
*/ |
15
|
|
|
protected function setUp(): void |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
parent::setUp(); |
18
|
|
|
|
19
|
|
|
$this->setUpEntitySchema([GH6776Cost::class, GH6776Vehicle::class]); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Verifies that removing and then inserting an element in a collection using a unique constraint does not |
25
|
|
|
* make this constraint fail. |
26
|
|
|
*/ |
27
|
|
|
public function testIssue(): void |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
// create some vehicle with dimensions |
30
|
|
|
$vehicle = new GH6776Vehicle(); |
31
|
|
|
$vehicle->name = 'SuperCar'; |
32
|
|
|
|
33
|
|
|
$cost1 = new GH6776Cost(); |
34
|
|
|
$cost1->currency = 'GBP'; |
35
|
|
|
$cost1->amount = 12000000; |
36
|
|
|
$cost1->vehicle = $vehicle; |
37
|
|
|
|
38
|
|
|
$vehicle->cost = $cost1; |
39
|
|
|
|
40
|
|
|
// persist and flush vehicle and the 2 original dimensions |
41
|
|
|
$this->_em->persist($vehicle); |
|
|
|
|
42
|
|
|
$this->_em->persist($cost1); |
43
|
|
|
$this->_em->flush(); |
44
|
|
|
|
45
|
|
|
self::assertEquals($cost1, $vehicle->cost); |
46
|
|
|
|
47
|
|
|
// remove cost1 and add its clone; when flushing it should crash because of unique constraint violation |
48
|
|
|
$vehicle->cost = null; |
49
|
|
|
$this->_em->remove($cost1); |
50
|
|
|
|
51
|
|
|
self::assertEquals(null, $vehicle->cost); |
52
|
|
|
|
53
|
|
|
$cost2 = clone $cost1; |
54
|
|
|
$cost2->amount = 15000000; |
55
|
|
|
|
56
|
|
|
$this->_em->persist($cost2); |
57
|
|
|
$vehicle->cost = $cost2; |
58
|
|
|
|
59
|
|
|
$this->_em->flush(); |
60
|
|
|
|
61
|
|
|
// still the same count |
62
|
|
|
self::assertEquals($cost2, $vehicle->cost); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Entity |
68
|
|
|
*/ |
69
|
|
|
class GH6776Vehicle |
70
|
|
|
{ |
71
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */ |
72
|
|
|
public $id; |
73
|
|
|
|
74
|
|
|
/** @Column(type="string") */ |
75
|
|
|
public $name; |
76
|
|
|
|
77
|
|
|
/** @OneToOne(targetEntity="GH6776Cost", mappedBy="vehicle") */ |
78
|
|
|
public $cost; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @Entity() |
83
|
|
|
* @Table(uniqueConstraints={@UniqueConstraint(name="cost", columns={"vehicle_id"})}) |
84
|
|
|
*/ |
85
|
|
|
class GH6776Cost |
86
|
|
|
{ |
87
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */ |
88
|
|
|
public $id; |
89
|
|
|
|
90
|
|
|
/** @OneToOne(targetEntity="GH6776Vehicle", inversedBy="code") */ |
91
|
|
|
public $vehicle; |
92
|
|
|
|
93
|
|
|
/** @Column(type="string", length=3) */ |
94
|
|
|
public $currency; |
95
|
|
|
|
96
|
|
|
/** @Column(type="integer") */ |
97
|
|
|
public $amount; |
98
|
|
|
} |
99
|
|
|
|