|
41 | 41 | use Symfony\Bridge\Doctrine\Tests\Fixtures\UpdateCompositeIntIdEntity;
|
42 | 42 | use Symfony\Bridge\Doctrine\Tests\Fixtures\UpdateCompositeObjectNoToStringIdEntity;
|
43 | 43 | use Symfony\Bridge\Doctrine\Tests\Fixtures\UpdateEmployeeProfile;
|
| 44 | +use Symfony\Bridge\Doctrine\Tests\Fixtures\UserUuidNameDto; |
| 45 | +use Symfony\Bridge\Doctrine\Tests\Fixtures\UserUuidNameEntity; |
44 | 46 | use Symfony\Bridge\Doctrine\Tests\TestRepositoryFactory;
|
45 | 47 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
46 | 48 | use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator;
|
| 49 | +use Symfony\Component\Uid\Uuid; |
47 | 50 | use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
|
48 | 51 | use Symfony\Component\Validator\Exception\UnexpectedValueException;
|
49 | 52 | use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
@@ -116,6 +119,7 @@ private function createSchema($em)
|
116 | 119 | $em->getClassMetadata(Employee::class),
|
117 | 120 | $em->getClassMetadata(CompositeObjectNoToStringIdEntity::class),
|
118 | 121 | $em->getClassMetadata(SingleIntIdStringWrapperNameEntity::class),
|
| 122 | + $em->getClassMetadata(UserUuidNameEntity::class), |
119 | 123 | ]);
|
120 | 124 | }
|
121 | 125 |
|
@@ -1401,4 +1405,25 @@ public function testEntityManagerNullObjectWhenDTODoctrineStyle()
|
1401 | 1405 |
|
1402 | 1406 | $this->validator->validate($dto, $constraint);
|
1403 | 1407 | }
|
| 1408 | + |
| 1409 | + public function testUuidIdentifierWithSameValueDifferentInstanceDoesNotCauseViolation() |
| 1410 | + { |
| 1411 | + $uuidString = 'ec562e21-1fc8-4e55-8de7-a42389ac75c5'; |
| 1412 | + $existingPerson = new UserUuidNameEntity(Uuid::fromString($uuidString), 'Foo Bar'); |
| 1413 | + $this->em->persist($existingPerson); |
| 1414 | + $this->em->flush(); |
| 1415 | + |
| 1416 | + $dto = new UserUuidNameDto(Uuid::fromString($uuidString), 'Foo Bar', ''); |
| 1417 | + |
| 1418 | + $constraint = new UniqueEntity( |
| 1419 | + fields: ['fullName'], |
| 1420 | + entityClass: UserUuidNameEntity::class, |
| 1421 | + identifierFieldNames: ['id'], |
| 1422 | + em: self::EM_NAME, |
| 1423 | + ); |
| 1424 | + |
| 1425 | + $this->validator->validate($dto, $constraint); |
| 1426 | + |
| 1427 | + $this->assertNoViolation(); |
| 1428 | + } |
1404 | 1429 | }
|
0 commit comments