Skip to content

Commit

Permalink
minor #13331 [OptionsResolver] added test for allowed values and type…
Browse files Browse the repository at this point in the history
…s that default to null (Tobion)

This PR was merged into the 2.6 branch.

Discussion
----------

[OptionsResolver] added test for allowed values and types that default to null

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | no
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Added test to keep logic as experienced in #12809

Commits
-------

0b42cad [OptionsResolver] added test for allowed values and types that default to null
  • Loading branch information
fabpot committed Jan 26, 2015
2 parents 3015f12 + 0b42cad commit 1901c84
Showing 1 changed file with 26 additions and 2 deletions.
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 1901c84

Please sign in to comment.