From 0b42cad97a4e2cb2669af7485a28938c4f4247db Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Thu, 8 Jan 2015 14:00:41 +0100 Subject: [PATCH] [OptionsResolver] added test for allowed values and types that default to null ref #12809 --- .../Tests/OptionsResolver2Dot6Test.php | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php index 5d715c57a446..3d8e0e339fc0 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php @@ -504,7 +504,19 @@ public function testFailIfSetAllowedTypesFromLazyOption() */ 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->resolve(); @@ -675,7 +687,19 @@ public function testFailIfSetAllowedValuesFromLazyOption() */ 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->resolve();