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

Function TestGoFileGenerator_Generate

internal/extgen/gofile_test.go:15–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestGoFileGenerator_Generate(t *testing.T) {
16 tmpDir := t.TempDir()
17
18 sourceContent := `package main
19
20import (
21 "fmt"
22 "strings"
23 "github.com/dunglas/frankenphp/internal/extensions/types"
24)
25
26//export_php: greet(name string): string
27func greet(name *go_string) *go_value {
28 return types.String("Hello " + CStringToGoString(name))
29}
30
31//export_php: calculate(a int, b int): int
32func calculate(a long, b long) *go_value {
33 result := a + b
34 return types.Int(result)
35}
36
37func internalHelper(data string) string {
38 return strings.ToUpper(data)
39}
40
41func anotherHelper() {
42 fmt.Println("Internal helper")
43}`
44
45 sourceFile := filepath.Join(tmpDir, "test.go")
46 require.NoError(t, os.WriteFile(sourceFile, []byte(sourceContent), 0644))
47
48 generator := &Generator{
49 BaseName: "test",
50 SourceFile: sourceFile,
51 BuildDir: tmpDir,
52 Functions: []phpFunction{
53 {
54 Name: "greet",
55 ReturnType: phpString,
56 GoFunction: `func greet(name *go_string) *go_value {
57 return types.String("Hello " + CStringToGoString(name))
58}`,
59 },
60 {
61 Name: "calculate",
62 ReturnType: phpInt,
63 GoFunction: `func calculate(a long, b long) *go_value {
64 result := a + b
65 return types.Int(result)
66}`,
67 },
68 },
69 }
70
71 goGen := GoFileGenerator{generator}
72 require.NoError(t, goGen.generate())

Callers

nothing calls this directly

Calls 4

generateMethod · 0.95
readFileFunction · 0.85

Tested by

no test coverage detected