1
0
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:
Nikita Popov 2017-04-24 21:28:03 +02:00
parent e4f493cd1d
commit 8f40eec122
2 changed files with 22 additions and 0 deletions

View File

@ -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);

View File

@ -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')