2015-06-29 22:05:26 +02:00
|
|
|
<?php
|
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
class Ticket4646InstanceOfTest extends OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
protected function setUp()
|
2015-06-29 22:05:26 +02:00
|
|
|
{
|
2017-06-21 10:26:31 +02:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
$this->_schemaTool->createSchema([
|
|
|
|
$this->_em->getClassMetadata(PersonTicket4646::class),
|
|
|
|
$this->_em->getClassMetadata(EmployeeTicket4646::class),
|
|
|
|
]);
|
|
|
|
}
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
public function testInstanceOf()
|
|
|
|
{
|
|
|
|
$this->loadData();
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
$dql = 'SELECT p FROM Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646 p
|
|
|
|
WHERE p INSTANCE OF Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646';
|
|
|
|
$query = $this->_em->createQuery($dql);
|
|
|
|
$result = $query->getResult();
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
$this->assertCount(2, $result);
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
foreach ($result as $r) {
|
|
|
|
$this->assertInstanceOf(PersonTicket4646::class, $r);
|
|
|
|
if ($r instanceof EmployeeTicket4646) {
|
|
|
|
$this->assertEquals('bar', $r->getName());
|
|
|
|
} else {
|
|
|
|
$this->assertEquals('foo', $r->getName());
|
2015-06-29 22:05:26 +02:00
|
|
|
}
|
|
|
|
}
|
2017-06-21 10:26:31 +02:00
|
|
|
}
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
private function loadData()
|
|
|
|
{
|
|
|
|
$person = new PersonTicket4646();
|
|
|
|
$person->setName('foo');
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
$employee = new EmployeeTicket4646();
|
|
|
|
$employee->setName('bar');
|
|
|
|
$employee->setDepartement('qux');
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
$this->_em->persist($person);
|
|
|
|
$this->_em->persist($employee);
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
$this->_em->flush(array($person, $employee));
|
2015-06-29 22:05:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
/**
|
|
|
|
* @Entity()
|
|
|
|
* @Table(name="instance_of_test_person")
|
|
|
|
* @InheritanceType(value="JOINED")
|
|
|
|
* @DiscriminatorColumn(name="kind", type="string")
|
|
|
|
* @DiscriminatorMap(value={
|
|
|
|
* "person": "Doctrine\Tests\ORM\Functional\Ticket\PersonTicket4646",
|
|
|
|
* "employee": "Doctrine\Tests\ORM\Functional\Ticket\EmployeeTicket4646"
|
|
|
|
* })
|
|
|
|
*/
|
|
|
|
class PersonTicket4646
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id()
|
|
|
|
* @GeneratedValue()
|
|
|
|
* @Column(type="integer")
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
2015-06-29 22:05:26 +02:00
|
|
|
/**
|
2017-06-21 10:26:31 +02:00
|
|
|
* @Column(type="string")
|
2015-06-29 22:05:26 +02:00
|
|
|
*/
|
2017-06-21 10:26:31 +02:00
|
|
|
private $name;
|
|
|
|
|
|
|
|
public function getId()
|
2015-06-29 22:05:26 +02:00
|
|
|
{
|
2017-06-21 10:26:31 +02:00
|
|
|
return $this->id;
|
|
|
|
}
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->name;
|
|
|
|
}
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
public function setName($name)
|
|
|
|
{
|
|
|
|
$this->name = $name;
|
2015-06-29 22:05:26 +02:00
|
|
|
}
|
2017-06-21 10:26:31 +02:00
|
|
|
}
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
/**
|
|
|
|
* @Entity()
|
|
|
|
* @Table(name="instance_of_test_employee")
|
|
|
|
*/
|
|
|
|
class EmployeeTicket4646 extends PersonTicket4646
|
|
|
|
{
|
2015-06-29 22:05:26 +02:00
|
|
|
/**
|
2017-06-21 10:26:31 +02:00
|
|
|
* @Column(type="string")
|
2015-06-29 22:05:26 +02:00
|
|
|
*/
|
2017-06-21 10:26:31 +02:00
|
|
|
private $departement;
|
|
|
|
|
|
|
|
public function getDepartement()
|
2015-06-29 22:05:26 +02:00
|
|
|
{
|
2017-06-21 10:26:31 +02:00
|
|
|
return $this->departement;
|
|
|
|
}
|
2015-06-29 22:05:26 +02:00
|
|
|
|
2017-06-21 10:26:31 +02:00
|
|
|
public function setDepartement($departement)
|
|
|
|
{
|
|
|
|
$this->departement = $departement;
|
2015-06-29 22:05:26 +02:00
|
|
|
}
|
|
|
|
}
|