1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
6
|
|
|
|
7
|
|
View Code Duplication |
class Ticket4646InstanceOfParametricTest extends OrmFunctionalTestCase |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
protected function setUp() |
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() |
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
|
|
|
$this->assertCount(2, $result); |
32
|
|
|
$this->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() |
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
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.