Skip to content

Commit 3d0a0c4

Browse files
committed
[OptionsResolver] fix invalid value exception formatting
1 parent 79ee1bc commit 3d0a0c4

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

OptionsResolver.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ public function offsetGet($option)
848848
'"%s", but is of type "%s".',
849849
$option,
850850
$this->formatValue($value),
851-
implode('", "', $this->allowedTypes[$option]),
851+
implode('" or "', $this->allowedTypes[$option]),
852852
$this->formatTypeOf($value)
853853
));
854854
}
@@ -873,9 +873,7 @@ public function offsetGet($option)
873873
break;
874874
}
875875

876-
$printableAllowedValues[] = is_object($value)
877-
? get_class($value)
878-
: (is_array($value) ? 'array' : (string) $value);
876+
$printableAllowedValues[] = $allowedValue;
879877
}
880878

881879
if (!$success) {
@@ -887,7 +885,7 @@ public function offsetGet($option)
887885

888886
if (count($printableAllowedValues) > 0) {
889887
$message .= sprintf(
890-
' Accepted values are: %s',
888+
' Accepted values are: %s.',
891889
$this->formatValues($printableAllowedValues)
892890
);
893891
}

Tests/OptionsResolver2Dot6Test.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ public function testFailIfSetAllowedTypesFromLazyOption()
490490

491491
/**
492492
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
493+
* @expectedExceptionMessage The option "foo" with value 42 is expected to be of type "string", but is of type "integer".
493494
*/
494495
public function testResolveFailsIfInvalidType()
495496
{
@@ -509,6 +510,7 @@ public function testResolveSucceedsIfValidType()
509510

510511
/**
511512
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
513+
* @expectedExceptionMessage The option "foo" with value 42 is expected to be of type "string" or "bool", but is of type "integer".
512514
*/
513515
public function testResolveFailsIfInvalidTypeMultiple()
514516
{
@@ -659,6 +661,7 @@ public function testFailIfSetAllowedValuesFromLazyOption()
659661

660662
/**
661663
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
664+
* @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar".
662665
*/
663666
public function testResolveFailsIfInvalidValue()
664667
{
@@ -689,11 +692,12 @@ public function testResolveSucceedsIfValidValue()
689692

690693
/**
691694
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
695+
* @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar", false, null.
692696
*/
693697
public function testResolveFailsIfInvalidValueMultiple()
694698
{
695699
$this->resolver->setDefault('foo', 42);
696-
$this->resolver->setAllowedValues('foo', array('bar', 'baz'));
700+
$this->resolver->setAllowedValues('foo', array('bar', false, null));
697701

698702
$this->resolver->resolve();
699703
}

0 commit comments

Comments
 (0)