diff --git a/src/Validator/ObjectExists.php b/src/Validator/ObjectExists.php index e8475338..61044cdd 100644 --- a/src/Validator/ObjectExists.php +++ b/src/Validator/ObjectExists.php @@ -118,14 +118,14 @@ private function validateFields(): array } /** - * @param string|object|mixed[] $value a field value or an array of field values if more fields have been configured to be + * @param string|int|object|mixed[] $value a field value or an array of field values if more fields have been configured to be * matched * * @return mixed[] * * @throws Exception\RuntimeException */ - protected function cleanSearchValue(string|object|array $value): array + protected function cleanSearchValue(string|int|object|array $value): array { $value = is_object($value) ? [$value] : (array) $value; diff --git a/tests/Validator/ObjectExistsTest.php b/tests/Validator/ObjectExistsTest.php index 8cbe1a70..c19ca9c1 100644 --- a/tests/Validator/ObjectExistsTest.php +++ b/tests/Validator/ObjectExistsTest.php @@ -36,6 +36,22 @@ public function testCanValidateWithSingleField(): void $this->assertTrue($validator->isValid(['matchKey' => 'matchValue'])); } + public function testCanValidateWithIntegerId(): void + { + $repository = $this->createMock(ObjectRepository::class); + + $repository + ->expects($this->exactly(2)) + ->method('findOneBy') + ->with(['matchKey' => 123]) + ->will($this->returnValue(new stdClass())); + + $validator = new ObjectExists(['object_repository' => $repository, 'fields' => 'matchKey']); + + $this->assertTrue($validator->isValid(123)); + $this->assertTrue($validator->isValid(['matchKey' => 123])); + } + public function testCanValidateWithMultipleFields(): void { $repository = $this->createMock(ObjectRepository::class);