mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-11-26 20:04:48 +01:00
Add BuilderFactory->val() method
This commit is contained in:
parent
e4f493cd1d
commit
8f40eec122
@ -117,6 +117,17 @@ class BuilderFactory
|
||||
return new Builder\Use_($name, Use_::TYPE_NORMAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates node a for a literal value.
|
||||
*
|
||||
* @param Node\Expr|bool|null|int|float|string|array $value $value
|
||||
*
|
||||
* @return Node\Expr
|
||||
*/
|
||||
public function val($value) {
|
||||
return BuilderHelpers::normalizeValue($value);
|
||||
}
|
||||
|
||||
public function __call($name, array $args) {
|
||||
if (method_exists($this, '_' . $name)) {
|
||||
return $this->{'_' . $name}(...$args);
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace PhpParser;
|
||||
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
|
||||
class BuilderFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@ -34,6 +35,16 @@ class BuilderFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
$factory->foo();
|
||||
}
|
||||
|
||||
public function testVal() {
|
||||
// This method is a wrapper around BuilderHelpers::normalizeValue(),
|
||||
// which is already tested elsewhere
|
||||
$factory = new BuilderFactory();
|
||||
$this->assertEquals(
|
||||
new String_("foo"),
|
||||
$factory->val("foo")
|
||||
);
|
||||
}
|
||||
|
||||
public function testIntegration() {
|
||||
$factory = new BuilderFactory;
|
||||
$node = $factory->namespace('Name\Space')
|
||||
|
Loading…
Reference in New Issue
Block a user