Skip to content

Commit b24e8d6

Browse files
Merge branch '5.3' into 5.4
* 5.3: [gha] swap the php versions we use in jobs [DoctrineBridge] fix calling get_class on non-object Update PR template [HttpClient] Fix handling error info in MockResponse
2 parents 61efc93 + c1af5af commit b24e8d6

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines 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
/**
@@ -859,6 +860,32 @@ public function testValidateUniquenessWithEmptyIterator($entity, $result)
859860
$this->assertNoViolation();
860861
}
861862

863+
public function testValueMustBeObject()
864+
{
865+
$constraint = new UniqueEntity([
866+
'message' => 'myMessage',
867+
'fields' => ['name'],
868+
'em' => self::EM_NAME,
869+
]);
870+
871+
$this->expectException(UnexpectedValueException::class);
872+
873+
$this->validator->validate('foo', $constraint);
874+
}
875+
876+
public function testValueCanBeNull()
877+
{
878+
$constraint = new UniqueEntity([
879+
'message' => 'myMessage',
880+
'fields' => ['name'],
881+
'em' => self::EM_NAME,
882+
]);
883+
884+
$this->validator->validate(null, $constraint);
885+
886+
$this->assertNoViolation();
887+
}
888+
862889
public function resultWithEmptyIterator(): array
863890
{
864891
$entity = new SingleIntIdEntity(1, 'foo');

Validator/Constraints/UniqueEntityValidator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Validator\ConstraintValidator;
1919
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
2020
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
21+
use Symfony\Component\Validator\Exception\UnexpectedValueException;
2122

2223
/**
2324
* Unique Entity Validator checks if one or a set of fields contain unique values.
@@ -63,6 +64,10 @@ public function validate($entity, Constraint $constraint)
6364
return;
6465
}
6566

67+
if (!\is_object($entity)) {
68+
throw new UnexpectedValueException($entity, 'object');
69+
}
70+
6671
if ($constraint->em) {
6772
$em = $this->registry->getManager($constraint->em);
6873

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"symfony/http-kernel": "<5",
6262
"symfony/messenger": "<4.4",
6363
"symfony/property-info": "<5",
64+
"symfony/proxy-manager-bridge": "<4.4.19",
6465
"symfony/security-bundle": "<5",
6566
"symfony/security-core": "<5.3",
6667
"symfony/validator": "<5.2"

0 commit comments

Comments
 (0)