[OptionsResolver] Optimized previous values of a lazy option not to be evaluated if the second argument is not defined
This commit is contained in:
parent
8a338cb6fa
commit
d858f7bdf3
@ -190,7 +190,7 @@ class Options implements \ArrayAccess, \Iterator, \Countable
|
|||||||
$params = $reflClosure->getParameters();
|
$params = $reflClosure->getParameters();
|
||||||
|
|
||||||
if (isset($params[0]) && null !== ($class = $params[0]->getClass()) && __CLASS__ === $class->name) {
|
if (isset($params[0]) && null !== ($class = $params[0]->getClass()) && __CLASS__ === $class->name) {
|
||||||
$currentValue = isset($this->options[$option]) ? $this->options[$option] : null;
|
$currentValue = isset($params[1]) && isset($this->options[$option]) ? $this->options[$option] : null;
|
||||||
$value = new LazyOption($value, $currentValue);
|
$value = new LazyOption($value, $currentValue);
|
||||||
|
|
||||||
// Store which options are lazy for more efficient resolving
|
// Store which options are lazy for more efficient resolving
|
||||||
|
@ -156,6 +156,23 @@ class OptionsTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('dynamic', $this->options->get('foo'));
|
$this->assertEquals('dynamic', $this->options->get('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPreviousValueIsNotEvaluatedIfNoSecondArgument()
|
||||||
|
{
|
||||||
|
$test = $this;
|
||||||
|
|
||||||
|
// defined by superclass
|
||||||
|
$this->options->set('foo', function (Options $options) use ($test) {
|
||||||
|
$test->fail('Should not be called');
|
||||||
|
});
|
||||||
|
|
||||||
|
// defined by subclass, no $previousValue argument defined!
|
||||||
|
$this->options->overload('foo', function (Options $options) use ($test) {
|
||||||
|
return 'dynamic';
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->assertEquals('dynamic', $this->options->get('foo'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testLazyOptionCanAccessOtherOptions()
|
public function testLazyOptionCanAccessOtherOptions()
|
||||||
{
|
{
|
||||||
$test = $this;
|
$test = $this;
|
||||||
|
Reference in New Issue
Block a user