1
0
mirror of synced 2025-01-18 06:21:40 +03:00

Merge pull request #663 from doctrine/hotfix/DDC-2432

Hotfix for DDC-2432
This commit is contained in:
Benjamin Eberlei 2013-05-09 14:37:55 -07:00
commit fa75856d5f
2 changed files with 69 additions and 0 deletions

View File

@ -117,6 +117,9 @@ class ProxyFactory extends AbstractProxyFactory
{
if ($classMetadata->getReflectionClass()->hasMethod('__wakeup')) {
return function (BaseProxy $proxy) use ($entityPersister, $classMetadata) {
$initializer = $proxy->__getInitializer();
$cloner = $proxy->__getCloner();
$proxy->__setInitializer(null);
$proxy->__setCloner(null);
@ -136,12 +139,19 @@ class ProxyFactory extends AbstractProxyFactory
$proxy->__wakeup();
if (null === $entityPersister->load($classMetadata->getIdentifierValues($proxy), $proxy)) {
$proxy->__setInitializer($initializer);
$proxy->__setCloner($cloner);
$proxy->__setInitialized(false);
throw new EntityNotFoundException();
}
};
}
return function (BaseProxy $proxy) use ($entityPersister, $classMetadata) {
$initializer = $proxy->__getInitializer();
$cloner = $proxy->__getCloner();
$proxy->__setInitializer(null);
$proxy->__setCloner(null);
@ -160,6 +170,10 @@ class ProxyFactory extends AbstractProxyFactory
$proxy->__setInitialized(true);
if (null === $entityPersister->load($classMetadata->getIdentifierValues($proxy), $proxy)) {
$proxy->__setInitializer($initializer);
$proxy->__setCloner($cloner);
$proxy->__setInitialized(false);
throw new EntityNotFoundException();
}
};

View File

@ -2,6 +2,7 @@
namespace Doctrine\Tests\ORM\Proxy;
use Doctrine\ORM\EntityNotFoundException;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\Common\Proxy\ProxyGenerator;
@ -80,6 +81,60 @@ class ProxyFactoryTest extends \Doctrine\Tests\OrmTestCase
$this->assertEquals(0, $num, "No proxies generated.");
}
/**
* @group DDC-2432
*/
public function testFailedProxyLoadingDoesNotMarkTheProxyAsInitialized()
{
$persister = $this->getMock('Doctrine\ORM\Persisters\BasicEntityPersister', array('load'), array(), '', false);
$this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister);
/* @var $proxy \Doctrine\Common\Proxy\Proxy */
$proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', array('id' => 42));
$persister
->expects($this->atLeastOnce())
->method('load')
->will($this->returnValue(null));
try {
$proxy->getDescription();
$this->fail('An exception was expected to be raised');
} catch (EntityNotFoundException $exception) {
}
$this->assertFalse($proxy->__isInitialized());
$this->assertInstanceOf('Closure', $proxy->__getInitializer(), 'The initializer wasn\'t removed');
$this->assertInstanceOf('Closure', $proxy->__getCloner(), 'The cloner wasn\'t removed');
}
/**
* @group DDC-2432
*/
public function testFailedProxyCloningDoesNotMarkTheProxyAsInitialized()
{
$persister = $this->getMock('Doctrine\ORM\Persisters\BasicEntityPersister', array('load'), array(), '', false);
$this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister);
/* @var $proxy \Doctrine\Common\Proxy\Proxy */
$proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', array('id' => 42));
$persister
->expects($this->atLeastOnce())
->method('load')
->will($this->returnValue(null));
try {
$cloned = clone $proxy;
$this->fail('An exception was expected to be raised');
} catch (EntityNotFoundException $exception) {
}
$this->assertFalse($proxy->__isInitialized());
$this->assertInstanceOf('Closure', $proxy->__getInitializer(), 'The initializer wasn\'t removed');
$this->assertInstanceOf('Closure', $proxy->__getCloner(), 'The cloner wasn\'t removed');
}
}
abstract class AbstractClass