|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class DDC7140Test |
|
10
|
|
|
* |
|
11
|
|
|
* @package Doctrine\Tests\ORM\Functional\Ticket |
|
12
|
|
|
* @group 7140 |
|
13
|
|
|
*/ |
|
14
|
|
|
class DDC7140Test extends OrmFunctionalTestCase |
|
15
|
|
|
{ |
|
16
|
|
|
public function testDDC7140() |
|
17
|
|
|
{ |
|
18
|
|
|
$this->createData(); |
|
19
|
|
|
|
|
20
|
|
|
/** @var DDC7140PersonUser $personUser */ |
|
21
|
|
|
$personUser = $this->_em->getRepository(DDC7140PersonUser::class)->find(1); |
|
22
|
|
|
|
|
23
|
|
|
// Uncommenting this makes both asserts pass |
|
24
|
|
|
//self::assertInstanceOf(DDC7140Account::class, $personUser->getPerson()->getAccount()); |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
$queryBuilder = $this->_em->createQueryBuilder(); |
|
27
|
|
|
|
|
28
|
|
|
$data = $queryBuilder |
|
|
|
|
|
|
29
|
|
|
->select('personUser') |
|
30
|
|
|
->addSelect('person', 'account') |
|
31
|
|
|
->from(DDC7140PersonUser::class, 'personUser') |
|
32
|
|
|
->join('personUser.person', 'person') |
|
33
|
|
|
->join('person.account', 'account') |
|
34
|
|
|
->where($queryBuilder->expr()->in('personUser.id', [1, 2])) |
|
35
|
|
|
->getQuery() |
|
36
|
|
|
->getResult(); |
|
37
|
|
|
|
|
38
|
|
|
self::assertInstanceOf(DDC7140Account::class, $personUser->getPerson()->getAccount()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
protected function setUp(): void |
|
42
|
|
|
{ |
|
43
|
|
|
parent::setUp(); |
|
44
|
|
|
|
|
45
|
|
|
$this->_schemaTool->createSchema([ |
|
46
|
|
|
$this->_em->getClassMetadata(DDC7140Account::class), |
|
47
|
|
|
$this->_em->getClassMetadata(DDC7140Person::class), |
|
48
|
|
|
$this->_em->getClassMetadata(DDC7140PersonUser::class), |
|
49
|
|
|
]); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
private function createData() |
|
53
|
|
|
{ |
|
54
|
|
|
$acc = new DDC7140Account(1); |
|
55
|
|
|
$person = new DDC7140Person($acc); |
|
56
|
|
|
$user1 = new DDC7140PersonUser(1, $person); |
|
57
|
|
|
$user2 = new DDC7140PersonUser(2, $person); |
|
58
|
|
|
$this->_em->persist($acc); |
|
59
|
|
|
$this->_em->persist($person); |
|
60
|
|
|
$this->_em->persist($user1); |
|
61
|
|
|
$this->_em->persist($user2); |
|
62
|
|
|
$this->_em->flush(); |
|
63
|
|
|
$this->_em->clear(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @Entity() |
|
69
|
|
|
* @Table(name="ddc7140_account") |
|
70
|
|
|
*/ |
|
71
|
|
|
class DDC7140Account |
|
72
|
|
|
{ |
|
73
|
|
|
/** |
|
74
|
|
|
* @Id() |
|
75
|
|
|
* @GeneratedValue(strategy="NONE") |
|
76
|
|
|
* @Column(name="id", type="integer", length=11) |
|
77
|
|
|
*/ |
|
78
|
|
|
private $id; |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* @Column(name="data", type="string", length=255) |
|
82
|
|
|
*/ |
|
83
|
|
|
private $data; |
|
84
|
|
|
|
|
85
|
|
|
public function __construct($id) |
|
86
|
|
|
{ |
|
87
|
|
|
$this->id = $id; |
|
88
|
|
|
$this->data = '3'; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function getId(): int |
|
92
|
|
|
{ |
|
93
|
|
|
return $this->id; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @Entity() |
|
99
|
|
|
* @Table(name="ddc7140_person") |
|
100
|
|
|
*/ |
|
101
|
|
|
class DDC7140Person |
|
102
|
|
|
{ |
|
103
|
|
|
/** |
|
104
|
|
|
* @Id() |
|
105
|
|
|
* @OneToOne(targetEntity=DDC7140Account::class) |
|
106
|
|
|
* @JoinColumn(name="account_id", referencedColumnName="id") |
|
107
|
|
|
*/ |
|
108
|
|
|
private $account; |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* @Column(name="data", type="string", length=255) |
|
112
|
|
|
*/ |
|
113
|
|
|
private $data; |
|
114
|
|
|
|
|
115
|
|
|
public function __construct($account) |
|
116
|
|
|
{ |
|
117
|
|
|
$this->account = $account; |
|
118
|
|
|
$this->data = '4'; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return DDC7140Account |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getAccount(): DDC7140Account |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->account; |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @Entity() |
|
132
|
|
|
* @Table(name="ddc7140_personuser") |
|
133
|
|
|
*/ |
|
134
|
|
|
class DDC7140PersonUser |
|
135
|
|
|
{ |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @Id() |
|
139
|
|
|
* @GeneratedValue(strategy="AUTO") |
|
140
|
|
|
* @Column(name="id", type="integer", length=11) |
|
141
|
|
|
*/ |
|
142
|
|
|
private $id; |
|
143
|
|
|
|
|
144
|
|
|
/** |
|
145
|
|
|
* @ManyToOne(targetEntity=DDC7140Person::class) |
|
146
|
|
|
* @JoinColumn(name="person_id", referencedColumnName="account_id") |
|
147
|
|
|
*/ |
|
148
|
|
|
private $person; |
|
149
|
|
|
|
|
150
|
|
|
public function __construct($id, $person) |
|
151
|
|
|
{ |
|
152
|
|
|
$this->id = $id; |
|
153
|
|
|
$this->person = $person; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function getId(): int |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->id; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public function getPerson(): DDC7140Person |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->person; |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.