From 1bfcff4fab44dab9698105630ad6b6695dd7d072 Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Thu, 24 May 2012 05:29:35 +0200 Subject: [PATCH] [OptionsResolver] added failing test cases to demonstrate two bugs --- .../Tests/OptionResolverTest.php | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionResolverTest.php b/src/Symfony/Component/OptionsResolver/Tests/OptionResolverTest.php index 5ecb38fd15..ef68c7f1e1 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionResolverTest.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionResolverTest.php @@ -372,4 +372,49 @@ class OptionsResolverTest extends \PHPUnit_Framework_TestCase $this->assertFalse($this->resolver->isRequired('foo')); } + + public function testResolveWithoutOptionSucceedsIfRequiredAndDefaultValue() + { + $this->resolver->setRequired(array( + 'foo', + )); + $this->resolver->setDefaults(array( + 'foo' => 'bar', + )); + + $this->assertEquals(array( + 'foo' => 'bar' + ), $this->resolver->resolve(array())); + } + + public function testResolveWithoutOptionSucceedsIfDefaultValueAndRequired() + { + $this->resolver->setDefaults(array( + 'foo' => 'bar', + )); + $this->resolver->setRequired(array( + 'foo', + )); + + $this->assertEquals(array( + 'foo' => 'bar' + ), $this->resolver->resolve(array())); + } + + public function testResolveSucceedsIfOptionRequiredAndValueAllowed() + { + $this->resolver->setRequired(array( + 'one', 'two', + )); + $this->resolver->setAllowedValues(array( + 'two' => array('2'), + )); + + $options = array( + 'one' => '1', + 'two' => '2' + ); + + $this->assertEquals($options, $this->resolver->resolve($options)); + } }