2011-11-18 13:28:56 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-1436
|
|
|
|
*/
|
|
|
|
class DDC1436Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
try {
|
2016-12-07 23:33:41 +01:00
|
|
|
$this->_schemaTool->createSchema(
|
|
|
|
[
|
2016-12-08 18:01:04 +01:00
|
|
|
$this->_em->getClassMetadata(DDC1436Page::class),
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2011-11-18 13:28:56 +01:00
|
|
|
} catch (\Exception $ignored) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIdentityMap()
|
|
|
|
{
|
|
|
|
// fixtures
|
|
|
|
$parent = null;
|
|
|
|
for ($i = 0; $i < 3; $i++) {
|
|
|
|
$page = new DDC1436Page();
|
|
|
|
$page->setParent($parent);
|
|
|
|
$this->_em->persist($page);
|
|
|
|
$parent = $page;
|
|
|
|
}
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
$id = $parent->getId();
|
|
|
|
|
|
|
|
// step 1
|
|
|
|
$page = $this->_em
|
|
|
|
->createQuery('SELECT p, parent FROM ' . __NAMESPACE__ . '\DDC1436Page p LEFT JOIN p.parent parent WHERE p.id = :id')
|
|
|
|
->setParameter('id', $id)
|
|
|
|
->getOneOrNullResult();
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$this->assertInstanceOf(DDC1436Page::class, $page);
|
2011-11-18 13:28:56 +01:00
|
|
|
|
|
|
|
// step 2
|
2016-12-08 18:01:04 +01:00
|
|
|
$page = $this->_em->find(DDC1436Page::class, $id);
|
|
|
|
$this->assertInstanceOf(DDC1436Page::class, $page);
|
|
|
|
$this->assertInstanceOf(DDC1436Page::class, $page->getParent());
|
|
|
|
$this->assertInstanceOf(DDC1436Page::class, $page->getParent()->getParent());
|
2011-11-18 13:28:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class DDC1436Page
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id
|
|
|
|
* @GeneratedValue
|
|
|
|
* @Column(type="integer", name="id")
|
|
|
|
*/
|
|
|
|
protected $id;
|
|
|
|
/**
|
|
|
|
* @ManyToOne(targetEntity="DDC1436Page")
|
|
|
|
* @JoinColumn(name="pid", referencedColumnName="id")
|
|
|
|
*/
|
|
|
|
protected $parent;
|
|
|
|
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return DDC1436Page
|
|
|
|
*/
|
|
|
|
public function getParent()
|
|
|
|
{
|
|
|
|
return $this->parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setParent($parent)
|
|
|
|
{
|
|
|
|
$this->parent = $parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|