Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Hotfix for DDC-2432 #663

Merged
merged 2 commits into from

2 participants

@Ocramius
Owner

Attempt to fix DDC-2432 ( http://www.doctrine-project.org/jira/browse/DDC-2432 )

Loading proxies with invalid identifiers will currently mark them as initialized regardless of the failure

Ocramius added some commits
@Ocramius Ocramius Adding failing test to demonstrate DDC-2432
Loading proxies with invalid identifiers will currently mark them as initialized regardless of the failure
07c2070
@Ocramius Ocramius applying required fixes for DDC-2432 22c9f6e
@beberlei beberlei merged commit fa75856 into master

1 check passed

Details default The Travis CI build passed
@Ocramius Ocramius deleted the hotfix/DDC-2432 branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 9, 2013
  1. @Ocramius

    Adding failing test to demonstrate DDC-2432

    Ocramius authored
    Loading proxies with invalid identifiers will currently mark them as initialized regardless of the failure
  2. @Ocramius
This page is out of date. Refresh to see the latest.
View
14 lib/Doctrine/ORM/Proxy/ProxyFactory.php
@@ -117,6 +117,9 @@ private function createInitializer(ClassMetadata $classMetadata, BasicEntityPers
{
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 @@ private function createInitializer(ClassMetadata $classMetadata, BasicEntityPers
$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 @@ private function createInitializer(ClassMetadata $classMetadata, BasicEntityPers
$proxy->__setInitialized(true);
if (null === $entityPersister->load($classMetadata->getIdentifierValues($proxy), $proxy)) {
+ $proxy->__setInitializer($initializer);
+ $proxy->__setCloner($cloner);
+ $proxy->__setInitialized(false);
+
throw new EntityNotFoundException();
}
};
View
55 tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php
@@ -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 @@ public function testSkipAbstractClassesOnGeneration()
$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
Something went wrong with that request. Please try again.