add new choices wildcard in message

This commit is contained in:
Nicolas PHILIPPE 2018-12-20 18:23:49 +01:00
parent 5f737e836e
commit 71dfa35a21
2 changed files with 7 additions and 0 deletions

View File

@ -68,6 +68,7 @@ class ChoiceValidator extends ConstraintValidator
if (!\in_array($_value, $choices, true)) {
$this->context->buildViolation($constraint->multipleMessage)
->setParameter('{{ value }}', $this->formatValue($_value))
->setParameter('{{ choices }}', $this->formatValues($choices))
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
->setInvalidValue($_value)
->addViolation();
@ -100,6 +101,7 @@ class ChoiceValidator extends ConstraintValidator
} elseif (!\in_array($value, $choices, true)) {
$this->context->buildViolation($constraint->message)
->setParameter('{{ value }}', $this->formatValue($value))
->setParameter('{{ choices }}', $this->formatValues($choices))
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
->addViolation();
}

View File

@ -169,6 +169,7 @@ class ChoiceValidatorTest extends ConstraintValidatorTestCase
$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"baz"')
->setParameter('{{ choices }}', '"foo", "bar"')
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
->assertRaised();
}
@ -186,6 +187,7 @@ class ChoiceValidatorTest extends ConstraintValidatorTestCase
$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"baz"')
->setParameter('{{ choices }}', '')
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
->assertRaised();
}
@ -202,6 +204,7 @@ class ChoiceValidatorTest extends ConstraintValidatorTestCase
$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"baz"')
->setParameter('{{ choices }}', '"foo", "bar"')
->setInvalidValue('baz')
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
->assertRaised();
@ -275,6 +278,7 @@ class ChoiceValidatorTest extends ConstraintValidatorTestCase
$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"2"')
->setParameter('{{ choices }}', '1, 2')
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
->assertRaised();
}
@ -291,6 +295,7 @@ class ChoiceValidatorTest extends ConstraintValidatorTestCase
$this->buildViolation('myMessage')
->setParameter('{{ value }}', '"3"')
->setParameter('{{ choices }}', '1, 2, 3')
->setInvalidValue('3')
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
->assertRaised();