OptionsResolver#validateOptionTypes should check if option value exists before checking its type; added corresponding test
OptionsResolver#validateOptionsCompleteness would already have thrown exception if the option were required, so this should only affect something explicitly marked as optional
This commit is contained in:
parent
b1618d210c
commit
c6a9638adb
@ -312,6 +312,10 @@ class OptionsResolver implements OptionsResolverInterface
|
||||
private function validateOptionTypes(array $options)
|
||||
{
|
||||
foreach ($this->allowedTypes as $option => $allowedTypes) {
|
||||
if (!isset($options[$option])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$value = $options[$option];
|
||||
$allowedTypes = (array) $allowedTypes;
|
||||
|
||||
|
@ -381,6 +381,27 @@ class OptionsResolverTest extends \PHPUnit_Framework_TestCase
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfOptionalWithTypeAndWithoutValue()
|
||||
{
|
||||
$this->resolver->setOptional(array(
|
||||
'one',
|
||||
'two',
|
||||
));
|
||||
|
||||
$this->resolver->setAllowedTypes(array(
|
||||
'one' => 'string',
|
||||
'two' => 'int',
|
||||
));
|
||||
|
||||
$options = array(
|
||||
'two' => 1,
|
||||
);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'two' => 1,
|
||||
), $this->resolver->resolve($options));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
*/
|
||||
|
Reference in New Issue
Block a user