Laravel version update

Laravel version update
This commit is contained in:
Manish Verma
2018-08-06 18:48:58 +05:30
parent d143048413
commit 126fbb0255
13678 changed files with 1031482 additions and 778530 deletions

View File

@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Builder;
@@ -6,8 +6,9 @@ use PhpParser\Comment;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PHPUnit\Framework\TestCase;
class ClassTest extends \PHPUnit_Framework_TestCase
class ClassTest extends TestCase
{
protected function createClassBuilder($class) {
return new Class_($class);
@@ -22,15 +23,15 @@ class ClassTest extends \PHPUnit_Framework_TestCase
;
$this->assertEquals(
new Stmt\Class_('SomeLogger', array(
new Stmt\Class_('SomeLogger', [
'extends' => new Name('BaseLogger'),
'implements' => array(
'implements' => [
new Name('Namespaced\Logger'),
new Name('SomeInterface'),
new Name\FullyQualified('Fully\Qualified'),
new Name\Relative('NamespaceRelative'),
),
)),
],
]),
$node
);
}
@@ -42,9 +43,9 @@ class ClassTest extends \PHPUnit_Framework_TestCase
;
$this->assertEquals(
new Stmt\Class_('Test', array(
'type' => Stmt\Class_::MODIFIER_ABSTRACT
)),
new Stmt\Class_('Test', [
'flags' => Stmt\Class_::MODIFIER_ABSTRACT
]),
$node
);
}
@@ -56,9 +57,9 @@ class ClassTest extends \PHPUnit_Framework_TestCase
;
$this->assertEquals(
new Stmt\Class_('Test', array(
'type' => Stmt\Class_::MODIFIER_FINAL
)),
new Stmt\Class_('Test', [
'flags' => Stmt\Class_::MODIFIER_FINAL
]),
$node
);
}
@@ -67,24 +68,24 @@ class ClassTest extends \PHPUnit_Framework_TestCase
$method = new Stmt\ClassMethod('testMethod');
$property = new Stmt\Property(
Stmt\Class_::MODIFIER_PUBLIC,
array(new Stmt\PropertyProperty('testProperty'))
[new Stmt\PropertyProperty('testProperty')]
);
$const = new Stmt\ClassConst(array(
$const = new Stmt\ClassConst([
new Node\Const_('TEST_CONST', new Node\Scalar\String_('ABC'))
));
$use = new Stmt\TraitUse(array(new Name('SomeTrait')));
]);
$use = new Stmt\TraitUse([new Name('SomeTrait')]);
$node = $this->createClassBuilder('Test')
->addStmt($method)
->addStmt($property)
->addStmts(array($const, $use))
->addStmts([$const, $use])
->getNode()
;
$this->assertEquals(
new Stmt\Class_('Test', array(
'stmts' => array($use, $const, $property, $method)
)),
new Stmt\Class_('Test', [
'stmts' => [$use, $const, $property, $method]
]),
$node
);
}
@@ -100,11 +101,11 @@ DOC;
->getNode();
$this->assertEquals(
new Stmt\Class_('Test', array(), array(
'comments' => array(
new Stmt\Class_('Test', [], [
'comments' => [
new Comment\Doc($docComment)
)
)),
]
]),
$class
);
@@ -113,11 +114,11 @@ DOC;
->getNode();
$this->assertEquals(
new Stmt\Class_('Test', array(), array(
'comments' => array(
new Stmt\Class_('Test', [], [
'comments' => [
new Comment\Doc($docComment)
)
)),
]
]),
$class
);
}
@@ -128,7 +129,7 @@ DOC;
*/
public function testInvalidStmtError() {
$this->createClassBuilder('Test')
->addStmt(new Stmt\Echo_(array()))
->addStmt(new Stmt\Echo_([]))
;
}
@@ -152,10 +153,10 @@ DOC;
/**
* @expectedException \LogicException
* @expectedExceptionMessage Name must be a string or an instance of PhpParser\Node\Name
* @expectedExceptionMessage Name must be a string or an instance of Node\Name
*/
public function testInvalidName() {
$this->createClassBuilder('Test')
->extend(array('Foo'));
->extend(['Foo']);
}
}

View File

@@ -1,14 +1,16 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Builder;
use PhpParser\Comment;
use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\Node\Expr\Print_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt;
use PHPUnit\Framework\TestCase;
class FunctionTest extends \PHPUnit_Framework_TestCase
class FunctionTest extends TestCase
{
public function createFunctionBuilder($name) {
return new Function_($name);
@@ -21,28 +23,28 @@ class FunctionTest extends \PHPUnit_Framework_TestCase
;
$this->assertEquals(
new Stmt\Function_('test', array(
new Stmt\Function_('test', [
'byRef' => true
)),
]),
$node
);
}
public function testParams() {
$param1 = new Node\Param('test1');
$param2 = new Node\Param('test2');
$param3 = new Node\Param('test3');
$param1 = new Node\Param(new Variable('test1'));
$param2 = new Node\Param(new Variable('test2'));
$param3 = new Node\Param(new Variable('test3'));
$node = $this->createFunctionBuilder('test')
->addParam($param1)
->addParams(array($param2, $param3))
->addParams([$param2, $param3])
->getNode()
;
$this->assertEquals(
new Stmt\Function_('test', array(
'params' => array($param1, $param2, $param3)
)),
new Stmt\Function_('test', [
'params' => [$param1, $param2, $param3]
]),
$node
);
}
@@ -54,14 +56,18 @@ class FunctionTest extends \PHPUnit_Framework_TestCase
$node = $this->createFunctionBuilder('test')
->addStmt($stmt1)
->addStmts(array($stmt2, $stmt3))
->addStmts([$stmt2, $stmt3])
->getNode()
;
$this->assertEquals(
new Stmt\Function_('test', array(
'stmts' => array($stmt1, $stmt2, $stmt3)
)),
new Stmt\Function_('test', [
'stmts' => [
new Stmt\Expression($stmt1),
new Stmt\Expression($stmt2),
new Stmt\Expression($stmt3),
]
]),
$node
);
}
@@ -71,19 +77,27 @@ class FunctionTest extends \PHPUnit_Framework_TestCase
->setDocComment('/** Test */')
->getNode();
$this->assertEquals(new Stmt\Function_('test', array(), array(
'comments' => array(new Comment\Doc('/** Test */'))
)), $node);
$this->assertEquals(new Stmt\Function_('test', [], [
'comments' => [new Comment\Doc('/** Test */')]
]), $node);
}
public function testReturnType() {
$node = $this->createFunctionBuilder('test')
->setReturnType('bool')
->setReturnType('void')
->getNode();
$this->assertEquals(new Stmt\Function_('test', array(
'returnType' => 'bool'
), array()), $node);
$this->assertEquals(new Stmt\Function_('test', [
'returnType' => 'void'
], []), $node);
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage void type cannot be nullable
*/
public function testInvalidNullableVoidType() {
$this->createFunctionBuilder('test')->setReturnType('?void');
}
/**
@@ -95,4 +109,13 @@ class FunctionTest extends \PHPUnit_Framework_TestCase
->addParam(new Node\Name('foo'))
;
}
/**
* @expectedException \LogicException
* @expectedExceptionMessage Expected statement or expression node
*/
public function testAddNonStmt() {
$this->createFunctionBuilder('test')
->addStmt(new Node\Name('Test'));
}
}

View File

