bug #37550 [OptionsResolver] Fix force prepend normalizer (hason)
This PR was merged into the 4.4 branch.
Discussion
----------
[OptionsResolver] Fix force prepend normalizer
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | -
| License | MIT
| Doc PR |
Commits
-------
6eb836b6f9
[OptionsResolver] Fix force prepend normalizer
This commit is contained in:
commit
a10ff4cb00
@ -532,6 +532,7 @@ class OptionsResolver implements Options
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($forcePrepend) {
|
if ($forcePrepend) {
|
||||||
|
$this->normalizers[$option] = $this->normalizers[$option] ?? [];
|
||||||
array_unshift($this->normalizers[$option], $normalizer);
|
array_unshift($this->normalizers[$option], $normalizer);
|
||||||
} else {
|
} else {
|
||||||
$this->normalizers[$option][] = $normalizer;
|
$this->normalizers[$option][] = $normalizer;
|
||||||
|
@ -1506,6 +1506,17 @@ class OptionsResolverTest extends TestCase
|
|||||||
$this->assertEquals(['foo' => '2nd-normalized-1st-normalized-bar'], $this->resolver->resolve());
|
$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()
|
public function testAddNormalizerFailsIfUnknownOption()
|
||||||
{
|
{
|
||||||
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
|
$this->expectException('Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException');
|
||||||
|
Reference in New Issue
Block a user