1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
6
|
|
|
|
7
|
|
|
class Ticket4646InstanceOfParametricTest extends OrmFunctionalTestCase |
8
|
|
|
{ |
9
|
|
|
protected function setUp(): void |
10
|
|
|
{ |
11
|
|
|
parent::setUp(); |
12
|
|
|
$this->_schemaTool->createSchema([ |
13
|
|
|
$this->_em->getClassMetadata(PersonTicket4646Parametric::class), |
14
|
|
|
$this->_em->getClassMetadata(EmployeeTicket4646Parametric::class), |
15
|
|
|
]); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testInstanceOf(): void |
19
|
|
|
{ |
20
|
|
|
$this->_em->persist(new PersonTicket4646Parametric()); |
21
|
|
|
$this->_em->persist(new EmployeeTicket4646Parametric()); |
22
|
|
|
$this->_em->flush(); |
23
|
|
|
$dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Parametric p |
24
|
|
|
WHERE p INSTANCE OF :parameter'; |
25
|
|
|
$query = $this->_em->createQuery($dql); |
26
|
|
|
$query->setParameter( |
27
|
|
|
'parameter', |
28
|
|
|
$this->_em->getClassMetadata(PersonTicket4646Parametric::class) |
29
|
|
|
); |
30
|
|
|
$result = $query->getResult(); |
31
|
|
|
self::assertCount(2, $result); |
32
|
|
|
self::assertContainsOnlyInstancesOf(PersonTicket4646Parametric::class, $result); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @Entity() |
38
|
|
|
* @Table(name="instance_of_parametric_person") |
39
|
|
|
* @InheritanceType(value="JOINED") |
40
|
|
|
* @DiscriminatorColumn(name="kind", type="string") |
41
|
|
|
* @DiscriminatorMap(value={ |
42
|
|
|
* "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646Parametric", |
43
|
|
|
* "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646Parametric" |
44
|
|
|
* }) |
45
|
|
|
*/ |
46
|
|
|
class PersonTicket4646Parametric |
47
|
|
|
{ |
48
|
|
|
/** |
49
|
|
|
* @Id() |
50
|
|
|
* @GeneratedValue() |
51
|
|
|
* @Column(type="integer") |
52
|
|
|
*/ |
53
|
|
|
private $id; |
54
|
|
|
|
55
|
|
|
public function getId(): ?int |
56
|
|
|
{ |
57
|
|
|
return $this->id; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @Entity() |
63
|
|
|
* @Table(name="instance_of_parametric_employee") |
64
|
|
|
*/ |
65
|
|
|
class EmployeeTicket4646Parametric extends PersonTicket4646Parametric |
66
|
|
|
{ |
67
|
|
|
} |
68
|
|
|
|