DDC-2931 - adding test that verifies that fetch-joined entities get refreshed with hints
This commit is contained in:
parent
c204e6c6a1
commit
b596bbb29f
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Query;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../../TestInit.php';
|
require_once __DIR__ . '/../../../TestInit.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,6 +44,45 @@ class DDC2931Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
|
|
||||||
$this->assertSame(2, $second->getRank());
|
$this->assertSame(2, $second->getRank());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -58,6 +99,9 @@ class DDC2931User
|
|||||||
/** @OneToOne(targetEntity="DDC2931User", mappedBy="parent") */
|
/** @OneToOne(targetEntity="DDC2931User", mappedBy="parent") */
|
||||||
public $child;
|
public $child;
|
||||||
|
|
||||||
|
/** @Column(type="integer") */
|
||||||
|
public $value = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return Rank recursively
|
* Return Rank recursively
|
||||||
* My rank is 1 + rank of my parent
|
* My rank is 1 + rank of my parent
|
||||||
|
Loading…
x
Reference in New Issue
Block a user