Skip to content

Commit de29182

Browse files
committed
Merge branch '7.2' into 7.3
* 7.2: Use Composer InstalledVersions to check if flex is installed instead of existence of InstallRecipesCommand Improve readability of disallow_search_engine_index condition [DoctrineBridge] Fix UniqueEntityValidator Stringable identifiers [DoctrineBridge] Fix UniqueEntity for non-integer identifiers [Security] Avoid failing when PersistentRememberMeHandler handles a malformed cookie [PropertyAccess] Improve PropertyAccessor::setValue param docs fix asking for the retry option although --force was used [DoctrineBridge] Undefined variable
2 parents af88566 + 912975c commit de29182

File tree

5 files changed

+85
-1
lines changed

5 files changed

+85
-1
lines changed

Tests/Fixtures/UserUuidNameDto.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Symfony\Component\Uid\Uuid;
15+
16+
class UserUuidNameDto
17+
{
18+
public function __construct(
19+
public ?Uuid $id,
20+
public ?string $fullName,
21+
public ?string $address,
22+
) {
23+
}
24+
}

Tests/Fixtures/UserUuidNameEntity.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Entity;
16+
use Doctrine\ORM\Mapping\Id;
17+
use Symfony\Component\Uid\Uuid;
18+
19+
#[Entity]
20+
class UserUuidNameEntity
21+
{
22+
public function __construct(
23+
#[Id, Column]
24+
public ?Uuid $id = null,
25+
#[Column(unique: true)]
26+
public ?string $fullName = null,
27+
) {
28+
}
29+
}

Tests/PropertyInfo/Fixtures/DoctrineFooType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform): ?str
4141
throw new ConversionException(sprintf('Expected "%s", got "%s"', 'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\Foo', get_debug_type($value)));
4242
}
4343

44-
return $foo->bar;
44+
return $value->bar;
4545
}
4646

4747
public function convertToPHPValue($value, AbstractPlatform $platform): ?Foo

Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@
4141
use Symfony\Bridge\Doctrine\Tests\Fixtures\UpdateCompositeIntIdEntity;
4242
use Symfony\Bridge\Doctrine\Tests\Fixtures\UpdateCompositeObjectNoToStringIdEntity;
4343
use Symfony\Bridge\Doctrine\Tests\Fixtures\UpdateEmployeeProfile;
44+
use Symfony\Bridge\Doctrine\Tests\Fixtures\UserUuidNameDto;
45+
use Symfony\Bridge\Doctrine\Tests\Fixtures\UserUuidNameEntity;
4446
use Symfony\Bridge\Doctrine\Tests\TestRepositoryFactory;
4547
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
4648
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntityValidator;
49+
use Symfony\Component\Uid\Uuid;
4750
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
4851
use Symfony\Component\Validator\Exception\UnexpectedValueException;
4952
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
@@ -116,6 +119,7 @@ private function createSchema($em)
116119
$em->getClassMetadata(Employee::class),
117120
$em->getClassMetadata(CompositeObjectNoToStringIdEntity::class),
118121
$em->getClassMetadata(SingleIntIdStringWrapperNameEntity::class),
122+
$em->getClassMetadata(UserUuidNameEntity::class),
119123
]);
120124
}
121125

@@ -1423,4 +1427,25 @@ public function testEntityManagerNullObjectWhenDTODoctrineStyle()
14231427

14241428
$this->validator->validate($dto, $constraint);
14251429
}
1430+
1431+
public function testUuidIdentifierWithSameValueDifferentInstanceDoesNotCauseViolation()
1432+
{
1433+
$uuidString = 'ec562e21-1fc8-4e55-8de7-a42389ac75c5';
1434+
$existingPerson = new UserUuidNameEntity(Uuid::fromString($uuidString), 'Foo Bar');
1435+
$this->em->persist($existingPerson);
1436+
$this->em->flush();
1437+
1438+
$dto = new UserUuidNameDto(Uuid::fromString($uuidString), 'Foo Bar', '');
1439+
1440+
$constraint = new UniqueEntity(
1441+
fields: ['fullName'],
1442+
entityClass: UserUuidNameEntity::class,
1443+
identifierFieldNames: ['id'],
1444+
em: self::EM_NAME,
1445+
);
1446+
1447+
$this->validator->validate($dto, $constraint);
1448+
1449+
$this->assertNoViolation();
1450+
}
14261451
}

Validator/Constraints/UniqueEntityValidator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ public function validate(mixed $value, Constraint $constraint): void
197197

198198
foreach ($constraint->identifierFieldNames as $identifierFieldName) {
199199
$propertyValue = $this->getPropertyValue($entityClass, $identifierFieldName, current($result));
200+
if ($fieldValues[$identifierFieldName] instanceof \Stringable) {
201+
$fieldValues[$identifierFieldName] = (string) $fieldValues[$identifierFieldName];
202+
}
203+
if ($propertyValue instanceof \Stringable) {
204+
$propertyValue = (string) $propertyValue;
205+
}
200206
if ($fieldValues[$identifierFieldName] !== $propertyValue) {
201207
$entityMatched = false;
202208
break;

0 commit comments

Comments
 (0)