@@ -1,13 +1,14 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Builder;
use PhpParser\Node;
use PhpParser\Node\Stmt;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Comment;
use PhpParser\Node;
use PhpParser\Node\Scalar\DNumber;
use PhpParser\Node\Stmt;
use PHPUnit\Framework\TestCase;
class InterfaceTest extends \PHPUnit_Framework_TestCase
class InterfaceTest extends TestCase
{
/** @var Interface_ */
protected $builder;
@@ -18,45 +19,45 @@ class InterfaceTest extends \PHPUnit_Framework_TestCase
private function dump($node) {
$pp = new \PhpParser\PrettyPrinter\Standard;
return $pp->prettyPrint(array($node));
return $pp->prettyPrint([$node]);
}
public function testEmpty() {
$contract = $this->builder->getNode();
$this->assertInstanceOf('PhpParser\Node\Stmt\Interface_', $contract);
$this->assertSame('Contract', $contract->name);
$this->assertInstanceOf(Stmt\Interface_::class, $contract);
$this->assertEquals(new Node\Identifier('Contract'), $contract->name);
}
public function testExtending() {
$contract = $this->builder->extend('Space\Root1', 'Root2')->getNode();
$this->assertEquals(
new Stmt\Interface_('Contract', array(
'extends' => array(
new Stmt\Interface_('Contract', [
'extends' => [
new Node\Name('Space\Root1'),
new Node\Name('Root2')
),
)), $contract
],
]), $contract
);
}
public function testAddMethod() {
$method = new Stmt\ClassMethod('doSomething');
$contract = $this->builder->addStmt($method)->getNode();
$this->assertSame(array($method), $contract->stmts);
$this->assertSame([$method], $contract->stmts);
}
public function testAddConst() {
$const = new Stmt\ClassConst(array(
$const = new Stmt\ClassConst([
new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458.0))
));
]);
$contract = $this->builder->addStmt($const)->getNode();
$this->assertSame(299792458.0, $contract->stmts[0]->consts[0]->value->value);
}
public function testOrder() {
$const = new Stmt\ClassConst(array(
$const = new Stmt\ClassConst([
new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458))
));
]);
$method = new Stmt\ClassMethod('doSomething');
$contract = $this->builder
->addStmt($method)
@@ -64,8 +65,8 @@ class InterfaceTest extends \PHPUnit_Framework_TestCase
->getNode()
;
$this->assertInstanceOf('PhpParser\Node\Stmt\ClassConst', $contract->stmts[0]);
$this->assertInstanceOf('PhpParser\Node\Stmt\ClassMethod', $contract->stmts[1]);
$this->assertInstanceOf(Stmt\ClassConst::class, $contract->stmts[0]);
$this->assertInstanceOf(Stmt\ClassMethod::class, $contract->stmts[1]);
}
public function testDocComment() {
@@ -73,9 +74,9 @@ class InterfaceTest extends \PHPUnit_Framework_TestCase
->setDocComment('/** Test */')
->getNode();
$this->assertEquals(new Stmt\Interface_('Contract', array(), array(
'comments' => array(new Comment\Doc('/** Test */'))
)), $node);
$this->assertEquals(new Stmt\Interface_('Contract', [], [
'comments' => [new Comment\Doc('/** Test */')]
]), $node);
}
/**
@@ -87,9 +88,9 @@ class InterfaceTest extends \PHPUnit_Framework_TestCase
}
public function testFullFunctional() {
$const = new Stmt\ClassConst(array(
$const = new Stmt\ClassConst([
new Node\Const_('SPEED_OF_LIGHT', new DNumber(299792458))
));
]);
$method = new Stmt\ClassMethod('doSomething');
$contract = $this->builder
->addStmt($method)
@@ -102,4 +103,3 @@ class InterfaceTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(interface_exists('Contract', false));
}
}

View File

@@ -1,14 +1,16 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Builder;
use PhpParser\Comment;
use PhpParser\Node;
use PhpParser\Node\Expr\Print_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\Stmt;
use PhpParser\Comment;
use PHPUnit\Framework\TestCase;
class MethodTest extends \PHPUnit_Framework_TestCase
class MethodTest extends TestCase
{
public function createMethodBuilder($name) {
return new Method($name);
@@ -23,12 +25,12 @@ class MethodTest extends \PHPUnit_Framework_TestCase
;
$this->assertEquals(
new Stmt\ClassMethod('test', array(
'type' => Stmt\Class_::MODIFIER_PUBLIC
| Stmt\Class_::MODIFIER_ABSTRACT
| Stmt\Class_::MODIFIER_STATIC,
new Stmt\ClassMethod('test', [
'flags' => Stmt\Class_::MODIFIER_PUBLIC
| Stmt\Class_::MODIFIER_ABSTRACT
| Stmt\Class_::MODIFIER_STATIC,
'stmts' => null,
)),
]),
$node
);
@@ -39,10 +41,10 @@ class MethodTest extends \PHPUnit_Framework_TestCase
;
$this->assertEquals(
new Stmt\ClassMethod('test', array(
'type' => Stmt\Class_::MODIFIER_PROTECTED
| Stmt\Class_::MODIFIER_FINAL
)),
new Stmt\ClassMethod('test', [
'flags' => Stmt\Class_::MODIFIER_PROTECTED
| Stmt\Class_::MODIFIER_FINAL
]),
$node
);
@@ -52,9 +54,9 @@ class MethodTest extends \PHPUnit_Framework_TestCase
;
$this->assertEquals(
new Stmt\ClassMethod('test', array(
new Stmt\ClassMethod('test', [
'type' => Stmt\Class_::MODIFIER_PRIVATE
)),
]),
$node
);
}
@@ -66,28 +68,28 @@ class MethodTest extends \PHPUnit_Framework_TestCase
;
$this->assertEquals(
new Stmt\ClassMethod('test', array(
new Stmt\ClassMethod('test', [
'byRef' => true
)),
]),
$node
);
}
public function testParams() {
$param1 = new Node\Param('test1');
$param2 = new Node\Param('test2');
$param3 = new Node\Param('test3');
$param1 = new Node\Param(new Variable('test1'));
$param2 = new Node\Param(new Variable('test2'));
$param3 = new Node\Param(new Variable('test3'));
$node = $this->createMethodBuilder('test')
->addParam($param1)
->addParams(array($param2, $param3))
->addParams([$param2, $param3])
->getNode()
;
$this->assertEquals(
new Stmt\ClassMethod('test', array(
'params' => array($param1, $param2, $param3)
)),
new Stmt\ClassMethod('test', [
'params' => [$param1, $param2, $param3]
]),
$node
);
}
@@ -99,14 +101,18 @@ class MethodTest extends \PHPUnit_Framework_TestCase
$node = $this->createMethodBuilder('test')
->addStmt($stmt1)
->addStmts(array($stmt2, $stmt3))
->addStmts([$stmt2, $stmt3])
->getNode()
;
$this->assertEquals(
new Stmt\ClassMethod('test', array(
'stmts' => array($stmt1, $stmt2, $stmt3)
)),
new Stmt\ClassMethod('test', [
'stmts' => [
new Stmt\Expression($stmt1),
new Stmt\Expression($stmt2),
new Stmt\Expression($stmt3),
]
]),
$node
);
}
@@ -115,18 +121,18 @@ class MethodTest extends \PHPUnit_Framework_TestCase
->setDocComment('/** Test */')
->getNode();
$this->assertEquals(new Stmt\ClassMethod('test', array(), array(
'comments' => array(new Comment\Doc('/** Test */'))
)), $node);
$this->assertEquals(new Stmt\ClassMethod('test', [], [
'comments' => [new Comment\Doc('/** Test */')]
]), $node);
}
public function testReturnType() {
$node = $this->createMethodBuilder('test')
->setReturnType('bool')
->getNode();
$this->assertEquals(new Stmt\ClassMethod('test', array(
$this->assertEquals(new Stmt\ClassMethod('test', [
'returnType' => 'bool'
), array()), $node);
], []), $node);
}
/**

View File

@@ -1,11 +1,13 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Builder;
use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Stmt;
use PHPUnit\Framework\TestCase;
class NamespaceTest extends \PHPUnit_Framework_TestCase
class NamespaceTest extends TestCase
{
protected function createNamespaceBuilder($fqn) {
return new Namespace_($fqn);
@@ -15,20 +17,24 @@ class NamespaceTest extends \PHPUnit_Framework_TestCase
$stmt1 = new Stmt\Class_('SomeClass');
$stmt2 = new Stmt\Interface_('SomeInterface');
$stmt3 = new Stmt\Function_('someFunction');
$docComment = new Doc('/** Test */');
$expected = new Stmt\Namespace_(
new Node\Name('Name\Space'),
array($stmt1, $stmt2, $stmt3)
[$stmt1, $stmt2, $stmt3],
['comments' => [$docComment]]
);
$node = $this->createNamespaceBuilder('Name\Space')
->addStmt($stmt1)
->addStmts(array($stmt2, $stmt3))
->addStmts([$stmt2, $stmt3])
->setDocComment($docComment)
->getNode()
;
$this->assertEquals($expected, $node);
$node = $this->createNamespaceBuilder(new Node\Name(array('Name', 'Space')))
->addStmts(array($stmt1, $stmt2))
$node = $this->createNamespaceBuilder(new Node\Name(['Name', 'Space']))
->setDocComment($docComment)
->addStmts([$stmt1, $stmt2])
->addStmt($stmt3)
->getNode()
;

View File

@@ -1,12 +1,13 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Builder;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Scalar;
use PHPUnit\Framework\TestCase;
class ParamTest extends \PHPUnit_Framework_TestCase
class ParamTest extends TestCase
{
public function createParamBuilder($name) {
return new Param($name);
@@ -25,42 +26,42 @@ class ParamTest extends \PHPUnit_Framework_TestCase
}
public function provideTestDefaultValues() {
return array(
array(
return [
[
null,
new Expr\ConstFetch(new Node\Name('null'))
),
array(
],
[
true,
new Expr\ConstFetch(new Node\Name('true'))
),
array(
],
[
false,
new Expr\ConstFetch(new Node\Name('false'))
),
array(
],
[
31415,
new Scalar\LNumber(31415)
),
array(
],
[
3.1415,
new Scalar\DNumber(3.1415)
),
array(
],
[
'Hallo World',
new Scalar\String_('Hallo World')
),
array(
array(1, 2, 3),
new Expr\Array_(array(
],
[
[1, 2, 3],
new Expr\Array_([
new Expr\ArrayItem(new Scalar\LNumber(1)),
new Expr\ArrayItem(new Scalar\LNumber(2)),
new Expr\ArrayItem(new Scalar\LNumber(3)),
))
),
array(
array('foo' => 'bar', 'bar' => 'foo'),
new Expr\Array_(array(
])
],
[
['foo' => 'bar', 'bar' => 'foo'],
new Expr\Array_([
new Expr\ArrayItem(
new Scalar\String_('bar'),
new Scalar\String_('foo')
@@ -69,45 +70,79 @@ class ParamTest extends \PHPUnit_Framework_TestCase
new Scalar\String_('foo'),
new Scalar\String_('bar')
),
))
),
array(
])
],
[
new Scalar\MagicConst\Dir,
new Scalar\MagicConst\Dir
)
);
]
];
}
public function testTypeHints() {
/**
* @dataProvider provideTestTypeHints
*/
public function testTypeHints($typeHint, $expectedType) {
$node = $this->createParamBuilder('test')
->setTypeHint('array')
->setTypeHint($typeHint)
->getNode()
;
$type = $node->type;
$this->assertEquals(
new Node\Param('test', null, 'array'),
$node
);
/* Manually implement comparison to avoid __toString stupidity */
if ($expectedType instanceof Node\NullableType) {
$this->assertInstanceOf(get_class($expectedType), $type);
$expectedType = $expectedType->type;
$type = $type->type;
}
$node = $this->createParamBuilder('test')
->setTypeHint('callable')
->getNode()
;
$this->assertInstanceOf(get_class($expectedType), $type);
$this->assertEquals($expectedType, $type);
}
$this->assertEquals(
new Node\Param('test', null, 'callable'),
$node
);
public function provideTestTypeHints() {
return [
['array', new Node\Identifier('array')],
['callable', new Node\Identifier('callable')],
['bool', new Node\Identifier('bool')],
['int', new Node\Identifier('int')],
['float', new Node\Identifier('float')],
['string', new Node\Identifier('string')],
['iterable', new Node\Identifier('iterable')],
['object', new Node\Identifier('object')],
['Array', new Node\Identifier('array')],
['CALLABLE', new Node\Identifier('callable')],
['Some\Class', new Node\Name('Some\Class')],
['\Foo', new Node\Name\FullyQualified('Foo')],
['self', new Node\Name('self')],
['?array', new Node\NullableType(new Node\Identifier('array'))],
['?Some\Class', new Node\NullableType(new Node\Name('Some\Class'))],
[new Node\Name('Some\Class'), new Node\Name('Some\Class')],
[
new Node\NullableType(new Node\Identifier('int')),
new Node\NullableType(new Node\Identifier('int'))
],
[
new Node\NullableType(new Node\Name('Some\Class')),
new Node\NullableType(new Node\Name('Some\Class'))
],
];
}
$node = $this->createParamBuilder('test')
->setTypeHint('Some\Class')
->getNode()
;
/**
* @expectedException \LogicException
* @expectedExceptionMessage Parameter type cannot be void
*/
public function testVoidTypeError() {
$this->createParamBuilder('test')->setTypeHint('void');
}
$this->assertEquals(
new Node\Param('test', null, new Node\Name('Some\Class')),
$node
);
/**
* @expectedException \LogicException
* @expectedExceptionMessage Type must be a string, or an instance of Name, Identifier or NullableType
*/
public function testInvalidTypeError() {
$this->createParamBuilder('test')->setTypeHint(new \stdClass);
}
public function testByRef() {
@@ -117,7 +152,19 @@ class ParamTest extends \PHPUnit_Framework_TestCase
;
$this->assertEquals(
new Node\Param('test', null, null, true),
new Node\Param(new Expr\Variable('test'), null, null, true),
$node
);
}
public function testVariadic() {
$node = $this->createParamBuilder('test')
->makeVariadic()
->getNode()
;
$this->assertEquals(
new Node\Param(new Expr\Variable('test'), null, null, false, true),
$node
);
}

View File

@@ -1,14 +1,15 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Builder;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\Node\Expr;
use PhpParser\Node\Scalar;
use PhpParser\Comment;
use PhpParser\Node\Expr;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar;
use PhpParser\Node\Stmt;
use PHPUnit\Framework\TestCase;
class PropertyTest extends \PHPUnit_Framework_TestCase
class PropertyTest extends TestCase
{
public function createPropertyBuilder($name) {
return new Property($name);
@@ -25,9 +26,9 @@ class PropertyTest extends \PHPUnit_Framework_TestCase
new Stmt\Property(
Stmt\Class_::MODIFIER_PRIVATE
| Stmt\Class_::MODIFIER_STATIC,
array(
[
new Stmt\PropertyProperty('test')
)
]
),
$node
);
@@ -40,9 +41,9 @@ class PropertyTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(
new Stmt\Property(
Stmt\Class_::MODIFIER_PROTECTED,
array(
[
new Stmt\PropertyProperty('test')
)
]
),
$node
);
@@ -55,9 +56,9 @@ class PropertyTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(
new Stmt\Property(
Stmt\Class_::MODIFIER_PUBLIC,
array(
[
new Stmt\PropertyProperty('test')
)
]
),
$node
);
@@ -70,12 +71,12 @@ class PropertyTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(new Stmt\Property(
Stmt\Class_::MODIFIER_PUBLIC,
array(
[
new Stmt\PropertyProperty('test')
),
array(
'comments' => array(new Comment\Doc('/** Test */'))
)
],
[
'comments' => [new Comment\Doc('/** Test */')]
]
), $node);
}
@@ -92,42 +93,42 @@ class PropertyTest extends \PHPUnit_Framework_TestCase
}
public function provideTestDefaultValues() {
return array(
array(
return [
[
null,
new Expr\ConstFetch(new Name('null'))
),
array(
],
[
true,
new Expr\ConstFetch(new Name('true'))
),
array(
],
[
false,
new Expr\ConstFetch(new Name('false'))
),
array(
],
[
31415,
new Scalar\LNumber(31415)
),
array(
],
[
3.1415,
new Scalar\DNumber(3.1415)
),
array(
],
[
'Hallo World',
new Scalar\String_('Hallo World')
),
array(
array(1, 2, 3),
new Expr\Array_(array(
],
[
[1, 2, 3],
new Expr\Array_([
new Expr\ArrayItem(new Scalar\LNumber(1)),
new Expr\ArrayItem(new Scalar\LNumber(2)),
new Expr\ArrayItem(new Scalar\LNumber(3)),
))
),
array(
array('foo' => 'bar', 'bar' => 'foo'),
new Expr\Array_(array(
])
],
[
['foo' => 'bar', 'bar' => 'foo'],
new Expr\Array_([
new Expr\ArrayItem(
new Scalar\String_('bar'),
new Scalar\String_('foo')
@@ -136,12 +137,12 @@ class PropertyTest extends \PHPUnit_Framework_TestCase
new Scalar\String_('foo'),
new Scalar\String_('bar')
),
))
),
array(
])
],
[
new Scalar\MagicConst\Dir,
new Scalar\MagicConst\Dir
)
);
]
];
}
}

View File

@@ -1,13 +1,13 @@
<?php
<?php declare(strict_types=1);
namespace PhpParser\Builder;
use PhpParser\Comment;
use PhpParser\Node;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PHPUnit\Framework\TestCase;
class TraitTest extends \PHPUnit_Framework_TestCase
class TraitTest extends TestCase
{
protected function createTraitBuilder($class) {
return new Trait_($class);
@@ -17,22 +17,24 @@ class TraitTest extends \PHPUnit_Framework_TestCase
$method1 = new Stmt\ClassMethod('test1');
$method2 = new Stmt\ClassMethod('test2');
$method3 = new Stmt\ClassMethod('test3');
$prop = new Stmt\Property(Stmt\Class_::MODIFIER_PUBLIC, array(
$prop = new Stmt\Property(Stmt\Class_::MODIFIER_PUBLIC, [
new Stmt\PropertyProperty('test')
));
]);
$use = new Stmt\TraitUse([new Name('OtherTrait')]);
$trait = $this->createTraitBuilder('TestTrait')
->setDocComment('/** Nice trait */')
->addStmt($method1)
->addStmts(array($method2, $method3))
->addStmts([$method2, $method3])
->addStmt($prop)
->addStmt($use)
->getNode();
$this->assertEquals(new Stmt\Trait_('TestTrait', array(
$prop, $method1, $method2, $method3
), array(
'comments' => array(
$this->assertEquals(new Stmt\Trait_('TestTrait', [
'stmts' => [$use, $prop, $method1, $method2, $method3]
], [
'comments' => [
new Comment\Doc('/** Nice trait */')
)
)), $trait);
]
]), $trait);
}
/**
@@ -41,7 +43,7 @@ class TraitTest extends \PHPUnit_Framework_TestCase
*/
public function testInvalidStmtError() {
$this->createTraitBuilder('Test')
->addStmt(new Stmt\Echo_(array()))
->addStmt(new Stmt\Echo_([]))
;
}
}

View File

@@ -1,10 +1,11 @@
<?php
<?php declare(strict_types=1);
use PhpParser\Builder;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PHPUnit\Framework\TestCase;
class UseTest extends \PHPUnit_Framework_TestCase
class UseTest extends TestCase
{
protected function createUseBuilder($name, $type = Stmt\Use_::TYPE_NORMAL) {
return new Builder\Use_($name, $type);
@@ -12,24 +13,18 @@ class UseTest extends \PHPUnit_Framework_TestCase
public function testCreation() {
$node = $this->createUseBuilder('Foo\Bar')->getNode();
$this->assertEquals(new Stmt\Use_(array(
new Stmt\UseUse(new Name('Foo\Bar'), 'Bar')
)), $node);
$this->assertEquals(new Stmt\Use_([
new Stmt\UseUse(new Name('Foo\Bar'), null)
]), $node);
$node = $this->createUseBuilder(new Name('Foo\Bar'))->as('XYZ')->getNode();
$this->assertEquals(new Stmt\Use_(array(
$this->assertEquals(new Stmt\Use_([
new Stmt\UseUse(new Name('Foo\Bar'), 'XYZ')
)), $node);
]), $node);
$node = $this->createUseBuilder('foo\bar', Stmt\Use_::TYPE_FUNCTION)->as('foo')->getNode();
$this->assertEquals(new Stmt\Use_(array(
$this->assertEquals(new Stmt\Use_([
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();
], Stmt\Use_::TYPE_FUNCTION), $node);
}
}