1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Proxy\Proxy; |
6
|
|
|
use Doctrine\Tests\Models\CMS\CmsGroup; |
7
|
|
|
use Doctrine\Tests\VerifyDeprecations; |
8
|
|
|
|
9
|
|
|
class DDC1734Test extends \Doctrine\Tests\OrmFunctionalTestCase |
10
|
|
|
{ |
11
|
|
|
use VerifyDeprecations; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* {@inheritDoc} |
15
|
|
|
*/ |
16
|
|
|
protected function setUp() |
17
|
|
|
{ |
18
|
|
|
$this->useModelSet('cms'); |
19
|
|
|
parent::setUp(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** @after */ |
23
|
|
|
public function ensureTestGeneratedDeprecationMessages() : void |
24
|
|
|
{ |
25
|
|
|
$this->assertHasDeprecationMessages(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* This test is DDC-1734 minus the serialization, i.e. it works |
30
|
|
|
* |
31
|
|
|
* @group DDC-1734 |
32
|
|
|
*/ |
33
|
|
|
public function testMergeWorksOnNonSerializedProxies() |
34
|
|
|
{ |
35
|
|
|
$group = new CmsGroup(); |
36
|
|
|
|
37
|
|
|
$group->setName('Foo'); |
38
|
|
|
$this->_em->persist($group); |
39
|
|
|
$this->_em->flush(); |
40
|
|
|
$this->_em->clear(); |
41
|
|
|
|
42
|
|
|
$proxy = $this->getProxy($group); |
43
|
|
|
|
44
|
|
|
$this->assertInstanceOf(Proxy::class, $proxy); |
45
|
|
|
$this->assertFalse($proxy->__isInitialized()); |
46
|
|
|
|
47
|
|
|
$this->_em->detach($proxy); |
|
|
|
|
48
|
|
|
$this->_em->clear(); |
49
|
|
|
|
50
|
|
|
$proxy = $this->_em->merge($proxy); |
|
|
|
|
51
|
|
|
|
52
|
|
|
$this->assertEquals('Foo', $proxy->getName(), 'The entity is broken'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* This test reproduces DDC-1734 which is: |
57
|
|
|
* - A non-initialized proxy is detached and serialized (the identifier of the proxy is *not* serialized) |
58
|
|
|
* - the object is deserialized and merged (to turn into an entity) |
59
|
|
|
* - the entity is broken because it has no identifier and no field defined |
60
|
|
|
* |
61
|
|
|
* @group DDC-1734 |
62
|
|
|
*/ |
63
|
|
|
public function testMergeWorksOnSerializedProxies() |
64
|
|
|
{ |
65
|
|
|
$group = new CmsGroup(); |
66
|
|
|
|
67
|
|
|
$group->setName('Foo'); |
68
|
|
|
$this->_em->persist($group); |
69
|
|
|
$this->_em->flush(); |
70
|
|
|
$this->_em->clear(); |
71
|
|
|
|
72
|
|
|
$proxy = $this->getProxy($group); |
73
|
|
|
|
74
|
|
|
$this->assertInstanceOf(Proxy::class, $proxy); |
75
|
|
|
$this->assertFalse($proxy->__isInitialized()); |
76
|
|
|
|
77
|
|
|
$this->_em->detach($proxy); |
|
|
|
|
78
|
|
|
$serializedProxy = serialize($proxy); |
79
|
|
|
$this->_em->clear(); |
80
|
|
|
|
81
|
|
|
$unserializedProxy = $this->_em->merge(unserialize($serializedProxy)); |
|
|
|
|
82
|
|
|
$this->assertEquals('Foo', $unserializedProxy->getName(), 'The entity is broken'); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param object $object |
87
|
|
|
* |
88
|
|
|
* @return \Doctrine\Common\Proxy\Proxy |
89
|
|
|
*/ |
90
|
|
|
private function getProxy($object) |
91
|
|
|
{ |
92
|
|
|
$metadataFactory = $this->_em->getMetadataFactory(); |
93
|
|
|
$className = get_class($object); |
94
|
|
|
$identifier = $metadataFactory->getMetadataFor($className)->getIdentifierValues($object); |
95
|
|
|
|
96
|
|
|
return $this->_em->getProxyFactory()->getProxy($className, $identifier); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
} |
100
|
|
|
|
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.