1
0
mirror of https://github.com/danog/PHP-Parser.git synced 2024-11-26 20:04:48 +01:00

Add test coverage for all nodes

This commit is contained in:
nikic 2011-11-27 11:20:35 +01:00
parent 03a0449b1a
commit 21dc9b32f4
49 changed files with 2663 additions and 8 deletions

View File

@ -22,14 +22,21 @@ class PHPParser_Tests_codeTest extends PHPUnit_Framework_TestCase
$it = new RecursiveDirectoryIterator(dirname(__FILE__) . '/../../code');
$it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::LEAVES_ONLY);
$it = new RegexIterator($it, '~\.test$~');
if (version_compare(PHP_VERSION, '5.4.0RC1', '>=')) {
$it = new RegexIterator($it, '~\.test(-5\.4)?$~');
} else {
$it = new RegexIterator($it, '~\.test$~');
}
foreach ($it as $file) {
// read file
$fileContents = file_get_contents($file);
// evaluate @@{expr}@@ expressions
$fileContents = preg_replace('/@@\{(.*?)\}@@/e', '$1', $fileContents);
// parse sections
$tests[] = array_map('trim', explode('-----', $fileContents));
}

View File

@ -0,0 +1,133 @@
Array definitions
-----
<?php
array();
array(1, 2, 3);
array('a' => 'b');
array('a' => 'b', 'c');
array('a' => &$b);
[];
[1, 2, 3];
['a' => 'b'];
-----
array(
0: Expr_Array(
items: array(
)
)
1: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 2
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 3
)
byRef: false
)
)
)
2: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
value: Scalar_String(
value: b
)
byRef: false
)
)
)
3: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
value: Scalar_String(
value: b
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_String(
value: c
)
byRef: false
)
)
)
4: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
value: Expr_Variable(
name: b
)
byRef: true
)
)
)
5: Expr_Array(
items: array(
)
)
6: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 2
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 3
)
byRef: false
)
)
)
7: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
value: Scalar_String(
value: b
)
byRef: false
)
)
)
)

217
test/code/expr/assign.test Normal file
View File

@ -0,0 +1,217 @@
Assignments
-----
<?php
// simple assign
$a = $b;
// combined assign
$a &= $b;
$a |= $b;
$a ^= $b;
$a .= $b;
$a /= $b;
$a -= $b;
$a %= $b;
$a *= $b;
$a += $b;
$a <<= $b;
$a >>= $b;
// by ref assign
$a =& $b;
$a =& new B;
// list() assign
list($a) = $b;
list($a, , $b) = $c;
list($a, list(, $c), $d) = $e;
// inc/dec
++$a;
$a++;
--$a;
$a--;
-----
array(
0: Expr_Assign(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
1: Expr_AssignBitwiseAnd(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
2: Expr_AssignBitwiseOr(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
3: Expr_AssignBitwiseXor(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
4: Expr_AssignConcat(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
5: Expr_AssignDiv(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
6: Expr_AssignMinus(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
7: Expr_AssignMod(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
8: Expr_AssignMul(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
9: Expr_AssignPlus(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
10: Expr_AssignShiftLeft(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
11: Expr_AssignShiftRight(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
12: Expr_AssignRef(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
13: Expr_Assign(
var: Expr_Variable(
name: a
)
expr: Expr_New(
class: Name(
parts: array(
0: B
)
)
args: array(
)
)
)
14: Expr_AssignList(
vars: array(
0: Expr_Variable(
name: a
)
)
expr: Expr_Variable(
name: b
)
)
15: Expr_AssignList(
vars: array(
0: Expr_Variable(
name: a
)
1: null
2: Expr_Variable(
name: b
)
)
expr: Expr_Variable(
name: c
)
)
16: Expr_AssignList(
vars: array(
0: Expr_Variable(
name: a
)
1: array(
0: null
1: Expr_Variable(
name: c
)
)
2: Expr_Variable(
name: d
)
)
expr: Expr_Variable(
name: e
)
)
17: Expr_PreInc(
var: Expr_Variable(
name: a
)
)
18: Expr_PostInc(
var: Expr_Variable(
name: a
)
)
19: Expr_PreDec(
var: Expr_Variable(
name: a
)
)
20: Expr_PostDec(
var: Expr_Variable(
name: a
)
)
)

72
test/code/expr/cast.test Normal file
View File

@ -0,0 +1,72 @@
Casts
-----
<?php
(array) $a;
(bool) $a;
(boolean) $a;
(real) $a;
(double) $a;
(float) $a;
(int) $a;
(integer) $a;
(object) $a;
(string) $a;
(unset) $a;
-----
array(
0: Expr_Cast_Array(
expr: Expr_Variable(
name: a
)
)
1: Expr_Cast_Bool(
expr: Expr_Variable(
name: a
)
)
2: Expr_Cast_Bool(
expr: Expr_Variable(
name: a
)
)
3: Expr_Cast_Double(
expr: Expr_Variable(
name: a
)
)
4: Expr_Cast_Double(
expr: Expr_Variable(
name: a
)
)
5: Expr_Cast_Double(
expr: Expr_Variable(
name: a
)
)
6: Expr_Cast_Int(
expr: Expr_Variable(
name: a
)
)
7: Expr_Cast_Int(
expr: Expr_Variable(
name: a
)
)
8: Expr_Cast_Object(
expr: Expr_Variable(
name: a
)
)
9: Expr_Cast_String(
expr: Expr_Variable(
name: a
)
)
10: Expr_Cast_Unset(
expr: Expr_Variable(
name: a
)
)
)

View File

@ -0,0 +1,94 @@
Closures
-----
<?php
function($a) { $a; };
function($a) use($b) {};
function() use($a, &$b) {};
function &($a) {};
static function() {};
-----
array(
0: Expr_Closure(
static: false
byRef: false
params: array(
0: Param(
name: a
default: null
type: null
byRef: false
)
)
uses: array(
)
stmts: array(
0: Expr_Variable(
name: a
)
)
)
1: Expr_Closure(
static: false
byRef: false
params: array(
0: Param(
name: a
default: null
type: null
byRef: false
)
)
uses: array(
0: Expr_ClosureUse(
var: b
byRef: false
)
)
stmts: array(
)
)
2: Expr_Closure(
static: false
byRef: false
params: array(
)
uses: array(
0: Expr_ClosureUse(
var: a
byRef: false
)
1: Expr_ClosureUse(
var: b
byRef: true
)
)
stmts: array(
)
)
3: Expr_Closure(
static: false
byRef: true
params: array(
0: Param(
name: a
default: null
type: null
byRef: false
)
)
uses: array(
)
stmts: array(
)
)
4: Expr_Closure(
static: true
byRef: false
params: array(
)
uses: array(
)
stmts: array(
)
)
)

View File

@ -0,0 +1,98 @@
Comparison operators
-----
<?php
$a < $b;
$a <= $b;
$a > $b;
$a >= $b;
$a == $b;
$a === $b;
$a != $b;
$a !== $b;
$a instanceof B;
$a instanceof $b;
-----
array(
0: Expr_Smaller(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
1: Expr_SmallerOrEqual(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
2: Expr_Greater(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
3: Expr_GreaterOrEqual(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
4: Expr_Equal(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
5: Expr_Identical(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
6: Expr_NotEqual(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
7: Expr_NotIdentical(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
8: Expr_Instanceof(
expr: Expr_Variable(
name: a
)
class: Name(
parts: array(
0: B
)
)
)
9: Expr_Instanceof(
expr: Expr_Variable(
name: a
)
class: Expr_Variable(
name: b
)
)
)

View File

@ -0,0 +1,12 @@
Error suppression
-----
<?php
@$a;
-----
array(
0: Expr_ErrorSuppress(
expr: Expr_Variable(
name: a
)
)
)

34
test/code/expr/exit.test Normal file
View File

@ -0,0 +1,34 @@
Exit
-----
<?php
exit;
exit();
exit('Die!');
die;
die();
die('Exit!');
-----
array(
0: Expr_Exit(
expr: null
)
1: Expr_Exit(
expr: null
)
2: Expr_Exit(
expr: Scalar_String(
value: Die!
)
)
3: Expr_Exit(
expr: null
)
4: Expr_Exit(
expr: null
)
5: Expr_Exit(
expr: Scalar_String(
value: Exit!
)
)
)

View File

@ -0,0 +1,40 @@
Include and eval
-----
<?php
include 'A.php';
include_once 'A.php';
require 'A.php';
require_once 'A.php';
eval('A');
-----
array(
0: Expr_Include(
expr: Scalar_String(
value: A.php
)
type: 1
)
1: Expr_Include(
expr: Scalar_String(
value: A.php
)
type: 2
)
2: Expr_Include(
expr: Scalar_String(
value: A.php
)
type: 3
)
3: Expr_Include(
expr: Scalar_String(
value: A.php
)
type: 4
)
4: Expr_Eval(
expr: Scalar_String(
value: A
)
)
)

View File

@ -0,0 +1,35 @@
isset() and empty()
-----
<?php
isset($a);
isset($a, $b, $c);
empty($a);
-----
array(
0: Expr_Isset(
vars: array(
0: Expr_Variable(
name: a
)
)
)
1: Expr_Isset(
vars: array(
0: Expr_Variable(
name: a
)
1: Expr_Variable(
name: b
)
2: Expr_Variable(
name: c
)
)
)
2: Expr_Empty(
var: Expr_Variable(
name: a
)
)
)

138
test/code/expr/logic.test Normal file
View File

@ -0,0 +1,138 @@
Logical operators
-----
<?php
// boolean ops
$a && $b;
$a || $b;
!$a;
!!$a;
// logical ops
$a and $b;
$a or $b;
$a xor $b;
// precedence
$a && $b || $c && $d;
$a && ($b || $c) && $d;
$a = $b || $c;
$a = $b or $c;
-----
array(
0: Expr_BooleanAnd(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
1: Expr_BooleanOr(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
2: Expr_BooleanNot(
expr: Expr_Variable(
name: a
)
)
3: Expr_BooleanNot(
expr: Expr_BooleanNot(
expr: Expr_Variable(
name: a
)
)
)
4: Expr_LogicalAnd(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
5: Expr_LogicalOr(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
6: Expr_LogicalXor(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
7: Expr_BooleanOr(
left: Expr_BooleanAnd(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
right: Expr_BooleanAnd(
left: Expr_Variable(
name: c
)
right: Expr_Variable(
name: d
)
)
)
8: Expr_BooleanAnd(
left: Expr_BooleanAnd(
left: Expr_Variable(
name: a
)
right: Expr_BooleanOr(
left: Expr_Variable(
name: b
)
right: Expr_Variable(
name: c
)
)
)
right: Expr_Variable(
name: d
)
)
9: Expr_Assign(
var: Expr_Variable(
name: a
)
expr: Expr_BooleanOr(
left: Expr_Variable(
name: b
)
right: Expr_Variable(
name: c
)
)
)
10: Expr_LogicalOr(
left: Expr_Assign(
var: Expr_Variable(
name: a
)
expr: Expr_Variable(
name: b
)
)
right: Expr_Variable(
name: c
)
)
)

187
test/code/expr/math.test Normal file
View File

@ -0,0 +1,187 @@
Mathematical operators
-----
<?php
// unary ops
~$a;
+$a;
-$a;
// binary ops
$a & $b;
$a | $b;
$a ^ $b;
$a . $b;
$a / $b;
$a - $b;
$a % $b;
$a * $b;
$a + $b;
$a << $b;
$a >> $b;
// associativity
$a * $b * $c;
$a * ($b * $c);
// precedence
$a + $b * $c;
($a + $b) * $c;
-----
array(
0: Expr_BitwiseNot(
expr: Expr_Variable(
name: a
)
)
1: Expr_UnaryPlus(
expr: Expr_Variable(
name: a
)
)
2: Expr_UnaryMinus(
expr: Expr_Variable(
name: a
)
)
3: Expr_BitwiseAnd(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
4: Expr_BitwiseOr(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
5: Expr_BitwiseXor(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
6: Expr_Concat(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
7: Expr_Div(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
8: Expr_Minus(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
9: Expr_Mod(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
10: Expr_Mul(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
11: Expr_Plus(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
12: Expr_ShiftLeft(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
13: Expr_ShiftRight(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
14: Expr_Mul(
left: Expr_Mul(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
right: Expr_Variable(
name: c
)
)
15: Expr_Mul(
left: Expr_Variable(
name: a
)
right: Expr_Mul(
left: Expr_Variable(
name: b
)
right: Expr_Variable(
name: c
)
)
)
16: Expr_Plus(
left: Expr_Variable(
name: a
)
right: Expr_Mul(
left: Expr_Variable(
name: b
)
right: Expr_Variable(
name: c
)
)
)
17: Expr_Mul(
left: Expr_Plus(
left: Expr_Variable(
name: a
)
right: Expr_Variable(
name: b
)
)
right: Expr_Variable(
name: c
)
)
)

View File

@ -0,0 +1,54 @@
New and clone
-----
<?php
new A;
new A($b);
new $a($b);
clone $a;
-----
array(
0: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
)
)
1: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
0: Arg(
value: Expr_Variable(
name: b
)
byRef: false
)
)
)
2: Expr_New(
class: Expr_Variable(
name: a
)
args: array(
0: Arg(
value: Expr_Variable(
name: b
)
byRef: false
)
)
)
3: Expr_Clone(
expr: Expr_Variable(
name: a
)
)
)

12
test/code/expr/print.test Normal file
View File

@ -0,0 +1,12 @@
Print
-----
<?php
print $a;
-----
array(
0: Expr_Print(
expr: Expr_Variable(
name: a
)
)
)

View File

@ -0,0 +1,33 @@
Shell execution
-----
<?php
`test`;
`test $A`;
`test \``;
`test \"`;
-----
array(
0: Expr_ShellExec(
parts: array(
0: test
)
)
1: Expr_ShellExec(
parts: array(
0: test
1: Expr_Variable(
name: A
)
)
)
2: Expr_ShellExec(
parts: array(
0: test `
)
)
3: Expr_ShellExec(
parts: array(
0: test \"
)
)
)

View File

@ -0,0 +1,95 @@
Simple fetches (array, property, constant) and calls
-----
<?php
// simple calls
a();
$a->b();
A::b();
// simple properties
$a->b;
A::$b;
// simple array access
$a[$b];
$a{$b};
// simple constants
A;
A::B;
-----
array(
0: Expr_FuncCall(
name: Name(
parts: array(
0: a
)
)
args: array(
)
)
1: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: b
args: array(
)
)
2: Expr_StaticCall(
class: Name(
parts: array(
0: A
)
)
name: b
args: array(
)
)
3: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
4: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: b
)
5: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Expr_Variable(
name: b
)
)
6: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Expr_Variable(
name: b
)
)
7: Expr_ConstFetch(
name: Name(
parts: array(
0: A
)
)
)
8: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: B
)
)

View File

@ -0,0 +1,72 @@
Ternary operator
-----
<?php
// ternary
$a ? $b : $c;
$a ?: $c;
// precedence
$a ? $b : $c ? $d : $e;
$a ? $b : ($c ? $d : $e);
-----
array(
0: Expr_Ternary(
cond: Expr_Variable(
name: a
)
if: Expr_Variable(
name: b
)
else: Expr_Variable(
name: c
)
)
1: Expr_Ternary(
cond: Expr_Variable(
name: a
)
if: null
else: Expr_Variable(
name: c
)
)
2: Expr_Ternary(
cond: Expr_Ternary(
cond: Expr_Variable(
name: a
)
if: Expr_Variable(
name: b
)
else: Expr_Variable(
name: c
)
)
if: Expr_Variable(
name: d
)
else: Expr_Variable(
name: e
)
)
3: Expr_Ternary(
cond: Expr_Variable(
name: a
)
if: Expr_Variable(
name: b
)
else: Expr_Ternary(
cond: Expr_Variable(
name: c
)
if: Expr_Variable(
name: d
)
else: Expr_Variable(
name: e
)
)
)
)

View File

@ -1,6 +1,7 @@
Constant string syntaxes
-----
<?php
'';
"";
b'';

View File

@ -1,6 +1,7 @@
Encapsed strings
-----
<?php
"$A";
"$A->B";
"$A[B]";

View File

@ -1,6 +1,7 @@
Different float syntaxes
-----
<?php
0.0;
0.;
.0;

View File

@ -1,6 +1,7 @@
Different integer syntaxes
-----
<?php
0;
1;
@@{ PHP_INT_MAX }@@;
@ -10,7 +11,6 @@ Different integer syntaxes
0XfFf;
0777;
0787;
0b111000111000;
-----
array(
0: Scalar_LNumber(
@ -40,7 +40,4 @@ array(
8: Scalar_LNumber(
value: 7
)
9: Scalar_LNumber(
value: 3640
)
)

View File

@ -0,0 +1,11 @@
Different integer syntaxes
-----
<?php
0b111000111000;
-----
array(
0: Scalar_LNumber(
value: 3640
)
)

View File

@ -1,6 +1,7 @@
Magic constants
-----
<?php
__CLASS__;
__DIR__;
__FILE__;
@ -8,7 +9,6 @@ __FUNCTION__;
__LINE__;
__METHOD__;
__NAMESPACE__;
__TRAIT__;
-----
array(
0: Scalar_ClassConst(
@ -25,6 +25,4 @@ array(
)
6: Scalar_NSConst(
)
7: Scalar_TraitConst(
)
)

View File

@ -0,0 +1,10 @@
Magic constants
-----
<?php
__TRAIT__;
-----
array(
0: Scalar_TraitConst(
)
)

View File

@ -0,0 +1,37 @@
Abstract class
-----
<?php
abstract class A {
public function a() {}
abstract public function b();
}
-----
array(
0: Stmt_Class(
type: 16
extends: null
implements: array(
)
stmts: array(
0: Stmt_ClassMethod(
type: 1
byRef: false
params: array(
)
stmts: array(
)
name: a
)
1: Stmt_ClassMethod(
type: 17
byRef: false
params: array(
)
stmts: null
name: b
)
)
name: A
)
)

View File

@ -0,0 +1,35 @@
Interface
-----
<?php
interface A extends C, D {
public function a();
}
-----
array(
0: Stmt_Interface(
extends: array(
0: Name(
parts: array(
0: C
)
)
1: Name(
parts: array(
0: D
)
)
)
stmts: array(
0: Stmt_ClassMethod(
type: 1
byRef: false
params: array(
)
stmts: null
name: a
)
)
name: A
)
)

View File

@ -0,0 +1,139 @@
Class declaration
-----
<?php
class A extends B implements C, D {
const A = 'B', C = 'D';
public $a = 'b', $c = 'd';
protected $e;
private $f;
public function a() {}
public static function b() {}
public final function c() {}
protected function d() {}
private function e() {}
}
-----
array(
0: Stmt_Class(
type: 0
extends: Name(
parts: array(
0: B
)
)
implements: array(
0: Name(
parts: array(
0: C
)
)
1: Name(
parts: array(
0: D
)
)
)
stmts: array(
0: Stmt_ClassConst(
consts: array(
0: Const(
name: A
value: Scalar_String(
value: B
)
)
1: Const(
name: C
value: Scalar_String(
value: D
)
)
)
)
1: Stmt_Property(
type: 1
props: array(
0: Stmt_PropertyProperty(
name: a
default: Scalar_String(
value: b
)
)
1: Stmt_PropertyProperty(
name: c
default: Scalar_String(
value: d
)
)
)
)
2: Stmt_Property(
type: 2
props: array(
0: Stmt_PropertyProperty(
name: e
default: null
)
)
)
3: Stmt_Property(
type: 4
props: array(
0: Stmt_PropertyProperty(
name: f
default: null
)
)
)
4: Stmt_ClassMethod(
type: 1
byRef: false
params: array(
)
stmts: array(
)
name: a
)
5: Stmt_ClassMethod(
type: 9
byRef: false
params: array(
)
stmts: array(
)
name: b
)
6: Stmt_ClassMethod(
type: 33
byRef: false
params: array(
)
stmts: array(
)
name: c
)
7: Stmt_ClassMethod(
type: 2
byRef: false
params: array(
)
stmts: array(
)
name: d
)
8: Stmt_ClassMethod(
type: 4
byRef: false
params: array(
)
stmts: array(
)
name: e
)
)
name: A
)
)

View File

@ -0,0 +1,159 @@
Traits
-----
<?php
trait A {
public function a() {}
}
class B {
use C;
use D {
a as protected b;
c as d;
e as private;
}
use E, F, G {
E::a insteadof F, G;
E::b as protected c;
E::d as e;
E::f as private;
}
}
-----
array(
0: Stmt_Trait(
name: A
stmts: array(
0: Stmt_ClassMethod(
type: 1
byRef: false
params: array(
)
stmts: array(
)
name: a
)
)
)
1: Stmt_Class(
type: 0
extends: null
implements: array(
)
stmts: array(
0: Stmt_TraitUse(
traits: array(
0: Name(
parts: array(
0: C
)
)
)
adaptations: array(
)
)
1: Stmt_TraitUse(
traits: array(
0: Name(
parts: array(
0: D
)
)
)
adaptations: array(
0: Stmt_TraitUseAdaptation_Alias(
trait: null
method: a
newModifier: 2
newName: b
)
1: Stmt_TraitUseAdaptation_Alias(
trait: null
method: c
newModifier: null
newName: d
)
2: Stmt_TraitUseAdaptation_Alias(
trait: null
method: e
newModifier: 4
newName: null
)
)
)
2: Stmt_TraitUse(
traits: array(
0: Name(
parts: array(
0: E
)
)
1: Name(
parts: array(
0: F
)
)
2: Name(
parts: array(
0: G
)
)
)
adaptations: array(
0: Stmt_TraitUseAdaptation_Precedence(
trait: Name(
parts: array(
0: E
)
)
method: a
insteadof: array(
0: Name(
parts: array(
0: F
)
)
1: Name(
parts: array(
0: G
)
)
)
)
1: Stmt_TraitUseAdaptation_Alias(
trait: Name(
parts: array(
0: E
)
)
method: b
newModifier: 2
newName: c
)
2: Stmt_TraitUseAdaptation_Alias(
trait: Name(
parts: array(
0: E
)
)
method: d
newModifier: null
newName: e
)
3: Stmt_TraitUseAdaptation_Alias(
trait: Name(
parts: array(
0: E
)
)
method: f
newModifier: 4
newName: null
)
)
)
)
name: B
)
)

40
test/code/stmt/const.test Normal file
View File

@ -0,0 +1,40 @@
Global constants
-----
<?php
const A = 0, B = 1.0, C = 'A', D = E;
-----
array(
0: Stmt_Const(
consts: array(
0: Const(
name: A
value: Scalar_LNumber(
value: 0
)
)
1: Const(
name: B
value: Scalar_DNumber(
value: 1
)
)
2: Const(
name: C
value: Scalar_String(
value: A
)
)
3: Const(
name: D
value: Expr_ConstFetch(
name: Name(
parts: array(
0: E
)
)
)
)
)
)
)

View File

@ -0,0 +1,55 @@
Control flow statements
-----
<?php
break;
break 2;
continue;
continue 2;
return;
return $a;
throw $e;
label:
goto label;
-----
array(
0: Stmt_Break(
num: null
)
1: Stmt_Break(
num: Scalar_LNumber(
value: 2
)
)
2: Stmt_Continue(
num: null
)
3: Stmt_Continue(
num: Scalar_LNumber(
value: 2
)
)
4: Stmt_Return(
expr: null
)
5: Stmt_Return(
expr: Expr_Variable(
name: a
)
)
6: Stmt_Throw(
expr: Expr_Variable(
name: e
)
)
7: Stmt_Label(
name: label
)
8: Stmt_Goto(
name: label
)
)

View File

@ -0,0 +1,47 @@
Declare
-----
<?php
declare (A='B', C='D') {}
declare (A='B', C='D'):
enddeclare;
-----
array(
0: Stmt_Declare(
declares: array(
0: Stmt_DeclareDeclare(
key: A
value: Scalar_String(
value: B
)
)
1: Stmt_DeclareDeclare(
key: C
value: Scalar_String(
value: D
)
)
)
stmts: array(
)
)
1: Stmt_Declare(
declares: array(
0: Stmt_DeclareDeclare(
key: A
value: Scalar_String(
value: B
)
)
1: Stmt_DeclareDeclare(
key: C
value: Scalar_String(
value: D
)
)
)
stmts: array(
)
)
)

32
test/code/stmt/echo.test Normal file
View File

@ -0,0 +1,32 @@
Echo
-----
<?php
echo 'Hallo World!';
echo 'Hallo', ' ', 'World', '!';
-----
array(
0: Stmt_Echo(
exprs: array(
0: Scalar_String(
value: Hallo World!
)
)
)
1: Stmt_Echo(
exprs: array(
0: Scalar_String(
value: Hallo
)
1: Scalar_String(
value:
)
2: Scalar_String(
value: World
)
3: Scalar_String(
value: !
)
)
)
)

View File

@ -0,0 +1,73 @@
Function parameters
-----
<?php
function a($b, &$c, array $d, A $e, $f = 'g', H &$i = 'j') {}
function &a() {}
-----
array(
0: Stmt_Function(
byRef: false
params: array(
0: Param(
name: b
default: null
type: null
byRef: false
)
1: Param(
name: c
default: null
type: null
byRef: true
)
2: Param(
name: d
default: null
type: array
byRef: false
)
3: Param(
name: e
default: null
type: Name(
parts: array(
0: A
)
)
byRef: false
)
4: Param(
name: f
default: Scalar_String(
value: g
)
type: null
byRef: false
)
5: Param(
name: i
default: Scalar_String(
value: j
)
type: Name(
parts: array(
0: H
)
)
byRef: true
)
)
stmts: array(
)
name: a
)
1: Stmt_Function(
byRef: true
params: array(
)
stmts: array(
)
name: a
)
)

View File

@ -0,0 +1,43 @@
Special function variables
-----
<?php
function a() {
global $a, $b;
static $c, $d = 'e';
}
-----
array(
0: Stmt_Function(
byRef: false
params: array(
)
stmts: array(
0: Stmt_Global(
vars: array(
0: Expr_Variable(
name: a
)
1: Expr_Variable(
name: b
)
)
)
1: Stmt_Static(
vars: array(
0: Stmt_StaticVar(
name: c
default: null
)
1: Stmt_StaticVar(
name: d
default: Scalar_String(
value: e
)
)
)
)
)
name: a
)
)

View File

@ -0,0 +1,17 @@
__halt_compiler (1)
-----
<?php
$a;
__halt_compiler()
?>
Hallo World!
-----
array(
0: Expr_Variable(
name: a
)
1: Stmt_HaltCompiler(
remaining: Hallo World!
)
)

View File

@ -0,0 +1,15 @@
__halt_compiler (2)
-----
<?php
$a;
__halt_compiler();Hallo World!
-----
array(
0: Expr_Variable(
name: a
)
1: Stmt_HaltCompiler(
remaining: Hallo World!
)
)

71
test/code/stmt/if.test Normal file
View File

@ -0,0 +1,71 @@
If/Elseif/Else
-----
<?php
if ($a) {}
elseif ($b) {}
elseif ($c) {}
else {}
if ($a):
elseif ($b):
elseif ($c):
else :
endif;
-----
array(
0: Stmt_If(
stmts: array(
)
elseifs: array(
0: Stmt_ElseIf(
cond: Expr_Variable(
name: b
)
stmts: array(
)
)
1: Stmt_ElseIf(
cond: Expr_Variable(
name: c
)
stmts: array(
)
)
)
else: Stmt_Else(
stmts: array(
)
)
cond: Expr_Variable(
name: a
)
)
1: Stmt_If(
stmts: array(
)
elseifs: array(
0: Stmt_ElseIf(
cond: Expr_Variable(
name: b
)
stmts: array(
)
)
1: Stmt_ElseIf(
cond: Expr_Variable(
name: c
)
stmts: array(
)
)
)
else: Stmt_Else(
stmts: array(
)
)
cond: Expr_Variable(
name: a
)
)
)

View File

@ -0,0 +1,27 @@
Inline HTML
-----
<?php
$a;
?>
B
<?php
$c;
?>
<?php
$d;
-----
array(
0: Expr_Variable(
name: a
)
1: Stmt_InlineHTML(
value: B
)
2: Expr_Variable(
name: c
)
3: Expr_Variable(
name: d
)
)

View File

@ -0,0 +1,17 @@
Do loop
-----
<?php
do {
} while ($a);
-----
array(
0: Stmt_Do(
cond: Expr_Variable(
name: a
)
stmts: array(
)
)
)

View File

@ -0,0 +1,86 @@
For loop
-----
<?php
// "classical" loop
for ($i = 0; $i < $c; ++$i) {}
// multiple expressions
for (;$a,$b;) {}
// infinite loop
for (;;) {}
// alternative syntax
for (;;):
endfor;
-----
array(
0: Stmt_For(
init: array(
0: Expr_Assign(
var: Expr_Variable(
name: i
)
expr: Scalar_LNumber(
value: 0
)
)
)
cond: array(
0: Expr_Smaller(
left: Expr_Variable(
name: i
)
right: Expr_Variable(
name: c
)
)
)
loop: array(
0: Expr_PreInc(
var: Expr_Variable(
name: i
)
)
)
stmts: array(
)
)
1: Stmt_For(
init: array(
)
cond: array(
0: Expr_Variable(
name: a
)
1: Expr_Variable(
name: b
)
)
loop: array(
)
stmts: array(
)
)
2: Stmt_For(
init: array(
)
cond: array(
)
loop: array(
)
stmts: array(
)
)
3: Stmt_For(
init: array(
)
cond: array(
)
loop: array(
)
stmts: array(
)
)
)

View File

@ -0,0 +1,96 @@
Foreach loop
-----
<?php
// foreach on variable
foreach ($a as $b) {}
foreach ($a as &$b) {}
foreach ($a as $b => $c) {}
foreach ($a as $b => &$c) {}
// foreach on expression
foreach (array() as $b) {}
// alternative syntax
foreach ($a as $b):
endforeach;
-----
array(
0: Stmt_Foreach(
keyVar: null
byRef: false
stmts: array(
)
expr: Expr_Variable(
name: a
)
valueVar: Expr_Variable(
name: b
)
)
1: Stmt_Foreach(
keyVar: null
byRef: true
stmts: array(
)
expr: Expr_Variable(
name: a
)
valueVar: Expr_Variable(
name: b
)
)
2: Stmt_Foreach(
keyVar: Expr_Variable(
name: b
)
byRef: false
stmts: array(
)
expr: Expr_Variable(
name: a
)
valueVar: Expr_Variable(
name: c
)
)
3: Stmt_Foreach(
keyVar: Expr_Variable(
name: b
)
byRef: true
stmts: array(
)
expr: Expr_Variable(
name: a
)
valueVar: Expr_Variable(
name: c
)
)
4: Stmt_Foreach(
keyVar: null
byRef: false
stmts: array(
)
expr: Expr_Array(
items: array(
)
)
valueVar: Expr_Variable(
name: b
)
)
5: Stmt_Foreach(
keyVar: null
byRef: false
stmts: array(
)
expr: Expr_Variable(
name: a
)
valueVar: Expr_Variable(
name: b
)
)
)

View File

@ -0,0 +1,25 @@
While loop
-----
<?php
while ($a) {}
while ($a):
endwhile;
-----
array(
0: Stmt_While(
cond: Expr_Variable(
name: a
)
stmts: array(
)
)
1: Stmt_While(
cond: Expr_Variable(
name: a
)
stmts: array(
)
)
)

View File

@ -0,0 +1,57 @@
Aliases (use)
-----
<?php
use A\B;
use C\D as E;
use F\G as H, J;
-----
array(
0: Stmt_Use(
uses: array(
0: Stmt_UseUse(
name: Name(
parts: array(
0: A
1: B
)
)
alias: B
)
)
)
1: Stmt_Use(
uses: array(
0: Stmt_UseUse(
name: Name(
parts: array(
0: C
1: D
)
)
alias: E
)
)
)
2: Stmt_Use(
uses: array(
0: Stmt_UseUse(
name: Name(
parts: array(
0: F
1: G
)
)
alias: H
)
1: Stmt_UseUse(
name: Name(
parts: array(
0: J
)
)
alias: J
)
)
)
)

View File

@ -0,0 +1,42 @@
Braced namespaces
-----
<?php
namespace Foo\Bar {
foo;
}
namespace {
bar;
}
-----
array(
0: Stmt_Namespace(
name: Name(
parts: array(
0: Foo
1: Bar
)
)
stmts: array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: foo
)
)
)
)
)
1: Stmt_Namespace(
name: null
stmts: array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: bar
)
)
)
)
)
)

View File

@ -0,0 +1,42 @@
Different name types
-----
<?php
A;
A\B;
\A\B;
namespace\A\B;
-----
array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: A
)
)
)
1: Expr_ConstFetch(
name: Name(
parts: array(
0: A
1: B
)
)
)
2: Expr_ConstFetch(
name: Name_FullyQualified(
parts: array(
0: A
1: B
)
)
)
3: Expr_ConstFetch(
name: Name_Relative(
parts: array(
0: A
1: B
)
)
)
)

View File

@ -0,0 +1,45 @@
Semicolon style namespaces
-----
<?php
namespace Foo\Bar;
foo;
namespace Bar;
bar;
-----
array(
0: Stmt_Namespace(
name: Name(
parts: array(
0: Foo
1: Bar
)
)
stmts: array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: foo
)
)
)
)
)
1: Stmt_Namespace(
name: Name(
parts: array(
0: Bar
)
)
stmts: array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: bar
)
)
)
)
)
)

View File

@ -0,0 +1,38 @@
Switch
-----
<?php
switch ($a) {
case 0:
case 1;
default:
}
-----
array(
0: Stmt_Switch(
cond: Expr_Variable(
name: a
)
cases: array(
0: Stmt_Case(
stmts: array(
)
cond: Scalar_LNumber(
value: 0
)
)
1: Stmt_Case(
stmts: array(
)
cond: Scalar_LNumber(
value: 1
)
)
2: Stmt_Case(
stmts: array(
)
cond: null
)
)
)
)

View File

@ -0,0 +1,39 @@
Try/catch
-----
<?php
try {
} catch (A $b) {
} catch (B $c) {
}
-----
array(
0: Stmt_TryCatch(
stmts: array(
)
catches: array(
0: Stmt_Catch(
type: Name(
parts: array(
0: A
)
)
var: b
stmts: array(
)
)
1: Stmt_Catch(
type: Name(
parts: array(
0: B
)
)
var: c
stmts: array(
)
)
)
)
)

26
test/code/stmt/unset.test Normal file
View File

@ -0,0 +1,26 @@
Unset
-----
<?php
unset($a);
unset($b, $c);
-----
array(
0: Stmt_Unset(
vars: array(
0: Expr_Variable(
name: a
)
)
)
1: Stmt_Unset(
vars: array(
0: Expr_Variable(
name: b
)
1: Expr_Variable(
name: c
)
)
)
)