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