Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unwanted BC break from 5.x series not allowing integer input for validators #823

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Validator/ObjectExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 16 additions & 0 deletions tests/Validator/ObjectExistsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading