1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Doctrine\Tests\Models\DDC3699\DDC3699RelationOne; |
4
|
|
|
use Doctrine\Tests\Models\DDC3699\DDC3699RelationMany; |
5
|
|
|
use Doctrine\Tests\Models\DDC3699\DDC3699Child; |
6
|
|
|
use Doctrine\Tests\VerifyDeprecations; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @group DDC-3699 |
10
|
|
|
*/ |
11
|
|
|
class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase |
12
|
|
|
{ |
13
|
|
|
use VerifyDeprecations; |
14
|
|
|
|
15
|
|
|
protected function setUp() |
16
|
|
|
{ |
17
|
|
|
$this->useModelSet('ddc3699'); |
18
|
|
|
|
19
|
|
|
parent::setUp(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** @after */ |
23
|
|
|
public function ensureTestGeneratedDeprecationMessages() : void |
24
|
|
|
{ |
25
|
|
|
$this->assertHasDeprecationMessages(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @group DDC-3699 |
30
|
|
|
*/ |
31
|
|
|
public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToOneUninitializedAssociations() |
32
|
|
|
{ |
33
|
|
|
$id = 1; |
34
|
|
|
|
35
|
|
|
$child = new DDC3699Child(); |
36
|
|
|
|
37
|
|
|
$child->id = $id; |
38
|
|
|
$child->childField = 'childValue'; |
39
|
|
|
$child->parentField = 'parentValue'; |
40
|
|
|
|
41
|
|
|
$relation = new DDC3699RelationOne(); |
42
|
|
|
|
43
|
|
|
$relation->id = $id; |
44
|
|
|
$relation->child = $child ; |
45
|
|
|
$child->oneRelation = $relation; |
46
|
|
|
|
47
|
|
|
$this->_em->persist($relation); |
48
|
|
|
$this->_em->persist($child); |
49
|
|
|
$this->_em->flush(); |
50
|
|
|
$this->_em->clear(); |
51
|
|
|
|
52
|
|
|
// fixtures loaded |
53
|
|
|
/* @var $unManagedChild DDC3699Child */ |
54
|
|
|
$unManagedChild = $this->_em->find(DDC3699Child::class, $id); |
55
|
|
|
|
56
|
|
|
$this->_em->detach($unManagedChild); |
|
|
|
|
57
|
|
|
|
58
|
|
|
// make it managed again |
59
|
|
|
$this->_em->find(DDC3699Child::class, $id); |
60
|
|
|
|
61
|
|
|
$unManagedChild->childField = 'modifiedChildValue'; |
62
|
|
|
$unManagedChild->parentField = 'modifiedParentValue'; |
63
|
|
|
|
64
|
|
|
/* @var $mergedChild DDC3699Child */ |
65
|
|
|
$mergedChild = $this->_em->merge($unManagedChild); |
|
|
|
|
66
|
|
|
|
67
|
|
|
$this->assertSame($mergedChild->childField, 'modifiedChildValue'); |
68
|
|
|
$this->assertSame($mergedChild->parentField, 'modifiedParentValue'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @group DDC-3699 |
73
|
|
|
*/ |
74
|
|
|
public function testMergingParentClassFieldsDoesNotStopMergingScalarFieldsForToManyUninitializedAssociations() |
75
|
|
|
{ |
76
|
|
|
$id = 2; |
77
|
|
|
|
78
|
|
|
$child = new DDC3699Child(); |
79
|
|
|
|
80
|
|
|
$child->id = $id; |
81
|
|
|
$child->childField = 'childValue'; |
82
|
|
|
$child->parentField = 'parentValue'; |
83
|
|
|
|
84
|
|
|
$relation = new DDC3699RelationMany(); |
85
|
|
|
|
86
|
|
|
$relation->id = $id; |
87
|
|
|
$relation->child = $child ; |
88
|
|
|
$child->relations[] = $relation; |
89
|
|
|
|
90
|
|
|
$this->_em->persist($relation); |
91
|
|
|
$this->_em->persist($child); |
92
|
|
|
$this->_em->flush(); |
93
|
|
|
$this->_em->clear(); |
94
|
|
|
|
95
|
|
|
/* @var $unmanagedChild DDC3699Child */ |
96
|
|
|
$unmanagedChild = $this->_em->find(DDC3699Child::class, $id); |
97
|
|
|
$this->_em->detach($unmanagedChild); |
|
|
|
|
98
|
|
|
|
99
|
|
|
// make it managed again |
100
|
|
|
$this->_em->find(DDC3699Child::class, $id); |
101
|
|
|
|
102
|
|
|
$unmanagedChild->childField = 'modifiedChildValue'; |
103
|
|
|
$unmanagedChild->parentField = 'modifiedParentValue'; |
104
|
|
|
|
105
|
|
|
/* @var $mergedChild DDC3699Child */ |
106
|
|
|
$mergedChild = $this->_em->merge($unmanagedChild); |
|
|
|
|
107
|
|
|
|
108
|
|
|
$this->assertSame($mergedChild->childField, 'modifiedChildValue'); |
109
|
|
|
$this->assertSame($mergedChild->parentField, 'modifiedParentValue'); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.