Skip to content

Commit

Permalink
Merge pull request #823 from driehle/fix/validator-int-input
Browse files Browse the repository at this point in the history
Fix unwanted BC break from 5.x series not allowing integer input for validators
  • Loading branch information
driehle authored Oct 25, 2023
2 parents e0ed106 + 78fa8ea commit 53d3719
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit 53d3719

Please sign in to comment.