diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php index 985d4601bf4d5..42220b8cf1dbc 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php @@ -197,6 +197,7 @@ public function testValidateUniqueness() $this->buildViolation('myMessage') ->atPath('property.path.name') ->setParameter('{{ value }}', '"Foo"') + ->setParameter('{{ name }}', '"Foo"') ->setInvalidValue($entity2) ->setCause([$entity1]) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) @@ -223,6 +224,7 @@ public function testValidateCustomErrorPath() $this->buildViolation('myMessage') ->atPath('property.path.bar') ->setParameter('{{ value }}', '"Foo"') + ->setParameter('{{ name }}', '"Foo"') ->setInvalidValue($entity2) ->setCause([$entity1]) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) @@ -277,6 +279,8 @@ public function testValidateUniquenessWithIgnoreNullDisabled() $this->buildViolation('myMessage') ->atPath('property.path.name') ->setParameter('{{ value }}', '"Foo"') + ->setParameter('{{ name }}', '"Foo"') + ->setParameter('{{ name2 }}', '') ->setInvalidValue('Foo') ->setCause([$entity1]) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) @@ -354,6 +358,8 @@ public function testValidateUniquenessWithValidCustomErrorPath() $this->buildViolation('myMessage') ->atPath('property.path.name2') ->setParameter('{{ value }}', '"Bar"') + ->setParameter('{{ name }}', '"Foo"') + ->setParameter('{{ name2 }}', '"Bar"') ->setInvalidValue('Bar') ->setCause([$entity1]) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) @@ -489,6 +495,7 @@ public function testAssociatedEntity() $this->buildViolation('myMessage') ->atPath('property.path.single') ->setParameter('{{ value }}', 'foo') + ->setParameter('{{ single }}', 'foo') ->setInvalidValue($entity1) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) ->setCause([$associated, $associated2]) @@ -527,6 +534,7 @@ public function testValidateUniquenessNotToStringEntityWithAssociatedEntity() $this->buildViolation('myMessage') ->atPath('property.path.single') ->setParameter('{{ value }}', $expectedValue) + ->setParameter('{{ single }}', $expectedValue) ->setInvalidValue($entity1) ->setCause([$associated, $associated2]) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) @@ -586,6 +594,7 @@ public function testValidateUniquenessWithArrayValue() $this->buildViolation('myMessage') ->atPath('property.path.phoneNumbers') ->setParameter('{{ value }}', 'array') + ->setParameter('{{ phoneNumbers }}', 'array') ->setInvalidValue([123]) ->setCause([$entity1]) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) @@ -690,7 +699,7 @@ public function testValidateInheritanceUniqueness() ->setInvalidValue('Foo') ->setCode('23bd9dbf-6b9b-41cd-a99e-4844bcf3077f') ->setCause([$entity1]) - ->setParameters(['{{ value }}' => '"Foo"']) + ->setParameters(['{{ value }}' => '"Foo"', '{{ name }}' => '"Foo"']) ->assertRaised(); } @@ -733,11 +742,14 @@ public function testValidateUniquenessWithCompositeObjectNoToStringIdEntity() $this->validator->validate($newEntity, $constraint); - $expectedValue = 'object("Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity") identified by (id => 1)'; + $expectedValueForObjectOne = 'object("Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity") identified by (id => 1)'; + $expectedValueForObjectTwo = 'object("Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity") identified by (id => 2)'; $this->buildViolation('myMessage') ->atPath('property.path.objectOne') - ->setParameter('{{ value }}', $expectedValue) + ->setParameter('{{ value }}', $expectedValueForObjectOne) + ->setParameter('{{ objectOne }}', $expectedValueForObjectOne) + ->setParameter('{{ objectTwo }}', $expectedValueForObjectTwo) ->setInvalidValue($objectOne) ->setCause([$entity]) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) @@ -766,6 +778,7 @@ public function testValidateUniquenessWithCustomDoctrineTypeValue() $this->buildViolation('myMessage') ->atPath('property.path.name') ->setParameter('{{ value }}', $expectedValue) + ->setParameter('{{ name }}', $expectedValue) ->setInvalidValue($existingEntity->name) ->setCause([$existingEntity]) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) @@ -802,6 +815,7 @@ public function testValidateUniquenessCause() $this->buildViolation('myMessage') ->atPath('property.path.name') ->setParameter('{{ value }}', '"Foo"') + ->setParameter('{{ name }}', '"Foo"') ->setInvalidValue($entity2) ->setCause([$entity1]) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) diff --git a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php index cbf40af2b5750..560c2c6e0fb6e 100644 --- a/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php +++ b/src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php @@ -167,13 +167,21 @@ public function validate($entity, Constraint $constraint) $errorPath = null !== $constraint->errorPath ? $constraint->errorPath : $fields[0]; $invalidValue = isset($criteria[$errorPath]) ? $criteria[$errorPath] : $criteria[$fields[0]]; - $this->context->buildViolation($constraint->message) + $constraintViolationBuilder = $this->context->buildViolation($constraint->message) ->atPath($errorPath) ->setParameter('{{ value }}', $this->formatWithIdentifiers($em, $class, $invalidValue)) ->setInvalidValue($invalidValue) ->setCode(UniqueEntity::NOT_UNIQUE_ERROR) ->setCause($result) - ->addViolation(); + ; + foreach ($fields as $field) { + $constraintViolationBuilder->setParameter( + sprintf('{{ %s }}', $field), + ($criteria[$field]) ? $this->formatWithIdentifiers($em, $class, $criteria[$field]) : '' + ); + } + + $constraintViolationBuilder->addViolation(); } private function formatWithIdentifiers($em, $class, $value) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy