[OptionsResolver] fix normalizer without corresponding option

This commit is contained in:
Tobias Schultze 2012-07-30 23:35:43 +02:00
parent 5a53821ca3
commit e2a50ef4bc
2 changed files with 12 additions and 1 deletions

View File

@ -504,7 +504,7 @@ class Options implements \ArrayAccess, \Iterator, \Countable
$normalizer = $this->normalizers[$option];
$this->lock[$option] = true;
$this->options[$option] = $normalizer($this, $this->options[$option]);
$this->options[$option] = $normalizer($this, array_key_exists($option, $this->options) ? $this->options[$option] : null);
unset($this->lock[$option]);
// The option is now normalized

View File

@ -514,4 +514,15 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
$this->options->clear();
$this->assertEmpty($this->options->all());
}
public function testNormalizerWithoutCorrespondingOption()
{
$test = $this;
$this->options->setNormalizer('foo', function (Options $options, $previousValue) use ($test) {
$test->assertNull($previousValue);
return '';
});
$this->assertEquals(array('foo' => ''), $this->options->all());
}
}