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

Appearance settings

Commit 70310ca

Browse filesBrowse files
committed
[DoctrineBridge] fix calling get_class on non-object
1 parent 382cde2 commit 70310ca
Copy full SHA for 70310ca

File tree

2 files changed

+32
-0
lines changed
Filter options

2 files changed

+32
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
3838
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator;
3939
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
40+
use Symfony\Component\Validator\Exception\UnexpectedValueException;
4041
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
4142

4243
/**
@@ -821,6 +822,32 @@ public function testValidateUniquenessWithEmptyIterator($entity, $result)
821822
$this->assertNoViolation();
822823
}
823824

825+
public function testValueMustBeObject()
826+
{
827+
$constraint = new UniqueEntity([
828+
'message' => 'myMessage',
829+
'fields' => ['name'],
830+
'em' => self::EM_NAME,
831+
]);
832+
833+
$this->expectException(UnexpectedValueException::class);
834+
835+
$this->validator->validate('foo', $constraint);
836+
}
837+
838+
public function testValueCanBeNull()
839+
{
840+
$constraint = new UniqueEntity([
841+
'message' => 'myMessage',
842+
'fields' => ['name'],
843+
'em' => self::EM_NAME,
844+
]);
845+
846+
$this->validator->validate(null, $constraint);
847+
848+
$this->assertNoViolation();
849+
}
850+
824851
public function resultWithEmptyIterator(): array
825852
{
826853
$entity = new SingleIntIdEntity(1, 'foo');

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Validator\ConstraintValidator;
1717
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
1818
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
19+
use Symfony\Component\Validator\Exception\UnexpectedValueException;
1920

2021
/**
2122
* Unique Entity Validator checks if one or a set of fields contain unique values.
@@ -61,6 +62,10 @@ public function validate($entity, Constraint $constraint)
6162
return;
6263
}
6364

65+
if (!\is_object($entity)) {
66+
throw new UnexpectedValueException($entity, 'object');
67+
}
68+
6469
if ($constraint->em) {
6570
$em = $this->registry->getManager($constraint->em);
6671

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.