diff --git a/lib/PhpParser/Builder/Use_.php b/lib/PhpParser/Builder/Use_.php index 9999d0a..f6d3a85 100644 --- a/lib/PhpParser/Builder/Use_.php +++ b/lib/PhpParser/Builder/Use_.php @@ -36,8 +36,12 @@ class Use_ extends BuilderAbstract { $this->alias = $alias; return $this; } - public function __call($method, $args) { - return call_user_func_array(array($this, $method . '_'), $args); + public function __call($name, $args) { + if (method_exists($this, $name . '_')) { + return call_user_func_array(array($this, $name . '_'), $args); + } + + throw new \LogicException(sprintf('Method "%s" does not exist', $name)); } /** diff --git a/test/PhpParser/Builder/UseTest.php b/test/PhpParser/Builder/UseTest.php index 79a2cb8..adaeb3a 100644 --- a/test/PhpParser/Builder/UseTest.php +++ b/test/PhpParser/Builder/UseTest.php @@ -26,4 +26,10 @@ class UseTest extends \PHPUnit_Framework_TestCase new Stmt\UseUse(new Name('foo\bar'), 'foo') ), Stmt\Use_::TYPE_FUNCTION), $node); } + + public function testNonExistingMethod() { + $this->setExpectedException('LogicException', 'Method "foo" does not exist'); + $builder = $this->createUseBuilder('Test'); + $builder->foo(); + } } diff --git a/test/PhpParser/BuilderFactoryTest.php b/test/PhpParser/BuilderFactoryTest.php index bc4e559..1c3ef18 100644 --- a/test/PhpParser/BuilderFactoryTest.php +++ b/test/PhpParser/BuilderFactoryTest.php @@ -28,6 +28,12 @@ class BuilderFactoryTest extends \PHPUnit_Framework_TestCase ); } + public function testNonExistingMethod() { + $this->setExpectedException('LogicException', 'Method "foo" does not exist'); + $factory = new BuilderFactory(); + $factory->foo(); + } + public function testIntegration() { $factory = new BuilderFactory; $node = $factory->namespace('Name\Space')