Skip to content

Commit 510c096

Browse files
committed
Merge branch '2.6' into 2.7
2 parents 51b955a + 88a17e5 commit 510c096

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

OptionsResolver.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,18 @@ public function setNormalizer($option, \Closure $normalizer)
424424
}
425425

426426
/**
427-
* {@inheritdoc}
427+
* Sets the normalizers for an array of options.
428+
*
429+
* @param array $normalizers An array of closures
430+
*
431+
* @return OptionsResolver This instance
432+
*
433+
* @throws UndefinedOptionsException If the option is undefined
434+
* @throws AccessException If called from a lazy option or normalizer
435+
*
436+
* @see setNormalizer()
437+
*
438+
* @deprecated since version 2.6, to be removed in 3.0.
428439
*/
429440
public function setNormalizers(array $normalizers)
430441
{
@@ -483,7 +494,7 @@ public function setAllowedValues($option, $allowedValues = null)
483494
));
484495
}
485496

486-
$this->allowedValues[$option] = $allowedValues instanceof \Closure ? array($allowedValues) : (array) $allowedValues;
497+
$this->allowedValues[$option] = is_array($allowedValues) ? $allowedValues : array($allowedValues);
487498

488499
// Make sure the option is processed
489500
unset($this->resolved[$option]);
@@ -539,12 +550,14 @@ public function addAllowedValues($option, $allowedValues = null)
539550
));
540551
}
541552

542-
if ($allowedValues instanceof \Closure) {
543-
$this->allowedValues[$option][] = $allowedValues;
544-
} elseif (!isset($this->allowedValues[$option])) {
545-
$this->allowedValues[$option] = (array) $allowedValues;
553+
if (!is_array($allowedValues)) {
554+
$allowedValues = array($allowedValues);
555+
}
556+
557+
if (!isset($this->allowedValues[$option])) {
558+
$this->allowedValues[$option] = $allowedValues;
546559
} else {
547-
$this->allowedValues[$option] = array_merge($this->allowedValues[$option], (array) $allowedValues);
560+
$this->allowedValues[$option] = array_merge($this->allowedValues[$option], $allowedValues);
548561
}
549562

550563
// Make sure the option is processed

Tests/OptionsResolver2Dot6Test.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,14 @@ public function testResolveSucceedsIfValidValue()
724724
$this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());
725725
}
726726

727+
public function testResolveSucceedsIfValidValueIsNull()
728+
{
729+
$this->resolver->setDefault('foo', null);
730+
$this->resolver->setAllowedValues('foo', null);
731+
732+
$this->assertEquals(array('foo' => null), $this->resolver->resolve());
733+
}
734+
727735
/**
728736
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
729737
* @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar", false, null.
@@ -847,6 +855,14 @@ public function testResolveSucceedsIfValidAddedValue()
847855
$this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());
848856
}
849857

858+
public function testResolveSucceedsIfValidAddedValueIsNull()
859+
{
860+
$this->resolver->setDefault('foo', null);
861+
$this->resolver->addAllowedValues('foo', null);
862+
863+
$this->assertEquals(array('foo' => null), $this->resolver->resolve());
864+
}
865+
850866
/**
851867
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
852868
*/

0 commit comments

Comments
 (0)