Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a10ff4c

Browse filesBrowse files
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 ------- 6eb836b [OptionsResolver] Fix force prepend normalizer
2 parents 73cb33a + 6eb836b commit a10ff4c
Copy full SHA for a10ff4c

File tree

2 files changed

+12
-0
lines changed
Filter options

2 files changed

+12
-0
lines changed

‎src/Symfony/Component/OptionsResolver/OptionsResolver.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/OptionsResolver.php
+1Lines 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;

‎src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php
+11Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.