[OptionsResolver] Fix catched exception along the dependency tree mistakenly detects cyclic dependencies
This commit is contained in:
parent
7d674c2135
commit
9a188c5215
@ -854,9 +854,14 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
// dependency
|
||||
// BEGIN
|
||||
$this->calling[$option] = true;
|
||||
try {
|
||||
foreach ($this->lazy[$option] as $closure) {
|
||||
$value = $closure($this, $value);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
unset($this->calling[$option]);
|
||||
throw $e;
|
||||
}
|
||||
unset($this->calling[$option]);
|
||||
// END
|
||||
}
|
||||
@ -953,7 +958,12 @@ class OptionsResolver implements Options, OptionsResolverInterface
|
||||
// dependency
|
||||
// BEGIN
|
||||
$this->calling[$option] = true;
|
||||
try {
|
||||
$value = $normalizer($this, $value);
|
||||
} catch (\Exception $e) {
|
||||
unset($this->calling[$option]);
|
||||
throw $e;
|
||||
}
|
||||
unset($this->calling[$option]);
|
||||
// END
|
||||
}
|
||||
|
@ -1103,6 +1103,56 @@ class OptionsResolver2Dot6Test extends \PHPUnit_Framework_TestCase
|
||||
$this->resolver->resolve();
|
||||
}
|
||||
|
||||
public function testCatchedExceptionFromNormalizerDoesNotCrashOptionResolver()
|
||||
{
|
||||
$throw = true;
|
||||
|
||||
$this->resolver->setDefaults(array('catcher' => null, 'thrower' => null));
|
||||
|
||||
$this->resolver->setNormalizer('catcher', function (Options $options) {
|
||||
try {
|
||||
return $options['thrower'];
|
||||
} catch(\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$this->resolver->setNormalizer('thrower', function (Options $options) use (&$throw) {
|
||||
if ($throw) {
|
||||
$throw = false;
|
||||
throw new \UnexpectedValueException('throwing');
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$this->resolver->resolve();
|
||||
}
|
||||
|
||||
public function testCatchedExceptionFromLazyDoesNotCrashOptionResolver()
|
||||
{
|
||||
$throw = true;
|
||||
|
||||
$this->resolver->setDefault('catcher', function (Options $options) {
|
||||
try {
|
||||
return $options['thrower'];
|
||||
} catch(\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
$this->resolver->setDefault('thrower', function (Options $options) use (&$throw) {
|
||||
if ($throw) {
|
||||
$throw = false;
|
||||
throw new \UnexpectedValueException('throwing');
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$this->resolver->resolve();
|
||||
}
|
||||
|
||||
public function testInvokeEachNormalizerOnlyOnce()
|
||||
{
|
||||
$calls = 0;
|
||||
|
Reference in New Issue
Block a user