From 2b207106a38b12849da226bced67b442f4298b93 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Sat, 9 Jul 2011 12:12:44 +0200 Subject: [PATCH] DDC-1022 - Call __wakeup() with the same semantics then ClassMetadata::newInstance() does inside UnitOfWork --- lib/Doctrine/ORM/Proxy/ProxyFactory.php | 8 ++++++++ .../Tests/Models/ECommerce/ECommerceProduct.php | 9 +++++++++ .../Tests/ORM/Functional/ReferenceProxyTest.php | 17 +++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/lib/Doctrine/ORM/Proxy/ProxyFactory.php b/lib/Doctrine/ORM/Proxy/ProxyFactory.php index 52a4791a9..90a3a8d5b 100644 --- a/lib/Doctrine/ORM/Proxy/ProxyFactory.php +++ b/lib/Doctrine/ORM/Proxy/ProxyFactory.php @@ -274,6 +274,14 @@ class extends \ implements \Doctrine\ORM\Proxy\Proxy { if (!$this->__isInitialized__ && $this->_entityPersister) { $this->__isInitialized__ = true; + + if (method_exists($this, "__wakeup")) { + // call this after __isInitialized__to avoid infinite recursion + // but before loading to emulate what ClassMetadata::newInstance() + // provides. + $this->__wakeup(); + } + if ($this->_entityPersister->load($this->_identifier, $this) === null) { throw new \Doctrine\ORM\EntityNotFoundException(); } diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php index 198e16720..d159a51da 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php @@ -56,6 +56,7 @@ class ECommerceProduct private $related; public $isCloned = false; + public $wakeUp = false; public function __construct() { @@ -166,4 +167,12 @@ class ECommerceProduct { $this->isCloned = true; } + + /** + * Testing docblock contents here + */ + public function __wakeup() + { + $this->wakeUp = true; + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php index 3b6e1f546..8ecb389af 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php @@ -130,4 +130,21 @@ class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); $this->assertEquals('Doctrine 2 Cookbook', $entity->getName()); } + + /** + * @group DDC-1022 + */ + public function testWakeupCalledOnProxy() + { + $id = $this->createProduct(); + + /* @var $entity Doctrine\Tests\Models\ECommerce\ECommerceProduct */ + $entity = $this->_em->getReference('Doctrine\Tests\Models\ECommerce\ECommerceProduct' , $id); + + $this->assertFalse($entity->wakeUp); + + $entity->setName('Doctrine 2 Cookbook'); + + $this->assertTrue($entity->wakeUp, "Loading the proxy should call __wakeup()."); + } }