diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index de3b1e0e5f2..2679c43407d 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -192,14 +192,14 @@ public function executeInserts() $paramIndex = 1; $data = $insertData[$tableName] ?? []; - foreach ((array) $id as $idName => $idVal) { + foreach ($id as $idName => $idVal) { $type = $this->columnTypes[$idName] ?? Type::STRING; $stmt->bindValue($paramIndex++, $idVal, $type); } foreach ($data as $columnName => $value) { - if (! is_array($id) || ! isset($id[$columnName])) { + if (! isset($id[$columnName])) { $stmt->bindValue($paramIndex++, $value, $this->columnTypes[$columnName]); } } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 7aa057d2901..f500bf884b2 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -3056,12 +3056,15 @@ public function setOriginalEntityProperty($oid, $property, $value) * * @param object $entity * - * @return mixed The identifier values. + * @return mixed[] The identifier values. */ public function getEntityIdentifier($entity) { - return $this->entityIdentifiers[spl_object_hash($entity)] - ?? EntityNotFoundException::noIdentifierFound(get_class($entity)); + if (! isset($this->entityIdentifiers[spl_object_hash($entity)])) { + throw EntityNotFoundException::noIdentifierFound(get_class($entity)); + } + + return $this->entityIdentifiers[spl_object_hash($entity)]; } /** diff --git a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php index 29098887e04..0853c2960de 100644 --- a/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php +++ b/tests/Doctrine/Tests/ORM/UnitOfWorkTest.php @@ -7,6 +7,7 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\Common\EventManager; +use Doctrine\ORM\EntityNotFoundException; use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\OptimisticLockException; @@ -815,6 +816,12 @@ public function testCommitThrowOptimisticLockExceptionWhenConnectionCommitReturn $this->expectException(OptimisticLockException::class); $this->_unitOfWork->commit(); } + + public function testItThrowsWhenLookingUpIdentifierForUnknownEntity(): void + { + $this->expectException(EntityNotFoundException::class); + $this->_unitOfWork->getEntityIdentifier(new stdClass()); + } } /**