Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Hotfix for DDC-2230 #589

Merged
merged 2 commits into from

3 participants

@Ocramius
Owner

See DDC-2230 and commit messages

Ocramius added some commits
@Ocramius Ocramius Adding failing test for DDC-2230
Proxies that implement the Doctrine\Common\PropertyChangedListener are getting eagerly
initialized because the UnitOfWork injects itself into them after they are created.
The test currently fails for what described above, and also verifies if the UoW
is correctly injected in the proxy during lazy loading.
be24439
@Ocramius Ocramius Applying fix for failing test for DDC-2230 350fa4f
@doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2230

@guilhermeblanco guilhermeblanco merged commit d5dd7d6 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 23, 2013
  1. @Ocramius

    Adding failing test for DDC-2230

    Ocramius authored
    Proxies that implement the Doctrine\Common\PropertyChangedListener are getting eagerly
    initialized because the UnitOfWork injects itself into them after they are created.
    The test currently fails for what described above, and also verifies if the UoW
    is correctly injected in the proxy during lazy loading.
  2. @Ocramius
This page is out of date. Refresh to see the latest.
View
7 lib/Doctrine/ORM/UnitOfWork.php
@@ -2659,7 +2659,10 @@ public function createEntity($className, array $data, &$hints = array())
$this->entityIdentifiers[$newValueOid] = $associatedId;
$this->identityMap[$targetClass->rootEntityName][$relatedIdHash] = $newValue;
- if ($newValue instanceof NotifyPropertyChanged) {
+ if (
+ $newValue instanceof NotifyPropertyChanged &&
+ ( ! $newValue instanceof Proxy || $newValue->__isInitialized())
+ ) {
$newValue->addPropertyChangedListener($this);
}
$this->entityStates[$newValueOid] = self::STATE_MANAGED;
@@ -3003,7 +3006,7 @@ public function registerManaged($entity, array $id, array $data)
$this->addToIdentityMap($entity);
- if ($entity instanceof NotifyPropertyChanged) {
+ if ($entity instanceof NotifyPropertyChanged && ( ! $entity instanceof Proxy || $entity->__isInitialized())) {
$entity->addPropertyChangedListener($this);
}
}
View
9 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1690Test.php
@@ -50,7 +50,14 @@ public function testChangeTracking()
$child = $this->_em->find(__NAMESPACE__.'\DDC1690Child', $childId);
$this->assertEquals(1, count($parent->listeners));
- $this->assertEquals(1, count($child->listeners));
+ $this->assertInstanceOf(
+ 'Doctrine\\ORM\\Proxy\\Proxy',
+ $child,
+ 'Verifying that $child is a proxy before using proxy API'
+ );
+ $this->assertCount(0, $child->listeners);
+ $child->__load();
+ $this->assertCount(1, $child->listeners);
unset($parent, $child);
$parent = $this->_em->find(__NAMESPACE__.'\DDC1690Parent', $parentId);
View
102 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2230Test.php
@@ -0,0 +1,102 @@
+<?php
+
+namespace Doctrine\Tests\ORM\Functional\Ticket;
+
+use Doctrine\Common\NotifyPropertyChanged;
+use Doctrine\Common\PropertyChangedListener;
+use Doctrine\ORM\Tools\ToolsException;
+use Doctrine\Tests\OrmFunctionalTestCase;
+
+/**
+ * @group DDC-2230
+ */
+class DDC2230Test extends OrmFunctionalTestCase
+{
+ protected function setup()
+ {
+ parent::setup();
+
+ try {
+ $this->_schemaTool->createSchema(array(
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2230User'),
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2230Address'),
+ ));
+ } catch (ToolsException $e) {}
+ }
+
+ public function testNotifyTrackingNotCalledOnUninitializedProxies()
+ {
+ $insertedUser = new DDC2230User();
+ $insertedUser->address = new DDC2230Address();
+
+ $this->_em->persist($insertedUser);
+ $this->_em->persist($insertedUser->address);
+ $this->_em->flush();
+ $this->_em->clear();
+
+ $user = $this->_em->find(__NAMESPACE__ . '\\DDC2230User', $insertedUser->id);
+
+ $this->_em->clear();
+
+ $mergedUser = $this->_em->merge($user);
+
+ /* @var $address \Doctrine\Common\Proxy\Proxy */
+ $address = $mergedUser->address;
+
+ $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $address);
+ $this->assertFalse($address->__isInitialized());
+ }
+
+ public function testNotifyTrackingCalledOnProxyInitialization()
+ {
+ $insertedAddress = new DDC2230Address();
+
+ $this->_em->persist($insertedAddress);
+ $this->_em->flush();
+ $this->_em->clear();
+
+ $addressProxy = $this->_em->getReference(__NAMESPACE__ . '\\DDC2230Address', $insertedAddress->id);
+
+ /* @var $addressProxy \Doctrine\Common\Proxy\Proxy|\Doctrine\Tests\ORM\Functional\Ticket\DDC2230Address */
+ $this->assertFalse($addressProxy->__isInitialized());
+ $this->assertNull($addressProxy->listener);
+
+ $addressProxy->__load();
+
+ $this->assertSame($this->_em->getUnitOfWork(), $addressProxy->listener);
+ }
+}
+
+/** @Entity */
+class DDC2230User
+{
+ /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
+ public $id;
+
+ /**
+ * @OneToOne(targetEntity="DDC2230Address")
+ */
+ public $address;
+}
+
+/**
+ * @Entity
+ * @ChangeTrackingPolicy("NOTIFY")
+ */
+class DDC2230Address implements NotifyPropertyChanged
+{
+ /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
+ public $id;
+
+ /**
+ * @var \Doctrine\Common\PropertyChangedListener
+ */
+ public $listener;
+
+ /** {@inheritDoc} */
+ function addPropertyChangedListener(PropertyChangedListener $listener)
+ {
+ $this->listener = $listener;
+ }
+}
+
Something went wrong with that request. Please try again.