Skip to content

Commit 376bd3a

Browse files
committed
[OptionsResolver] Fix force prepend normalizer
1 parent 2a96483 commit 376bd3a

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

OptionsResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ public function addNormalizer(string $option, \Closure $normalizer, bool $forceP
532532
}
533533

534534
if ($forcePrepend) {
535+
$this->normalizers[$option] = $this->normalizers[$option] ?? [];
535536
array_unshift($this->normalizers[$option], $normalizer);
536537
} else {
537538
$this->normalizers[$option][] = $normalizer;

Tests/OptionsResolverTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,17 @@ public function testForcePrependNormalizerClosure()
15061506
$this->assertEquals(['foo' => '2nd-normalized-1st-normalized-bar'], $this->resolver->resolve());
15071507
}
15081508

1509+
public function testForcePrependNormalizerForResolverWithoutPreviousNormalizers()
1510+
{
1511+
// defined by superclass
1512+
$this->resolver->setDefault('foo', 'bar');
1513+
$this->resolver->addNormalizer('foo', function (Options $options, $value) {
1514+
return '1st-normalized-'.$value;
1515+
}, true);
1516+
1517+
$this->assertEquals(['foo' => '1st-normalized-bar'], $this->resolver->resolve());
1518+
}
1519+
15091520
public function testAddNormalizerFailsIfUnknownOption()
15101521
{
15111522
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');

0 commit comments

Comments
 (0)