8000 [OptionsResolver] fix normalizer without corresponding option · symfony/symfony@e2a50ef · GitHub
[go: up one dir, main page]

Skip to content

Commit e2a50ef

Browse files
committed
[OptionsResolver] fix normalizer without corresponding option
1 parent 5a53821 commit e2a50ef

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Symfony/Component/OptionsResolver/Options.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ private function normalize($option)
504504
$normalizer = $this->normalizers[$option];
505505

506506
$this->lock[$option] = true;
507-
$this->options[$option] = $normalizer($this, $this->options[$option]);
507+
$this->options[$option] = $normalizer($this, array_key_exists($option, $this->options) ? $this->options[$option] : null);
508508
unset($this->lock[$option]);
509509

510510
// The option is now normalized

src/Symfony/Component/OptionsResolver/Tests/OptionsTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,4 +514,15 @@ public function testClearOptionAndNormalizer()
514514
$this->options->clear();
515515
$this->assertEmpty($this->options->all());
516516
}
517+
518+
public function testNormalizerWithoutCorrespondingOption()
519+
{
520+
$test = $this;
521+
522+
$this->options->setNormalizer('foo', function (Options $options, $previousValue) use ($test) {
523+
$test->assertNull($previousValue);
524+
return '';
525+
});
526+
$this->assertEquals(array('foo' => ''), $this->options->all());
527+
}
517528
}

0 commit comments

Comments
 (0)
0