Skip to content

Commit ae68b6c

Browse files
committed
[OptionsResolver] added test for allowed values and types that default to null
ref #12809
1 parent 23aed23 commit ae68b6c

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

Tests/OptionsResolver2Dot6Test.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,19 @@ public function testFailIfSetAllowedTypesFromLazyOption()
504504
*/
505505
public function testResolveFailsIfInvalidType()
506506
{
507-
$this->resolver->setDefault('foo', 42);
507+
$this->resolver->setDefined('foo');
508+
$this->resolver->setAllowedTypes('foo', 'string');
509+
510+
$this->resolver->resolve(array('foo' => 42));
511+
}
512+
513+
/**
514+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
515+
* @expectedExceptionMessage The option "foo" with value null is expected to be of type "string", but is of type "NULL".
516+
*/
517+
public function testResolveFailsIfInvalidTypeIsNull()
518+
{
519+
$this->resolver->setDefault('foo', null);
508520
$this->resolver->setAllowedTypes('foo', 'string');
509521

510522
$this->resolver->resolve();
@@ -675,7 +687,19 @@ public function testFailIfSetAllowedValuesFromLazyOption()
675687
*/
676688
public function testResolveFailsIfInvalidValue()
677689
{
678-
$this->resolver->setDefault('foo', 42);
690+
$this->resolver->setDefined('foo');
691+
$this->resolver->setAllowedValues('foo', 'bar');
692+
693+
$this->resolver->resolve(array('foo' => 42));
694+
}
695+
696+
/**
697+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
698+
* @expectedExceptionMessage The option "foo" with value null is invalid. Accepted values are: "bar".
699+
*/
700+
public function testResolveFailsIfInvalidValueIsNull()
701+
{
702+
$this->resolver->setDefault('foo', null);
679703
$this->resolver->setAllowedValues('foo', 'bar');
680704

681705
$this->resolver->resolve();

0 commit comments

Comments
 (0)