From 8fbcf7d5716b6bb7424e8021c6bdf363130856f9 Mon Sep 17 00:00:00 2001 From: beberlei Date: Sun, 28 Feb 2010 14:45:09 +0000 Subject: [PATCH] [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. --- lib/Doctrine/ORM/Proxy/ProxyFactory.php | 2 +- .../ORM/Functional/Ticket/DDC381Test.php | 58 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php index 3d4322dfe..9c5afba48 100644 --- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ORM/Proxy/ProxyFactory.php @@ -256,7 +256,7 @@ 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); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php new file mode 100644 index 000000000..a088ba8cf --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC381Test.php @@ -0,0 +1,58 @@ +_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