package languages import ( "testing" "github.com/zzet/gortex/internal/graph" ) func eloquentEdge(edges []*graph.Edge, model string) *graph.Edge { for _, e := range edges { if e.Kind != graph.EdgeCalls || e.Meta == nil { continue } if m, _ := e.Meta["eloquent_model"].(string); m == model { return e } } return nil } func hasCallTo(edges []*graph.Edge, to string) bool { for _, e := range edges { if e.Kind == graph.EdgeCalls && e.To == to { return true } } return false } func TestPHPEloquent_StaticFinderBindsModel(t *testing.T) { src := ` 'x']); } } ` res, err := NewPHPExtractor().Extract("c.php", []byte(src)) if err != nil { t.Fatal(err) } find := eloquentEdge(res.Edges, "User") if find == nil { t.Fatalf("User::find should bind to the User model") } if find.To != "unresolved::User" { t.Errorf("User::find To = %q (want unresolved::User, a model ref not a method)", find.To) } if !hasCallTo(res.Edges, "unresolved::User") { t.Errorf("expected a model ref to User") } if eloquentEdge(res.Edges, "Post") == nil { t.Errorf("Post::create should bind to the Post model") } } func TestPHPEloquent_NonModelStaticUnchanged(t *testing.T) { src := `