8000 minor #13331 [OptionsResolver] added test for allowed values and type… · symfony/symfony@1901c84 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1901c84

Browse files
committed
minor #13331 [OptionsResolver] added test for allowed values and types 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
2 parents 3015f12 + 0b42cad commit 1901c84

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/Symfony/Component/OptionsResolver/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)
0