Skip to content

[ExpressionLanguage] throws an exception on calling uncallable method #24041

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ public function evaluate($functions, $values)
if (!is_object($obj)) {
throw new \RuntimeException('Unable to get a property on a non-object.');
}
if (!is_callable($toCall = array($obj, $this->nodes['attribute']->attributes['value']))) {
throw new \RuntimeException(sprintf('Unable to call method "%s" of object "%s".', $this->nodes['attribute']->attributes['value'], get_class($obj)));
}

return call_user_func_array(array($obj, $this->nodes['attribute']->attributes['value']), $this->nodes['arguments']->evaluate($functions, $values));
return call_user_func_array($toCall, $this->nodes['arguments']->evaluate($functions, $values));

case self::ARRAY_CALL:
$array = $this->nodes['node']->evaluate($functions, $values);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ public function testRegisterAfterEval($registerCallback)
$registerCallback($el);
}

/**
* @expectedException \RuntimeException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add also an @expectedExceptionMessage annotation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I did not add before to be consistent with the codebase in this component. I use @expectedExceptionMessageRegExp instead :)

* @expectedExceptionMessageRegExp /Unable to call method "\w+" of object "\w+"./
*/
public function testCallBadCallable()
{
$el = new ExpressionLanguage();
$el->evaluate('foo.myfunction()', array('foo' => new \stdClass()));
}

/**
* @dataProvider getRegisterCallbacks
* @expectedException \LogicException
Expand Down