|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
4
|
|
|
use Doctrine\ORM\Mapping\DiscriminatorColumn; |
|
5
|
|
|
use Doctrine\ORM\Mapping\DiscriminatorMap; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @group DDC-2842 |
|
9
|
|
|
*/ |
|
10
|
|
|
class DDC2842Test extends \Doctrine\Tests\OrmFunctionalTestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function setUp() |
|
13
|
|
|
{ |
|
14
|
|
|
parent::setUp(); |
|
15
|
|
|
|
|
16
|
|
|
try { |
|
17
|
|
|
$this->_schemaTool->createSchema( |
|
18
|
|
|
[ |
|
19
|
|
|
$this->_em->getClassMetadata(DC2842Root::class), |
|
20
|
|
|
$this->_em->getClassMetadata(DC2842Child1::class), |
|
21
|
|
|
$this->_em->getClassMetadata(DC2842Child2::class), |
|
22
|
|
|
$this->_em->getClassMetadata(DC2842Owner::class) |
|
23
|
|
|
] |
|
24
|
|
|
); |
|
25
|
|
|
} catch(\Exception $ignore) { |
|
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testSelectConditionSQL() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->_em->getRepository(DC2842Root::class)->find(1); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertSQLEquals( |
|
35
|
|
|
'SELECT t0.id AS id_1, t0.discr FROM ddc2842_entities t0 WHERE t0.id = ?', |
|
36
|
|
|
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql'] |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
$this->_em->getRepository(DC2842Child1::class)->find(1); |
|
40
|
|
|
|
|
41
|
|
|
$this->assertSQLEquals( |
|
42
|
|
|
"SELECT t0.id AS id_1, t0.discr FROM ddc2842_entities t0 WHERE t0.id = ? AND t0.discr IN ('1')", |
|
43
|
|
|
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql'] |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testSelectConditionCriteriaSQL() |
|
48
|
|
|
{ |
|
49
|
|
|
$relation1 = new DC2842Child1(); |
|
50
|
|
|
|
|
51
|
|
|
$this->_em->persist($relation1); |
|
52
|
|
|
|
|
53
|
|
|
$entity1 = new DC2842Owner(); |
|
54
|
|
|
|
|
55
|
|
|
$entity1->setRelation($relation1); |
|
56
|
|
|
|
|
57
|
|
|
$this->_em->persist($entity1); |
|
58
|
|
|
|
|
59
|
|
|
$this->_em->flush(); |
|
60
|
|
|
|
|
61
|
|
|
$this->_em->clear(); |
|
62
|
|
|
|
|
63
|
|
|
$entity1 = $this->_em->getRepository(DC2842Owner::class)->find($entity1->getId()); |
|
64
|
|
|
|
|
65
|
|
|
$relation1 = $entity1->getRelation(); |
|
66
|
|
|
|
|
67
|
|
|
$this->assertSQLEquals( |
|
68
|
|
|
'SELECT t0.id AS id_1, t0.discr FROM ddc2842_entities t0 WHERE t0.id = ?', |
|
69
|
|
|
$this->_sqlLoggerStack->queries[$this->_sqlLoggerStack->currentQuery]['sql'] |
|
70
|
|
|
); |
|
71
|
|
|
|
|
72
|
|
|
$this->_em->remove($entity1); |
|
73
|
|
|
$this->_em->remove($relation1); |
|
74
|
|
|
|
|
75
|
|
|
$this->_em->flush(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testSelectQuerySQL() |
|
79
|
|
|
{ |
|
80
|
|
|
$query = $this->_em->createQuery('SELECT e FROM Doctrine\Tests\ORM\Functional\Ticket\DC2842Root e'); |
|
81
|
|
|
$this->assertSQLEquals( |
|
82
|
|
|
$query->getSQL(), |
|
83
|
|
|
'SELECT d0_.id as id_0, d0_.discr as discr_1 FROM ddc2842_entities d0_' |
|
84
|
|
|
); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @Entity |
|
90
|
|
|
* @Table(name="ddc2842_entities") |
|
91
|
|
|
* @InheritanceType("SINGLE_TABLE") |
|
92
|
|
|
* @DiscriminatorColumn(name = "discr", type = "integer", strict = true) |
|
93
|
|
|
* @DiscriminatorMap({1 = "DC2842Child1", 2 = "DC2842Child2"}) |
|
94
|
|
|
*/ |
|
95
|
|
|
abstract class DC2842Root |
|
96
|
|
|
{ |
|
97
|
|
|
/** |
|
98
|
|
|
* @Id @Column(type="integer") |
|
99
|
|
|
* @GeneratedValue |
|
100
|
|
|
*/ |
|
101
|
|
|
private $id; |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return mixed |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getId() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->id; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* @Entity |
|
114
|
|
|
*/ |
|
115
|
|
|
class DC2842Child1 extends DC2842Root |
|
116
|
|
|
{ |
|
117
|
|
|
} |
|
118
|
|
|
/** |
|
119
|
|
|
* @Entity |
|
120
|
|
|
*/ |
|
121
|
|
|
class DC2842Child2 extends DC2842Root |
|
122
|
|
|
{ |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @Entity |
|
127
|
|
|
*/ |
|
128
|
|
|
class DC2842Owner |
|
129
|
|
|
{ |
|
130
|
|
|
/** |
|
131
|
|
|
* @Id @Column(type="integer") |
|
132
|
|
|
* @GeneratedValue |
|
133
|
|
|
*/ |
|
134
|
|
|
private $id; |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DC2842Root") |
|
138
|
|
|
*/ |
|
139
|
|
|
private $relation; |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return mixed |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getId() |
|
145
|
|
|
{ |
|
146
|
|
|
return $this->id; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return mixed |
|
151
|
|
|
*/ |
|
152
|
|
|
public function getRelation() |
|
153
|
|
|
{ |
|
154
|
|
|
return $this->relation; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @param mixed $relation |
|
159
|
|
|
*/ |
|
160
|
|
|
public function setRelation($relation) |
|
161
|
|
|
{ |
|
162
|
|
|
$this->relation = $relation; |
|
163
|
|
|
} |
|
164
|
|
|
} |