|
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 Doctrine\Tests\OrmFunctionalTestCase; |
|
9
|
|
|
use ProxyManager\Proxy\GhostObjectInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Functional tests for get Id after clone child entity |
|
13
|
|
|
* |
|
14
|
|
|
* @author Lallement Thomas <[email protected]> |
|
15
|
|
|
*/ |
|
16
|
|
|
class DDC3223Test extends OrmFunctionalTestCase |
|
17
|
|
|
{ |
|
18
|
|
|
protected function setUp() |
|
19
|
|
|
{ |
|
20
|
|
|
parent::setUp(); |
|
21
|
|
|
|
|
22
|
|
|
$this->setUpEntitySchema( |
|
23
|
|
|
[ |
|
24
|
|
|
Journalist::class, |
|
25
|
|
|
Participant::class, |
|
26
|
|
|
Status::class, |
|
27
|
|
|
ProfileStatus::class, |
|
28
|
|
|
] |
|
29
|
|
|
); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testIssueGetId() |
|
33
|
|
|
{ |
|
34
|
|
|
$profileStatus = new ProfileStatus(); |
|
35
|
|
|
$participant = new Journalist(); |
|
36
|
|
|
$participant->profileStatus = $profileStatus; |
|
37
|
|
|
|
|
38
|
|
|
$this->em->persist($profileStatus); |
|
39
|
|
|
$this->em->persist($participant); |
|
40
|
|
|
$this->em->flush(); |
|
41
|
|
|
$this->em->clear(); |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
/* @var $fetchedParticipant Participant */ |
|
45
|
|
|
$fetchedParticipant = $this->em->find(Participant::class, $participant->id); |
|
46
|
|
|
|
|
47
|
|
|
/* @var $clonedProfileStatus GhostObjectInterface|ProfileStatus */ |
|
48
|
|
|
$clonedProfileStatus = clone $fetchedParticipant->profileStatus; |
|
49
|
|
|
|
|
50
|
|
|
self::assertInstanceOf(GhostObjectInterface::class, $clonedProfileStatus); |
|
51
|
|
|
self::assertInstanceOf(ProfileStatus::class, $clonedProfileStatus); |
|
52
|
|
|
self::assertTrue($clonedProfileStatus->isProxyInitialized()); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
$clonedIdentifier = $clonedProfileStatus->getId(); |
|
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
self::assertInternalType('integer', $clonedIdentifier); |
|
57
|
|
|
self::assertSame( |
|
58
|
|
|
$profileStatus->getId(), |
|
59
|
|
|
$clonedIdentifier, |
|
60
|
|
|
'The identifier on the cloned instance is an integer' |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** @ORM\Entity @ORM\Table(name="ddc3223_journalist") */ |
|
66
|
|
|
class Journalist extends Participant |
|
67
|
|
|
{ |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @ORM\Entity @ORM\Table(name="ddc3223_participant") |
|
72
|
|
|
* @ORM\InheritanceType("JOINED") |
|
73
|
|
|
* @ORM\DiscriminatorColumn(name="discr", type="string") |
|
74
|
|
|
* @ORM\DiscriminatorMap({ |
|
75
|
|
|
* "journalist" = "Journalist", |
|
76
|
|
|
* "participant" = "Participant", |
|
77
|
|
|
* }) |
|
78
|
|
|
*/ |
|
79
|
|
|
class Participant |
|
80
|
|
|
{ |
|
81
|
|
|
/** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue */ |
|
82
|
|
|
public $id; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @ORM\ManyToOne(targetEntity="ProfileStatus") |
|
86
|
|
|
* @ORM\JoinColumn(name="status_id", nullable=false) |
|
87
|
|
|
* @var ProfileStatus |
|
88
|
|
|
*/ |
|
89
|
|
|
public $profileStatus; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @ORM\Entity @ORM\Table(name="ddc3223_status") |
|
94
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
|
95
|
|
|
* @ORM\DiscriminatorColumn(name="discr", type="string") |
|
96
|
|
|
* @ORM\DiscriminatorMap({ |
|
97
|
|
|
* "profile" = "ProfileStatus", |
|
98
|
|
|
* "status" = "Status", |
|
99
|
|
|
* }) |
|
100
|
|
|
*/ |
|
101
|
|
|
class Status |
|
102
|
|
|
{ |
|
103
|
|
|
/** @ORM\Id @ORM\Column(type="integer") @ORM\GeneratedValue(strategy="AUTO") */ |
|
104
|
|
|
private $id; |
|
105
|
|
|
|
|
106
|
|
|
public function getId() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->id; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @ORM\Entity |
|
114
|
|
|
*/ |
|
115
|
|
|
class ProfileStatus extends Status |
|
116
|
|
|
{ |
|
117
|
|
|
} |
|
118
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: