1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Tools\ToolsException; |
6
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
7
|
|
|
use Doctrine\Tests\VerifyDeprecations; |
8
|
|
|
|
9
|
|
|
class MergeSharedEntitiesTest extends OrmFunctionalTestCase |
10
|
|
|
{ |
11
|
|
|
use VerifyDeprecations; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* {@inheritDoc} |
15
|
|
|
*/ |
16
|
|
|
protected function setUp() |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
|
20
|
|
|
try { |
21
|
|
|
$this->_schemaTool->createSchema( |
22
|
|
|
[ |
23
|
|
|
$this->_em->getClassMetadata(MSEFile::class), |
24
|
|
|
$this->_em->getClassMetadata(MSEPicture::class), |
25
|
|
|
] |
26
|
|
|
); |
27
|
|
|
} catch (ToolsException $ignored) { |
|
|
|
|
28
|
|
|
} |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** @after */ |
32
|
|
|
public function ensureTestGeneratedDeprecationMessages() : void |
33
|
|
|
{ |
34
|
|
|
$this->assertHasDeprecationMessages(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testMergeSharedNewEntities() |
38
|
|
|
{ |
39
|
|
|
$file = new MSEFile; |
40
|
|
|
$picture = new MSEPicture; |
41
|
|
|
|
42
|
|
|
$picture->file = $file; |
43
|
|
|
$picture->otherFile = $file; |
44
|
|
|
|
45
|
|
|
$picture = $this->_em->merge($picture); |
|
|
|
|
46
|
|
|
|
47
|
|
|
$this->assertEquals($picture->file, $picture->otherFile, 'Identical entities must remain identical'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function testMergeSharedManagedEntities() |
51
|
|
|
{ |
52
|
|
|
$file = new MSEFile; |
53
|
|
|
$picture = new MSEPicture; |
54
|
|
|
|
55
|
|
|
$picture->file = $file; |
56
|
|
|
$picture->otherFile = $file; |
57
|
|
|
|
58
|
|
|
$this->_em->persist($file); |
59
|
|
|
$this->_em->persist($picture); |
60
|
|
|
$this->_em->flush(); |
61
|
|
|
$this->_em->clear(); |
62
|
|
|
|
63
|
|
|
$picture = $this->_em->merge($picture); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$this->assertEquals($picture->file, $picture->otherFile, 'Identical entities must remain identical'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testMergeSharedDetachedSerializedEntities() |
69
|
|
|
{ |
70
|
|
|
$file = new MSEFile; |
71
|
|
|
$picture = new MSEPicture; |
72
|
|
|
|
73
|
|
|
$picture->file = $file; |
74
|
|
|
$picture->otherFile = $file; |
75
|
|
|
|
76
|
|
|
$serializedPicture = serialize($picture); |
77
|
|
|
|
78
|
|
|
$this->_em->persist($file); |
79
|
|
|
$this->_em->persist($picture); |
80
|
|
|
$this->_em->flush(); |
81
|
|
|
$this->_em->clear(); |
82
|
|
|
|
83
|
|
|
$picture = $this->_em->merge(unserialize($serializedPicture)); |
|
|
|
|
84
|
|
|
|
85
|
|
|
$this->assertEquals($picture->file, $picture->otherFile, 'Identical entities must remain identical'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @group DDC-2704 |
90
|
|
|
*/ |
91
|
|
|
public function testMergeInheritedTransientPrivateProperties() |
92
|
|
|
{ |
93
|
|
|
$admin1 = new MSEAdmin(); |
94
|
|
|
$admin2 = new MSEAdmin(); |
95
|
|
|
|
96
|
|
|
$admin1->id = 123; |
97
|
|
|
$admin2->id = 123; |
98
|
|
|
|
99
|
|
|
$this->_em->persist($admin1); |
100
|
|
|
|
101
|
|
|
$admin2->setSession('zeh current session data'); |
102
|
|
|
|
103
|
|
|
$this->assertSame($admin1, $this->_em->merge($admin2)); |
|
|
|
|
104
|
|
|
$this->assertSame('zeh current session data', $admin1->getSession()); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** @Entity */ |
109
|
|
|
class MSEPicture |
110
|
|
|
{ |
111
|
|
|
/** @Column(type="integer") @Id @GeneratedValue */ |
112
|
|
|
public $id; |
113
|
|
|
|
114
|
|
|
/** @ManyToOne(targetEntity="MSEFile", cascade={"merge"}) */ |
115
|
|
|
public $file; |
116
|
|
|
|
117
|
|
|
/** @ManyToOne(targetEntity="MSEFile", cascade={"merge"}) */ |
118
|
|
|
public $otherFile; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** @Entity */ |
122
|
|
|
class MSEFile |
123
|
|
|
{ |
124
|
|
|
/** @Column(type="integer") @Id @GeneratedValue(strategy="AUTO") */ |
125
|
|
|
public $id; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** @MappedSuperclass */ |
129
|
|
|
abstract class MSEUser |
130
|
|
|
{ |
131
|
|
|
private $session; // intentionally transient property |
132
|
|
|
|
133
|
|
|
public function getSession() |
134
|
|
|
{ |
135
|
|
|
return $this->session; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function setSession($session) |
139
|
|
|
{ |
140
|
|
|
$this->session = $session; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** @Entity */ |
145
|
|
|
class MSEAdmin extends MSEUser |
146
|
|
|
{ |
147
|
|
|
/** @Column(type="integer") @Id @GeneratedValue(strategy="NONE") */ |
148
|
|
|
public $id; |
149
|
|
|
} |
150
|
|
|
|