Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf7158bd

Browse files
committed
[Validator] Fix type error for non-array items when Unique::fields is set
1 parent9145a88 commitf7158bd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

‎src/Symfony/Component/Validator/Constraints/UniqueValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function validate(mixed $value, Constraint $constraint)
4343
$collectionElements = [];
4444
$normalizer =$this->getNormalizer($constraint);
4545
foreach ($valueas$element) {
46-
if ($fields && !$element=$this->reduceElementKeys($fields,$element)) {
46+
if ($fields && !(\is_array($element) &&$element=$this->reduceElementKeys($fields,$element))) {
4747
continue;
4848
}
4949

‎src/Symfony/Component/Validator/Tests/Constraints/UniqueValidatorTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,30 @@ public static function getInvalidFieldNames(): array
242242
];
243243
}
244244

245+
/**
246+
* @dataProvider getValidCollectionValues
247+
*/
248+
publicfunctiontestValidCollectionValues(array$value,array$fields)
249+
{
250+
$this->validator->validate($value,newUnique(fields:$fields));
251+
252+
$this->assertNoViolation();
253+
}
254+
255+
publicstaticfunctiongetValidCollectionValues():array
256+
{
257+
return [
258+
'unique empty item' => [
259+
[['field' =>1], ['field' =>2], []],
260+
['field'],
261+
],
262+
'unique non-array item' => [
263+
[['field' =>1], ['field' =>2],'',1,null],
264+
['field'],
265+
],
266+
];
267+
}
268+
245269
/**
246270
* @dataProvider getInvalidCollectionValues
247271
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp