[OptionsResolver] fix allowed values with null
This commit is contained in:
parent
e3e9a4d269
commit
cb37fbe707
@ -484,7 +484,7 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
));
|
||||
}
|
||||
|
||||
$this->allowedValues[$option] = $allowedValues instanceof \Closure ? array($allowedValues) : (array) $allowedValues;
|
||||
$this->allowedValues[$option] = is_array($allowedValues) ? $allowedValues : array($allowedValues);
|
||||
|
||||
// Make sure the option is processed
|
||||
unset($this->resolved[$option]);
|
||||
@ -538,12 +538,14 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
));
|
||||
}
|
||||
|
||||
if ($allowedValues instanceof \Closure) {
|
||||
$this->allowedValues[$option][] = $allowedValues;
|
||||
} elseif (!isset($this->allowedValues[$option])) {
|
||||
$this->allowedValues[$option] = (array) $allowedValues;
|
||||
if (!is_array($allowedValues)) {
|
||||
$allowedValues = array($allowedValues);
|
||||
}
|
||||
|
||||
if (!isset($this->allowedValues[$option])) {
|
||||
$this->allowedValues[$option] = $allowedValues;
|
||||
} else {
|
||||
$this->allowedValues[$option] = array_merge($this->allowedValues[$option], (array) $allowedValues);
|
||||
$this->allowedValues[$option] = array_merge($this->allowedValues[$option], $allowedValues);
|
||||
}
|
||||
|
||||
// Make sure the option is processed
|
||||
|
@ -724,6 +724,14 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfValidValueIsNull()
|
||||
{
|
||||
$this->resolver->setDefault('foo', null);
|
||||
$this->resolver->setAllowedValues('foo', null);
|
||||
|
||||
$this->assertEquals(array('foo' => null), $this->resolver->resolve());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
* @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar", false, null.
|
||||
@ -847,6 +855,14 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());
|
||||
}
|
||||
|
||||
public function testResolveSucceedsIfValidAddedValueIsNull()
|
||||
{
|
||||
$this->resolver->setDefault('foo', null);
|
||||
$this->resolver->addAllowedValues('foo', null);
|
||||
|
||||
$this->assertEquals(array('foo' => null), $this->resolver->resolve());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||
*/
|
||||
|
Reference in New Issue
Block a user