MCPcopy Create free account
hub / github.com/php/frankenphp / TestGeneratorWithNamespace

Function TestGeneratorWithNamespace

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

Source from the content-addressed store, hash-verified

80}
81
82func TestGeneratorWithNamespace(t *testing.T) {
83 content := `package main
84
85//export_php:namespace My\Test\Namespace
86
87//export_php:function hello(): string
88func hello() string {
89 return "Hello from namespace!"
90}
91
92//export_php:constant TEST_CONSTANT = "test_value"
93const TEST_CONSTANT = "test_value"
94`
95
96 tmpfile, err := os.CreateTemp("", "test_generator_namespace_*.go")
97 require.NoError(t, err, "Failed to create temp file")
98 defer func() {
99 require.NoError(t, os.Remove(tmpfile.Name()), "Failed to remove temp file")
100 }()
101
102 _, err = tmpfile.Write([]byte(content))
103 require.NoError(t, err, "Failed to write to temp file")
104
105 err = tmpfile.Close()
106 require.NoError(t, err, "Failed to close temp file")
107
108 parser := SourceParser{}
109 namespace, err := parser.ParseNamespace(tmpfile.Name())
110 require.NoErrorf(t, err, "Failed to parse namespace from %s: %v", tmpfile.Name(), err)
111
112 require.Equal(t, `My\Test\Namespace`, namespace, "Namespace should match the parsed namespace")
113
114 generator := &Generator{
115 SourceFile: tmpfile.Name(),
116 Namespace: namespace,
117 }
118
119 require.Equal(t, `My\Test\Namespace`, generator.Namespace, "Namespace should match the parsed namespace")
120}

Callers

nothing calls this directly

Calls 4

ParseNamespaceMethod · 0.95
NameMethod · 0.80
CloseMethod · 0.80
WriteMethod · 0.45

Tested by

no test coverage detected