[OptionsResolver] fix invalid value exception formatting
This commit is contained in:
parent
6c2130f578
commit
dc1250c2b8
@ -848,7 +848,7 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
'"%s", but is of type "%s".',
|
||||
$option,
|
||||
$this->formatValue($value),
|
||||
implode('", "', $this->allowedTypes[$option]),
|
||||
implode('" or "', $this->allowedTypes[$option]),
|
||||
$this->formatTypeOf($value)
|
||||
));
|
||||
}
|
||||
@ -873,9 +873,7 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
break;
|
||||
}
|
||||
|
||||
$printableAllowedValues[] = is_object($value)
|
||||
? get_class($value)
|
||||
: (is_array($value) ? 'array' : (string) $value);
|
||||
$printableAllowedValues[] = $allowedValue;
|
||||
}
|
||||
|
||||
if (!$success) {
|
||||
@ -887,7 +885,7 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
|
||||
if (count($printableAllowedValues) > 0) {
|
||||
$message .= sprintf(
|
||||
' Accepted values are: %s',
|
||||
' Accepted values are: %s.',
|
||||
$this->formatValues($printableAllowedValues)
|
||||
);
|
||||
}
|
||||
|
@ -490,6 +490,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
* @expectedExceptionMessage The option "foo" with value 42 is expected to be of type "string", but is of type "integer".
|
||||
*/
|
||||
public function testResolveFailsIfInvalidType()
|
||||
{
|
||||
@ -509,6 +510,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
* @expectedExceptionMessage The option "foo" with value 42 is expected to be of type "string" or "bool", but is of type "integer".
|
||||
*/
|
||||
public function testResolveFailsIfInvalidTypeMultiple()
|
||||
{
|
||||
@ -659,6 +661,7 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
* @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar".
|
||||
*/
|
||||
public function testResolveFailsIfInvalidValue()
|
||||
{
|
||||
@ -689,11 +692,12 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
* @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar", false, null.
|
||||
*/
|
||||
public function testResolveFailsIfInvalidValueMultiple()
|
||||
{
|
||||
$this->resolver->setDefault('foo', 42);
|
||||
$this->resolver->setAllowedValues('foo', array('bar', 'baz'));
|
||||
$this->resolver->setAllowedValues('foo', array('bar', false, null));
|
||||
|
||||
$this->resolver->resolve();
|
||||
}
|
||||
|
Reference in New Issue
Block a user