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

Function TestCFileGenerationWithNamespace

internal/extgen/cfile_namespace_test.go:52–109  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func TestCFileGenerationWithNamespace(t *testing.T) {
53 content := `package main
54
55//export_php:namespace Go\Extension
56
57//export_php:class MySuperClass
58type MySuperClass struct{}
59
60//export_php:method MySuperClass test(): string
61func (m *MySuperClass) Test() string {
62 return "test"
63}
64`
65
66 tmpfile, err := os.CreateTemp("", "test_cfile_namespace_*.go")
67 require.NoError(t, err, "Failed to create temp file")
68 defer func() {
69 require.NoError(t, os.Remove(tmpfile.Name()), "Failed to remove temp file")
70 }()
71
72 _, err = tmpfile.Write([]byte(content))
73 require.NoError(t, err, "Failed to write to temp file")
74
75 err = tmpfile.Close()
76 require.NoError(t, err, "Failed to close temp file")
77
78 generator := &Generator{
79 BaseName: "test_extension",
80 SourceFile: tmpfile.Name(),
81 BuildDir: t.TempDir(),
82 Namespace: `Go\Extension`,
83 Classes: []phpClass{
84 {
85 Name: "MySuperClass",
86 GoStruct: "MySuperClass",
87 Methods: []phpClassMethod{
88 {
89 Name: "test",
90 PhpName: "test",
91 Signature: "test(): string",
92 ReturnType: "string",
93 ClassName: "MySuperClass",
94 },
95 },
96 },
97 },
98 }
99
100 cFileGen := cFileGenerator{generator: generator}
101 contentResult, err := cFileGen.getTemplateContent()
102 require.NoError(t, err, "error generating C file")
103
104 expectedCall := "register_class_Go_Extension_MySuperClass()"
105 require.Contains(t, contentResult, expectedCall, "C file should contain the standard function call")
106
107 oldCall := "register_class_MySuperClass()"
108 require.NotContains(t, contentResult, oldCall, "C file should not contain old non-namespaced call")
109}

Callers

nothing calls this directly

Calls 4

getTemplateContentMethod · 0.95
NameMethod · 0.80
CloseMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected