[OptionsResolver] added test for allowed values and types that default to null
ref #12809
This commit is contained in:
parent
ccee4ea91d
commit
0b42cad97a
@ -504,7 +504,19 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testResolveFailsIfInvalidType()
|
public function testResolveFailsIfInvalidType()
|
||||||
{
|
{
|
||||||
$this->resolver->setDefault('foo', 42);
|
$this->resolver->setDefined('foo');
|
||||||
|
$this->resolver->setAllowedTypes('foo', 'string');
|
||||||
|
|
||||||
|
$this->resolver->resolve(array('foo' => 42));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||||
|
* @expectedExceptionMessage The option "foo" with value null is expected to be of type "string", but is of type "NULL".
|
||||||
|
*/
|
||||||
|
public function testResolveFailsIfInvalidTypeIsNull()
|
||||||
|
{
|
||||||
|
$this->resolver->setDefault('foo', null);
|
||||||
$this->resolver->setAllowedTypes('foo', 'string');
|
$this->resolver->setAllowedTypes('foo', 'string');
|
||||||
|
|
||||||
$this->resolver->resolve();
|
$this->resolver->resolve();
|
||||||
@ -675,7 +687,19 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testResolveFailsIfInvalidValue()
|
public function testResolveFailsIfInvalidValue()
|
||||||
{
|
{
|
||||||
$this->resolver->setDefault('foo', 42);
|
$this->resolver->setDefined('foo');
|
||||||
|
$this->resolver->setAllowedValues('foo', 'bar');
|
||||||
|
|
||||||
|
$this->resolver->resolve(array('foo' => 42));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
|
||||||
|
* @expectedExceptionMessage The option "foo" with value null is invalid. Accepted values are: "bar".
|
||||||
|
*/
|
||||||
|
public function testResolveFailsIfInvalidValueIsNull()
|
||||||
|
{
|
||||||
|
$this->resolver->setDefault('foo', null);
|
||||||
$this->resolver->setAllowedValues('foo', 'bar');
|
$this->resolver->setAllowedValues('foo', 'bar');
|
||||||
|
|
||||||
$this->resolver->resolve();
|
$this->resolver->resolve();
|
||||||
|
Reference in New Issue
Block a user