2014-01-23 21:31:08 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
2014-02-01 04:05:34 +04:00
|
|
|
use Doctrine\ORM\Query;
|
|
|
|
|
2014-01-23 21:31:08 +04:00
|
|
|
require_once __DIR__ . '/../../../TestInit.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-2931
|
|
|
|
*/
|
|
|
|
class DDC2931Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2014-01-23 23:14:22 +04:00
|
|
|
|
2014-01-23 21:31:08 +04:00
|
|
|
try {
|
|
|
|
$this->_schemaTool->createSchema(array(
|
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2931User'),
|
|
|
|
));
|
2014-01-23 23:14:22 +04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
// no action needed - schema seems to be already in place
|
2014-01-23 21:31:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIssue()
|
|
|
|
{
|
2014-02-01 04:05:34 +04:00
|
|
|
$first = new DDC2931User();
|
2014-01-23 23:14:22 +04:00
|
|
|
$second = new DDC2931User();
|
2014-02-01 04:05:34 +04:00
|
|
|
$third = new DDC2931User();
|
2014-01-23 21:31:08 +04:00
|
|
|
|
2014-01-23 23:14:22 +04:00
|
|
|
$second->parent = $first;
|
|
|
|
$third->parent = $second;
|
2014-01-23 21:31:08 +04:00
|
|
|
|
2014-01-23 23:14:22 +04:00
|
|
|
$this->_em->persist($first);
|
|
|
|
$this->_em->persist($second);
|
|
|
|
$this->_em->persist($third);
|
2014-01-23 21:31:08 +04:00
|
|
|
|
2014-01-23 23:14:22 +04:00
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
$second = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC2931User', $second->id);
|
2014-01-24 05:43:14 +04:00
|
|
|
|
2014-01-23 23:14:22 +04:00
|
|
|
$this->assertSame(2, $second->getRank());
|
2014-01-23 21:31:08 +04:00
|
|
|
}
|
2014-02-01 04:05:34 +04:00
|
|
|
|
|
|
|
public function testFetchJoinedEntitiesCanBeRefreshed()
|
|
|
|
{
|
|
|
|
$first = new DDC2931User();
|
|
|
|
$second = new DDC2931User();
|
|
|
|
$third = new DDC2931User();
|
|
|
|
|
|
|
|
$second->parent = $first;
|
|
|
|
$third->parent = $second;
|
|
|
|
|
|
|
|
$first->value = 1;
|
|
|
|
$second->value = 2;
|
|
|
|
$third->value = 3;
|
|
|
|
|
|
|
|
$this->_em->persist($first);
|
|
|
|
$this->_em->persist($second);
|
|
|
|
$this->_em->persist($third);
|
|
|
|
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$first->value = 4;
|
|
|
|
$second->value = 5;
|
|
|
|
$third->value = 6;
|
|
|
|
|
|
|
|
$refreshedSecond = $this
|
|
|
|
->_em
|
|
|
|
->createQuery(
|
|
|
|
'SELECT e, p, c FROM '
|
|
|
|
. __NAMESPACE__ . '\\DDC2931User e LEFT JOIN e.parent p LEFT JOIN e.child c WHERE e = :id'
|
|
|
|
)
|
|
|
|
->setParameter('id', $second)
|
|
|
|
->setHint(Query::HINT_REFRESH, true)
|
|
|
|
->getResult();
|
|
|
|
|
|
|
|
$this->assertCount(1, $refreshedSecond);
|
|
|
|
$this->assertSame(1, $first->value);
|
|
|
|
$this->assertSame(2, $second->value);
|
|
|
|
$this->assertSame(3, $third->value);
|
|
|
|
}
|
2014-01-23 21:31:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-23 23:14:22 +04:00
|
|
|
/** @Entity */
|
2014-01-23 21:31:08 +04:00
|
|
|
class DDC2931User
|
|
|
|
{
|
|
|
|
|
2014-01-23 23:14:22 +04:00
|
|
|
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
|
|
|
|
public $id;
|
2014-01-23 21:31:08 +04:00
|
|
|
|
2014-01-23 23:14:22 +04:00
|
|
|
/** @OneToOne(targetEntity="DDC2931User", inversedBy="child") */
|
|
|
|
public $parent;
|
2014-01-23 21:31:08 +04:00
|
|
|
|
2014-01-23 23:14:22 +04:00
|
|
|
/** @OneToOne(targetEntity="DDC2931User", mappedBy="parent") */
|
|
|
|
public $child;
|
2014-01-23 21:31:08 +04:00
|
|
|
|
2014-02-01 04:05:34 +04:00
|
|
|
/** @Column(type="integer") */
|
|
|
|
public $value = 0;
|
|
|
|
|
2014-01-23 23:14:22 +04:00
|
|
|
/**
|
|
|
|
* Return Rank recursively
|
|
|
|
* My rank is 1 + rank of my parent
|
|
|
|
* @return integer
|
|
|
|
*/
|
|
|
|
public function getRank()
|
|
|
|
{
|
|
|
|
return 1 + ($this->parent ? $this->parent->getRank() : 0);
|
|
|
|
}
|
2014-01-24 05:43:14 +04:00
|
|
|
|
|
|
|
public function __wakeup()
|
|
|
|
{
|
|
|
|
}
|
2014-01-23 21:31:08 +04:00
|
|
|
}
|