1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Annotation as ORM; |
8
|
|
|
use ProxyManager\Proxy\GhostObjectInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @group DDC-1238 |
12
|
|
|
*/ |
13
|
|
|
class DDC1238Test extends \Doctrine\Tests\OrmFunctionalTestCase |
14
|
|
|
{ |
15
|
|
|
public function setUp() |
16
|
|
|
{ |
17
|
|
|
parent::setUp(); |
18
|
|
|
try { |
19
|
|
|
$this->schemaTool->createSchema( |
20
|
|
|
[ |
21
|
|
|
$this->em->getClassMetadata(DDC1238User::class), |
22
|
|
|
] |
23
|
|
|
); |
24
|
|
|
} catch(\Exception $e) { |
|
|
|
|
25
|
|
|
|
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testIssue() |
30
|
|
|
{ |
31
|
|
|
$user = new DDC1238User; |
32
|
|
|
$user->setName("test"); |
33
|
|
|
|
34
|
|
|
$this->em->persist($user); |
35
|
|
|
$this->em->flush(); |
36
|
|
|
$this->em->clear(); |
37
|
|
|
|
38
|
|
|
$userId = $user->getId(); |
39
|
|
|
$this->em->clear(); |
40
|
|
|
|
41
|
|
|
$user = $this->em->getReference(DDC1238User::class, $userId); |
42
|
|
|
$this->em->clear(); |
43
|
|
|
|
44
|
|
|
$userId2 = $user->getId(); |
45
|
|
|
self::assertEquals($userId, $userId2, "This proxy can still be initialized."); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testIssueProxyClear() |
49
|
|
|
{ |
50
|
|
|
$user = new DDC1238User; |
51
|
|
|
$user->setName("test"); |
52
|
|
|
|
53
|
|
|
$this->em->persist($user); |
54
|
|
|
$this->em->flush(); |
55
|
|
|
$this->em->clear(); |
56
|
|
|
|
57
|
|
|
// force proxy load, getId() doesn't work anymore |
58
|
|
|
$user->getName(); |
|
|
|
|
59
|
|
|
$userId = $user->getId(); |
60
|
|
|
$this->em->clear(); |
61
|
|
|
|
62
|
|
|
/* @var $user DDC1238User|GhostObjectInterface */ |
63
|
|
|
$user = $this->em->getReference(DDC1238User::class, $userId); |
64
|
|
|
|
65
|
|
|
$this->em->clear(); |
66
|
|
|
|
67
|
|
|
/* @var $user2 DDC1238User|GhostObjectInterface */ |
68
|
|
|
$user2 = $this->em->getReference(DDC1238User::class, $userId); |
69
|
|
|
|
70
|
|
|
$user->initializeProxy(); |
|
|
|
|
71
|
|
|
|
72
|
|
|
self::assertInternalType( |
73
|
|
|
'integer', |
74
|
|
|
$user->getId(), |
|
|
|
|
75
|
|
|
'Even if a proxy is detached, it should still have an identifier' |
76
|
|
|
); |
77
|
|
|
|
78
|
|
|
$user2->initializeProxy(); |
79
|
|
|
|
80
|
|
|
self::assertInternalType( |
81
|
|
|
'integer', |
82
|
|
|
$user2->getId(), |
83
|
|
|
'The managed instance still has an identifier' |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @ORM\Entity |
90
|
|
|
*/ |
91
|
|
|
class DDC1238User |
92
|
|
|
{ |
93
|
|
|
/** @ORM\Id @ORM\GeneratedValue @ORM\Column(type="integer") */ |
94
|
|
|
private $id; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @ORM\Column |
98
|
|
|
* @var string |
99
|
|
|
*/ |
100
|
|
|
private $name; |
101
|
|
|
|
102
|
|
|
public function getId() |
103
|
|
|
{ |
104
|
|
|
return $this->id; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getName() |
108
|
|
|
{ |
109
|
|
|
return $this->name; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function setName($name) |
113
|
|
|
{ |
114
|
|
|
$this->name = $name; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|