Skip to content

Commit

Permalink
ignore a current object
Browse files Browse the repository at this point in the history
  • Loading branch information
fenric committed Feb 11, 2020
1 parent 0ade904 commit 1a46576
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Validator/Constraint/UniqueEntityValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public function validate($entity, Constraint $constraint)
return;
}

foreach ($result as $found) {
if ($entity === $found) {
return;
}
}

$atPath = $constraint->atPath ?? reset($constraint->fields);
$invalidValue = $criteria[$atPath] ?? reset($criteria);

Expand Down
4 changes: 4 additions & 0 deletions tests/Validator/Constraint/UniqueEntityValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ public function testValidate() : void

$manager->flush();

// update...
$violations = $validator->validate($entry);
$this->assertCount(0, $violations);

$violations = $validator->validate(new Fixture\Entity\Baz([
'bar' => 'bar.value',
'baz' => 'baz.value',
Expand Down

0 comments on commit 1a46576

Please sign in to comment.