Skip to content

Commit

Permalink
fix handling of special "value" constraint option
Browse files Browse the repository at this point in the history
  • Loading branch information
xabbuh committed Jun 14, 2024
1 parent 2c36eca commit b7ae744
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Tests/Validator/Constraints/UniqueEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ public function testAttributeWithGroupsAndPaylod()
self::assertSame('some attached data', $constraint->payload);
self::assertSame(['some_group'], $constraint->groups);
}

public function testValueOptionConfiguresFields()
{
$constraint = new UniqueEntity(['value' => 'email']);

$this->assertSame('email', $constraint->fields);
}
}

#[UniqueEntity(['email'], message: 'myMessage')]
Expand Down
2 changes: 1 addition & 1 deletion Validator/Constraints/UniqueEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function __construct(
$payload = null,
array $options = [],
) {
if (\is_array($fields) && \is_string(key($fields)) && [] === array_diff(array_keys($fields), array_keys(get_class_vars(static::class)))) {
if (\is_array($fields) && \is_string(key($fields)) && [] === array_diff(array_keys($fields), array_merge(array_keys(get_class_vars(static::class)), ['value']))) {
$options = array_merge($fields, $options);
} else {
$options['fields'] = $fields;
Expand Down

0 comments on commit b7ae744

Please sign in to comment.