diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index c3133de68ba..0bce6ade3b8 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -2796,25 +2796,20 @@ public function createEntity($className, array $data, &$hints = []) } $this->originalEntityData[$oid] = $data; + + if ($entity instanceof NotifyPropertyChanged) { + $entity->addPropertyChangedListener($this); + } } else { $entity = $this->newInstance($class); $oid = spl_object_id($entity); - - $this->entityIdentifiers[$oid] = $id; - $this->entityStates[$oid] = self::STATE_MANAGED; - $this->originalEntityData[$oid] = $data; - - $this->identityMap[$class->rootEntityName][$idHash] = $entity; + $this->registerManaged($entity, $id, $data); if (isset($hints[Query::HINT_READ_ONLY])) { $this->readOnlyObjects[$oid] = true; } } - if ($entity instanceof NotifyPropertyChanged) { - $entity->addPropertyChangedListener($this); - } - foreach ($data as $field => $value) { if (isset($class->fieldMappings[$field])) { $class->reflFields[$field]->setValue($entity, $value); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2785Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2785Test.php deleted file mode 100644 index bd30a1abe00..00000000000 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2785Test.php +++ /dev/null @@ -1,54 +0,0 @@ -useModelSet('cms'); - parent::setUp(); - } - - private $hashes = array(); - - public function testIssue() - { - $counter = 0; - do { - $object = $this->createObject($counter); - $counter++; - if ($counter > 1000) { - //mark as skipped ? (I never hit this on PHP 5.3 at least) - throw new \Exception('Failed to get a collision'); - } - } while ($object === false); - - print "Counter: $counter" . PHP_EOL; - $this->assertEquals(\Doctrine\ORM\UnitOfWork::STATE_NEW, $this->_em->getUnitOfWork()->getEntityState($object)); - } - - private function createObject($counter) - { - $phone = new CmsPhonenumber(); - $phone->phonenumber = 'pn-' . $counter; - $hash = spl_object_hash($phone); - - if (!array_key_exists($hash, $this->hashes)) { - $x = $this->_em->getReference(get_class($phone), $phone->phonenumber); - $this->_em->persist($phone); - $this->hashes[$hash] = true; - $this->_em->flush(); - $this->_em->remove($phone); - $this->_em->flush(); - return false; - } - - return $phone; - } -} diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php index bbb753084c3..534bb6c1c37 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH7869Test.php @@ -55,7 +55,7 @@ public function getClassMetadata($className): ClassMetadata $uow->clear(); $uow->triggerEagerLoads(); - self::assertSame(3, $em->getClassMetadataCalls); + self::assertSame(4, $em->getClassMetadataCalls); } }