Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7f90b4

Browse files
committed
[DoctrineBridge] fix calling get_class on non-object
1 parent 382cde2 commit a7f90b4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,21 @@ public function testValidateUniquenessWithEmptyIterator($entity, $result)
821821
$this->assertNoViolation();
822822
}
823823

824+
public function testValidateNonEntity()
825+
{
826+
$constraint = new UniqueEntity([
827+
'message' => 'myMessage',
828+
'fields' => ['name'],
829+
'em' => self::EM_NAME,
830+
]);
831+
832+
$this->validator->validate(null, $constraint);
833+
834+
$this->assertNoViolation();
835+
836+
$this->validator->validate('foo', $constraint);
837+
}
838+
824839
public function resultWithEmptyIterator(): array
825840
{
826841
$entity = new SingleIntIdEntity(1, 'foo');

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function validate($entity, Constraint $constraint)
5757
throw new ConstraintDefinitionException('At least one field has to be specified.');
5858
}
5959

60-
if (null === $entity) {
60+
if (!\is_object($entity)) {
6161
return;
6262
}
6363

0 commit comments

Comments
 (0)