1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional { |
4
|
|
|
|
5
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
6
|
|
|
|
7
|
|
|
class InstanceOfAbstractTest extends OrmFunctionalTestCase |
8
|
|
|
{ |
9
|
|
|
protected function setUp() |
10
|
|
|
{ |
11
|
|
|
parent::setUp(); |
12
|
|
|
|
13
|
|
|
$this->_schemaTool->createSchema(array( |
14
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfAbstractTest\Person'), |
15
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\InstanceOfAbstractTest\Employee'), |
16
|
|
|
)); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testInstanceOf() |
20
|
|
|
{ |
21
|
|
|
$this->loadData(); |
22
|
|
|
|
23
|
|
|
$dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person p |
24
|
|
|
WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person'; |
25
|
|
|
$query = $this->_em->createQuery($dql); |
26
|
|
|
$result = $query->getResult(); |
27
|
|
|
|
28
|
|
|
$this->assertCount(1, $result); |
29
|
|
|
|
30
|
|
|
foreach ($result as $r) { |
31
|
|
|
$this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Person', $r); |
32
|
|
|
$this->assertInstanceOf('Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee', $r); |
33
|
|
|
$this->assertEquals('bar', $r->getName()); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
private function loadData() |
38
|
|
|
{ |
39
|
|
|
$employee = new InstanceOfAbstractTest\Employee(); |
40
|
|
|
$employee->setName('bar'); |
41
|
|
|
$employee->setDepartement('qux'); |
42
|
|
|
|
43
|
|
|
$this->_em->persist($employee); |
44
|
|
|
|
45
|
|
|
$this->_em->flush($employee); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
namespace Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest { |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @Entity() |
54
|
|
|
* @Table(name="instance_of_abstract_test_person") |
55
|
|
|
* @InheritanceType(value="JOINED") |
56
|
|
|
* @DiscriminatorColumn(name="kind", type="string") |
57
|
|
|
* @DiscriminatorMap(value={ |
58
|
|
|
* "employee": "Doctrine\Tests\ORM\Functional\InstanceOfAbstractTest\Employee" |
59
|
|
|
* }) |
60
|
|
|
*/ |
61
|
|
|
abstract class Person |
62
|
|
|
{ |
63
|
|
|
/** |
64
|
|
|
* @Id() |
65
|
|
|
* @GeneratedValue() |
66
|
|
|
* @Column(type="integer") |
67
|
|
|
*/ |
68
|
|
|
private $id; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @Column(type="string") |
72
|
|
|
*/ |
73
|
|
|
private $name; |
74
|
|
|
|
75
|
|
|
public function getId() |
76
|
|
|
{ |
77
|
|
|
return $this->id; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getName() |
81
|
|
|
{ |
82
|
|
|
return $this->name; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function setName($name) |
86
|
|
|
{ |
87
|
|
|
$this->name = $name; |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @Entity() |
93
|
|
|
* @Table(name="instance_of_abstract_test_employee") |
94
|
|
|
*/ |
95
|
|
|
class Employee extends Person |
96
|
|
|
{ |
97
|
|
|
/** |
98
|
|
|
* @Column(type="string") |
99
|
|
|
*/ |
100
|
|
|
private $departement; |
101
|
|
|
|
102
|
|
|
public function getDepartement() |
103
|
|
|
{ |
104
|
|
|
return $this->departement; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function setDepartement($departement) |
108
|
|
|
{ |
109
|
|
|
$this->departement = $departement; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
114
|
|
|
|