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

Function TestPrintStmtClassMethod

printer/pretty_printer_test.go:2451–2488  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2449}
2450
2451func TestPrintStmtClassMethod(t *testing.T) {
2452 o := bytes.NewBufferString("")
2453
2454 p := printer.NewPrettyPrinter(o, " ")
2455 p.Print(&stmt.ClassMethod{
2456 Modifiers: []node.Node{&node.Identifier{Value: "public"}},
2457 ReturnsRef: true,
2458 MethodName: &node.Identifier{Value: "foo"},
2459 Params: []node.Node{
2460 &node.Parameter{
2461 ByRef: true,
2462 VariableType: &node.Nullable{Expr: &name.Name{Parts: []node.Node{&name.NamePart{Value: "int"}}}},
2463 Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
2464 DefaultValue: &expr.ConstFetch{Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}}},
2465 },
2466 &node.Parameter{
2467 Variadic: true,
2468 Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
2469 },
2470 },
2471 ReturnType: &name.Name{Parts: []node.Node{&name.NamePart{Value: "void"}}},
2472 Stmt: &stmt.StmtList{
2473 Stmts: []node.Node{
2474 &stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}},
2475 },
2476 },
2477 })
2478
2479 expected := `public function &foo(?int &$a = null, ...$b): void
2480{
2481 $a;
2482}`
2483 actual := o.String()
2484
2485 if expected != actual {
2486 t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
2487 }
2488}
2489func TestPrintStmtAbstractClassMethod(t *testing.T) {
2490 o := bytes.NewBufferString("")
2491

Callers

nothing calls this directly

Calls 3

PrintMethod · 0.95
NewPrettyPrinterFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…