Merge branch '2.6' into 2.7

This commit is contained in:
Tobias Schultze 2015-03-02 11:21:01 +01:00
commit 755ea09a44
2 changed files with 36 additions and 7 deletions

View File

@ -424,7 +424,18 @@ class OptionsResolver implements Options, OptionsResolverInterface
}
/**
* {@inheritdoc}
* Sets the normalizers for an array of options.
*
* @param array $normalizers An array of closures
*
* @return OptionsResolver This instance
*
* @throws UndefinedOptionsException If the option is undefined
* @throws AccessException If called from a lazy option or normalizer
*
* @see setNormalizer()
*
* @deprecated since version 2.6, to be removed in 3.0.
*/
public function setNormalizers(array $normalizers)
{
@ -483,7 +494,7 @@ class OptionsResolver implements Options, OptionsResolverInterface
));
}
$this->allowedValues[$option] = $allowedValues instanceof \Closure ? array($allowedValues) : (array) $allowedValues;
$this->allowedValues[$option] = is_array($allowedValues) ? $allowedValues : array($allowedValues);
// Make sure the option is processed
unset($this->resolved[$option]);
@ -539,12 +550,14 @@ class OptionsResolver implements Options, OptionsResolverInterface
));
}
if ($allowedValues instanceof \Closure) {
$this->allowedValues[$option][] = $allowedValues;
} elseif (!isset($this->allowedValues[$option])) {
$this->allowedValues[$option] = (array) $allowedValues;
if (!is_array($allowedValues)) {
$allowedValues = array($allowedValues);
}
if (!isset($this->allowedValues[$option])) {
$this->allowedValues[$option] = $allowedValues;
} else {
$this->allowedValues[$option] = array_merge($this->allowedValues[$option], (array) $allowedValues);
$this->allowedValues[$option] = array_merge($this->allowedValues[$option], $allowedValues);
}
// Make sure the option is processed

View File

@ -724,6 +724,14 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());
}
public function testResolveSucceedsIfValidValueIsNull()
{
$this->resolver->setDefault('foo', null);
$this->resolver->setAllowedValues('foo', null);
$this->assertEquals(array('foo' => null), $this->resolver->resolve());
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
* @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar", false, null.
@ -847,6 +855,14 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());
}
public function testResolveSucceedsIfValidAddedValueIsNull()
{
$this->resolver->setDefault('foo', null);
$this->resolver->addAllowedValues('foo', null);
$this->assertEquals(array('foo' => null), $this->resolver->resolve());
}
/**
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
*/