[OptionsResolver] fix normalizer without corresponding option
This commit is contained in:
parent
5a53821ca3
commit
e2a50ef4bc
@ -504,7 +504,7 @@ class Options implements \ArrayAccess, \Iterator, \Countable
|
|||||||
$normalizer = $this->normalizers[$option];
|
$normalizer = $this->normalizers[$option];
|
||||||
|
|
||||||
$this->lock[$option] = true;
|
$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]);
|
unset($this->lock[$option]);
|
||||||
|
|
||||||
// The option is now normalized
|
// The option is now normalized
|
||||||
|
@ -514,4 +514,15 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->options->clear();
|
$this->options->clear();
|
||||||
$this->assertEmpty($this->options->all());
|
$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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user