Skip to content

[DoctrineBridge][Validator] Expose all fields for message validation failure #38969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 7.4
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: update tests
  • Loading branch information
ahmed-bhs committed Nov 2, 2020
commit 995d080f2728a05bfad4c01fcc7576074b2fe3f8
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down