From 41b9907f826998a2530ae7ba673857e8b84b38f5 Mon Sep 17 00:00:00 2001 From: Kev Date: Wed, 7 Feb 2024 18:27:21 +0100 Subject: [PATCH] Add rrror handling when misuse of find() with array values --- src/UnitOfWork.php | 4 +++ .../Functional/IdentifierFunctionalTest.php | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/Tests/ORM/Functional/IdentifierFunctionalTest.php diff --git a/src/UnitOfWork.php b/src/UnitOfWork.php index 00698e56c60..56d8e399df2 100644 --- a/src/UnitOfWork.php +++ b/src/UnitOfWork.php @@ -1781,6 +1781,10 @@ public function addToIdentityMap($entity) */ final public static function getIdHashByIdentifier(array $identifier): string { + if (array_filter($identifier, 'is_array')) { + throw new UnexpectedValueException('Unexpected identifier value: Expecting scalar, got array.'); + } + return implode( ' ', array_map( diff --git a/tests/Tests/ORM/Functional/IdentifierFunctionalTest.php b/tests/Tests/ORM/Functional/IdentifierFunctionalTest.php new file mode 100644 index 00000000000..ed8c9fb9ddb --- /dev/null +++ b/tests/Tests/ORM/Functional/IdentifierFunctionalTest.php @@ -0,0 +1,26 @@ +useModelSet('cms'); + + parent::setUp(); + } + + public function testIdentifierArrayValue(): void + { + $this->expectException(UnexpectedValueException::class); + $this->expectExceptionMessage('Unexpected identifier value: Expecting scalar, got array.'); + $this->_em->find(CmsUser::class, ['id' => ['array']]); + } +}