MCPcopy Create free account
hub / github.com/z7zmey/php-parser / TestPrinterPrintStmtClassMethod

Function TestPrinterPrintStmtClassMethod

printer/printer_test.go:2926–2968  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2924}
2925
2926func TestPrinterPrintStmtClassMethod(t *testing.T) {
2927 o := bytes.NewBufferString("")
2928
2929 p := printer.NewPrinter(o)
2930 p.Print(&stmt.ClassMethod{
2931 Modifiers: []node.Node{&node.Identifier{Value: "public"}},
2932 ReturnsRef: true,
2933 MethodName: &node.Identifier{Value: "foo"},
2934 Params: []node.Node{
2935 &node.Parameter{
2936 ByRef: true,
2937 VariableType: &node.Nullable{Expr: &name.Name{Parts: []node.Node{&name.NamePart{Value: "int"}}}},
2938 Variable: &expr.Variable{
2939 VarName: &node.Identifier{Value: "a"},
2940 },
2941 DefaultValue: &expr.ConstFetch{Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}}},
2942 },
2943 &node.Parameter{
2944 Variadic: true,
2945 Variable: &expr.Variable{
2946 VarName: &node.Identifier{Value: "b"},
2947 },
2948 },
2949 },
2950 ReturnType: &name.Name{
2951 Parts: []node.Node{&name.NamePart{Value: "void"}},
2952 },
2953 Stmt: &stmt.StmtList{
2954 Stmts: []node.Node{
2955 &stmt.Expression{Expr: &expr.Variable{
2956 VarName: &node.Identifier{Value: "a"},
2957 }},
2958 },
2959 },
2960 })
2961
2962 expected := `public function &foo(?int&$a=null,...$b):void{$a;}`
2963 actual := o.String()
2964
2965 if expected != actual {
2966 t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
2967 }
2968}
2969
2970func TestPrinterPrintStmtAbstractClassMethod(t *testing.T) {
2971 o := bytes.NewBufferString("")

Callers

nothing calls this directly

Calls 3

PrintMethod · 0.95
NewPrinterFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…