add new choices
wildcard in message
This commit is contained in:
parent
5f737e836e
commit
71dfa35a21
@ -68,6 +68,7 @@ class ChoiceValidator extends ConstraintValidator
|
|||||||
if (!\in_array($_value, $choices, true)) {
|
if (!\in_array($_value, $choices, true)) {
|
||||||
$this->context->buildViolation($constraint->multipleMessage)
|
$this->context->buildViolation($constraint->multipleMessage)
|
||||||
->setParameter('{{ value }}', $this->formatValue($_value))
|
->setParameter('{{ value }}', $this->formatValue($_value))
|
||||||
|
->setParameter('{{ choices }}', $this->formatValues($choices))
|
||||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||||
->setInvalidValue($_value)
|
->setInvalidValue($_value)
|
||||||
->addViolation();
|
->addViolation();
|
||||||
@ -100,6 +101,7 @@ class ChoiceValidator extends ConstraintValidator
|
|||||||
} elseif (!\in_array($value, $choices, true)) {
|
} elseif (!\in_array($value, $choices, true)) {
|
||||||
$this->context->buildViolation($constraint->message)
|
$this->context->buildViolation($constraint->message)
|
||||||
->setParameter('{{ value }}', $this->formatValue($value))
|
->setParameter('{{ value }}', $this->formatValue($value))
|
||||||
|
->setParameter('{{ choices }}', $this->formatValues($choices))
|
||||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||||
->addViolation();
|
->addViolation();
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,7 @@ class ChoiceValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->setParameter('{{ value }}', '"baz"')
|
->setParameter('{{ value }}', '"baz"')
|
||||||
|
->setParameter('{{ choices }}', '"foo", "bar"')
|
||||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||||
->assertRaised();
|
->assertRaised();
|
||||||
}
|
}
|
||||||
@ -186,6 +187,7 @@ class ChoiceValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->setParameter('{{ value }}', '"baz"')
|
->setParameter('{{ value }}', '"baz"')
|
||||||
|
->setParameter('{{ choices }}', '')
|
||||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||||
->assertRaised();
|
->assertRaised();
|
||||||
}
|
}
|
||||||
@ -202,6 +204,7 @@ class ChoiceValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->setParameter('{{ value }}', '"baz"')
|
->setParameter('{{ value }}', '"baz"')
|
||||||
|
->setParameter('{{ choices }}', '"foo", "bar"')
|
||||||
->setInvalidValue('baz')
|
->setInvalidValue('baz')
|
||||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||||
->assertRaised();
|
->assertRaised();
|
||||||
@ -275,6 +278,7 @@ class ChoiceValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->setParameter('{{ value }}', '"2"')
|
->setParameter('{{ value }}', '"2"')
|
||||||
|
->setParameter('{{ choices }}', '1, 2')
|
||||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||||
->assertRaised();
|
->assertRaised();
|
||||||
}
|
}
|
||||||
@ -291,6 +295,7 @@ class ChoiceValidatorTest extends ConstraintValidatorTestCase
|
|||||||
|
|
||||||
$this->buildViolation('myMessage')
|
$this->buildViolation('myMessage')
|
||||||
->setParameter('{{ value }}', '"3"')
|
->setParameter('{{ value }}', '"3"')
|
||||||
|
->setParameter('{{ choices }}', '1, 2, 3')
|
||||||
->setInvalidValue('3')
|
->setInvalidValue('3')
|
||||||
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
->setCode(Choice::NO_SUCH_CHOICE_ERROR)
|
||||||
->assertRaised();
|
->assertRaised();
|
||||||
|
Reference in New Issue
Block a user