From b137fd9143fb22090ba29eef61436dcd9a01ca67 Mon Sep 17 00:00:00 2001 From: Olivier Maisonneuve Date: Thu, 27 Sep 2012 14:24:10 +0200 Subject: [PATCH 1/3] validateOptionValues throw a notice if an allowed value is set and the corresponding option isn't. --- OptionsResolver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OptionsResolver.php b/OptionsResolver.php index e048f67..86a1f7a 100644 --- a/OptionsResolver.php +++ b/OptionsResolver.php @@ -294,7 +294,7 @@ private function validateOptionsCompleteness(array $options) private function validateOptionValues(array $options) { foreach ($this->allowedValues as $option => $allowedValues) { - if (!in_array($options[$option], $allowedValues, true)) { + if (isset($options[$option]) && !in_array($options[$option], $allowedValues, true)) { throw new InvalidOptionsException(sprintf('The option "%s" has the value "%s", but is expected to be one of "%s"', $option, $options[$option], implode('", "', $allowedValues))); } } From a666795c834d2cda7626f4ab41cb90e9787acd74 Mon Sep 17 00:00:00 2001 From: Olivier Maisonneuve Date: Thu, 27 Sep 2012 14:39:42 +0200 Subject: [PATCH 2/3] Unit test for patched method OptionsResolver::validateOptionValues(). --- Tests/OptionsResolverTest.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Tests/OptionsResolverTest.php b/Tests/OptionsResolverTest.php index d6e02b0..2fae357 100644 --- a/Tests/OptionsResolverTest.php +++ b/Tests/OptionsResolverTest.php @@ -258,6 +258,30 @@ public function testResolveSucceedsIfOptionValueAllowed2() ), $this->resolver->resolve($options)); } + public function testResolveSucceedsIfOptionalWithAllowedValuesNotSet() + { + $this->resolver->setRequired(array( + 'one', + )); + + $this->resolver->setOptional(array( + 'two', + )); + + $this->resolver->setAllowedValues(array( + 'one' => array('1', 'one'), + 'two' => array('2', 'two'), + )); + + $options = array( + 'one' => '1', + ); + + $this->assertEquals(array( + 'one' => '1', + ), $this->resolver->resolve($options)); + } + /** * @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException */ From 1ee199a5be56f5d40306838a75b9cff05896e660 Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Thu, 4 Oct 2012 17:17:57 +0200 Subject: [PATCH 3/3] [2.1] Exclude tests from zips via gitattributes --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..e742c9b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +Tests/ export-ignore +phpunit.xml.dist export-ignore