[OptionsResolver] Fix force prepend normalizer
This commit is contained in:
parent
ecb5f7c875
commit
6eb836b6f9
@ -532,6 +532,7 @@ class OptionsResolver implements Options
|
||||
}
|
||||
|
||||
if ($forcePrepend) {
|
||||
$this->normalizers[$option] = $this->normalizers[$option] ?? [];
|
||||
array_unshift($this->normalizers[$option], $normalizer);
|
||||
} else {
|
||||
$this->normalizers[$option][] = $normalizer;
|
||||
|
@ -1506,6 +1506,17 @@ class OptionsResolverTest extends TestCase
|
||||
$this->assertEquals(['foo' => '2nd-normalized-1st-normalized-bar'], $this->resolver->resolve());
|
||||
}
|
||||
|
||||
public function testForcePrependNormalizerForResolverWithoutPreviousNormalizers()
|
||||
{
|
||||
// defined by superclass
|
||||
$this->resolver->setDefault('foo', 'bar');
|
||||
$this->resolver->addNormalizer('foo', function (Options $options, $value) {
|
||||
return '1st-normalized-'.$value;
|
||||
}, true);
|
||||
|
||||
$this->assertEquals(['foo' => '1st-normalized-bar'], $this->resolver->resolve());
|
||||
}
|
||||
|
||||
public function testAddNormalizerFailsIfUnknownOption()
|
||||
{
|
||||
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
|
||||
|
Reference in New Issue
Block a user