MCPcopy Index your code
hub / github.com/php/frankenphp / TestClassParser

Function TestClassParser

internal/extgen/classparser_test.go:12–120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestClassParser(t *testing.T) {
13 tests := []struct {
14 name string
15 input string
16 expect int
17 assert func(t *testing.T, classes []phpClass)
18 }{
19 {
20 name: "single class",
21 input: `package main
22
23//export_php:class User
24type UserStruct struct {
25 name string
26 Age int
27}`,
28 expect: 1,
29 assert: func(t *testing.T, classes []phpClass) {
30 c := classes[0]
31 assert.Equal(t, "User", c.Name)
32 assert.Equal(t, "UserStruct", c.GoStruct)
33 assert.Len(t, c.Properties, 2)
34 },
35 },
36 {
37 name: "multiple classes",
38 input: `package main
39
40//export_php:class User
41type UserStruct struct {
42 name string
43 Age int
44}
45
46//export_php:class Product
47type ProductStruct struct {
48 Title string
49 Price float64
50}`,
51 expect: 2,
52 },
53 {
54 name: "no php classes",
55 input: `package main
56
57type RegularStruct struct {
58 Data string
59}`,
60 expect: 0,
61 },
62 {
63 name: "class with nullable fields",
64 input: `package main
65
66//export_php:class OptionalData
67type OptionalStruct struct {
68 Required string
69 Optional *string

Callers

nothing calls this directly

Calls 1

parseMethod · 0.95

Tested by

no test coverage detected