Commit 8fbcf7d5 authored by beberlei's avatar beberlei

[2.0] DDC-381 - Unserialized Entity that was a proxy during serialize() will...

[2.0] DDC-381 - Unserialized Entity that was a proxy during serialize() will fatal when accessing methods that call _load() - A check for the existance of entity persister solves the problem.
parent a0fc0985
......@@ -256,7 +256,7 @@ namespace <namespace> {
$this->_identifier = $identifier;
}
private function _load() {
if (!$this->__isInitialized__) {
if (!$this->__isInitialized__ && $this->_entityPersister) {
$this->__isInitialized__ = true;
$this->_entityPersister->load($this->_identifier, $this);
unset($this->_entityPersister);
......
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\ORM\UnitOfWork;
require_once __DIR__ . '/../../../TestInit.php';
class DDC381Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
try {
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC381Entity'),
));
} catch(\Exception $e) {
}
}
public function testCallUnserializedProxyMethods()
{
$entity = new DDC381Entity();
$this->_em->persist($entity);
$this->_em->flush();
$this->_em->clear();
$persistedId = $entity->getId();
$entity = $this->_em->getReference('Doctrine\Tests\ORM\Functional\Ticket\DDC381Entity', $persistedId);
// explicitly load proxy
$id = $entity->getId();
$data = serialize($entity);
$entity = unserialize($data);
$this->assertEquals($persistedId, $entity->getId());
}
}
/**
* @Entity
*/
class DDC381Entity
{
/**
* @Id @Column(type="integer") @generatedValue
*/
protected $id;
public function getId()
{
return $this->id;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment