xref: /php-ast/tests/decl_normalization.phpt (revision 260678d4)
1--TEST--
2The class ast\Node\Decl no longer exists
3--FILE--
4<?php
5
6require __DIR__ . '/../util.php';
7
8$code = <<<'PHP'
9<?php
10/** A */
11class A {
12    /** B */
13    const B = 0;
14
15    /** c */
16    public $c;
17
18    /** d */
19    function d() {}
20}
21/** E */
22const E = 0;
23/** f */
24function f() {}
25/** g */
26function() {};
27PHP;
28
29$ast = ast\parse_code($code, $version=70);
30var_dump(array_map('get_class', $ast->children));
31echo ast_dump($ast) . "\n";
32$ast = ast\parse_code($code, $version=50);
33echo ast_dump($ast) . "\n";
34
35?>
36--EXPECTF--
37array(4) {
38  [0]=>
39  string(8) "ast\Node"
40  [1]=>
41  string(8) "ast\Node"
42  [2]=>
43  string(8) "ast\Node"
44  [3]=>
45  string(8) "ast\Node"
46}
47AST_STMT_LIST
48    0: AST_CLASS
49        name: "A"
50        docComment: "/** A */"
51        extends: null
52        implements: null
53        stmts: AST_STMT_LIST
54            0: AST_CLASS_CONST_DECL
55                flags: MODIFIER_PUBLIC (%d)
56                0: AST_CONST_ELEM
57                    name: "B"
58                    value: 0
59                    docComment: "/** B */"
60            1: AST_PROP_GROUP
61                flags: MODIFIER_PUBLIC (%d)
62                type: null
63                props: AST_PROP_DECL
64                    0: AST_PROP_ELEM
65                        name: "c"
66                        default: null
67                        docComment: "/** c */"
68            2: AST_METHOD
69                flags: MODIFIER_PUBLIC (%d)
70                name: "d"
71                docComment: "/** d */"
72                params: AST_PARAM_LIST
73                stmts: AST_STMT_LIST
74                returnType: null
75                __declId: 0
76        __declId: 1
77    1: AST_CONST_DECL
78        0: AST_CONST_ELEM
79            name: "E"
80            value: 0
81            docComment: "/** E */"
82    2: AST_FUNC_DECL
83        name: "f"
84        docComment: "/** f */"
85        params: AST_PARAM_LIST
86        stmts: AST_STMT_LIST
87        returnType: null
88        __declId: 2
89    3: AST_CLOSURE
90        name: "{closure}"
91        docComment: "/** g */"
92        params: AST_PARAM_LIST
93        uses: null
94        stmts: AST_STMT_LIST
95        returnType: null
96        __declId: 3
97
98Deprecated: ast\parse_code(): Version 50 is deprecated in %sdecl_normalization.php on line 29
99AST_STMT_LIST
100    0: AST_CLASS
101        name: "A"
102        docComment: "/** A */"
103        extends: null
104        implements: null
105        stmts: AST_STMT_LIST
106            0: AST_CLASS_CONST_DECL
107                flags: MODIFIER_PUBLIC (%d)
108                0: AST_CONST_ELEM
109                    name: "B"
110                    value: 0
111                    docComment: "/** B */"
112            1: AST_PROP_DECL
113                flags: MODIFIER_PUBLIC (%d)
114                0: AST_PROP_ELEM
115                    name: "c"
116                    default: null
117                    docComment: "/** c */"
118            2: AST_METHOD
119                flags: MODIFIER_PUBLIC (%d)
120                name: "d"
121                docComment: "/** d */"
122                params: AST_PARAM_LIST
123                uses: null
124                stmts: AST_STMT_LIST
125                returnType: null
126                __declId: 0
127        __declId: 1
128    1: AST_CONST_DECL
129        0: AST_CONST_ELEM
130            name: "E"
131            value: 0
132            docComment: "/** E */"
133    2: AST_FUNC_DECL
134        name: "f"
135        docComment: "/** f */"
136        params: AST_PARAM_LIST
137        uses: null
138        stmts: AST_STMT_LIST
139        returnType: null
140        __declId: 2
141    3: AST_CLOSURE
142        name: "{closure}"
143        docComment: "/** g */"
144        params: AST_PARAM_LIST
145        uses: null
146        stmts: AST_STMT_LIST
147        returnType: null
148        __declId: 3