|
44 | 44 | use Symfony\Bridge\Doctrine\Tests\Fixtures\UpdateCompositeIntIdEntity;
|
45 | 45 | use Symfony\Bridge\Doctrine\Tests\Fixtures\UpdateCompositeObjectNoToStringIdEntity;
|
46 | 46 | use Symfony\Bridge\Doctrine\Tests\Fixtures\UpdateEmployeeProfile;
|
| 47 | +use Symfony\Bridge\Doctrine\Tests\Fixtures\UserUuidName; |
47 | 48 | use Symfony\Bridge\Doctrine\Tests\TestRepositoryFactory;
|
48 | 49 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
49 | 50 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator;
|
| 51 | +use Symfony\Component\Uid\Uuid; |
50 | 52 | use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
51 | 53 | use Symfony\Component\Validator\Exception\UnexpectedValueException;
|
52 | 54 | use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
@@ -160,6 +162,7 @@ private function createSchema($em)
|
160 | 162 | $em->getClassMetadata(Employee::class),
|
161 | 163 | $em->getClassMetadata(CompositeObjectNoToStringIdEntity::class),
|
162 | 164 | $em->getClassMetadata(SingleIntIdStringWrapperNameEntity::class),
|
| 165 | + $em->getClassMetadata(UserUuidName::class), |
163 | 166 | ]);
|
164 | 167 | }
|
165 | 168 |
|
@@ -1489,4 +1492,42 @@ public function testEntityManagerNullObjectWhenDTODoctrineStyle()
|
1489 | 1492 |
|
1490 | 1493 | $this->validator->validate($dto, $constraint);
|
1491 | 1494 | }
|
| 1495 | + |
| 1496 | + public function testIdentifierFieldNamesObject() |
| 1497 | + { |
| 1498 | + $entity1 = new UserUuidName(); |
| 1499 | + $entity1->id = Uuid::v7(); |
| 1500 | + $entity1->name = 'Foo'; |
| 1501 | + $entity2 = new UserUuidName(); |
| 1502 | + $entity2->id = Uuid::v6(); |
| 1503 | + $entity2->name = 'Foo'; |
| 1504 | + |
| 1505 | + $constraint = new UniqueEntity( |
| 1506 | + message: 'myMessage', |
| 1507 | + fields: ['name'], |
| 1508 | + entityClass: UserUuidName::class, |
| 1509 | + identifierFieldNames: ['id'], |
| 1510 | + em: self::EM_NAME, |
| 1511 | + ); |
| 1512 | + $this->validator->validate($entity1, $constraint); |
| 1513 | + |
| 1514 | + $this->assertNoViolation(); |
| 1515 | + |
| 1516 | + $this->em->persist($entity1); |
| 1517 | + $this->em->flush(); |
| 1518 | + |
| 1519 | + $this->validator->validate($entity1, $constraint); |
| 1520 | + |
| 1521 | + $this->assertNoViolation(); |
| 1522 | + |
| 1523 | + $this->validator->validate($entity2, $constraint); |
| 1524 | + |
| 1525 | + $this->buildViolation('myMessage') |
| 1526 | + ->atPath('property.path.name') |
| 1527 | + ->setParameter('{{ value }}', '"Foo"') |
| 1528 | + ->setInvalidValue('Foo') |
| 1529 | + ->setCause([$entity1]) |
| 1530 | + ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) |
| 1531 | + ->assertRaised(); |
| 1532 | + } |
1492 | 1533 | }
|
0 commit comments