(t *testing.T)
| 88 | } |
| 89 | |
| 90 | func TestGoFileGenerator_BuildContent(t *testing.T) { |
| 91 | tests := []struct { |
| 92 | name string |
| 93 | baseName string |
| 94 | sourceFile string |
| 95 | functions []phpFunction |
| 96 | classes []phpClass |
| 97 | contains []string |
| 98 | notContains []string |
| 99 | }{ |
| 100 | { |
| 101 | name: "simple extension", |
| 102 | baseName: "simple", |
| 103 | sourceFile: createTempSourceFile(t, `package main |
| 104 | |
| 105 | //export_php: test(): void |
| 106 | func test() { |
| 107 | // simple function |
| 108 | }`), |
| 109 | functions: []phpFunction{ |
| 110 | { |
| 111 | Name: "test", |
| 112 | ReturnType: phpVoid, |
| 113 | GoFunction: "func test() {\n\t// simple function\n}", |
| 114 | }, |
| 115 | }, |
| 116 | contains: []string{ |
| 117 | "package main", |
| 118 | `#include "simple.h"`, |
| 119 | `import "C"`, |
| 120 | "func init()", |
| 121 | "frankenphp.RegisterExtension(", |
| 122 | "//export go_test", |
| 123 | "func go_test()", |
| 124 | "test()", // wrapper calls original function |
| 125 | }, |
| 126 | }, |
| 127 | { |
| 128 | name: "extension with complex imports", |
| 129 | baseName: "complex", |
| 130 | sourceFile: createTempSourceFile(t, `package main |
| 131 | |
| 132 | import ( |
| 133 | "fmt" |
| 134 | "strings" |
| 135 | "encoding/json" |
| 136 | "github.com/dunglas/frankenphp/internal/extensions/types" |
| 137 | ) |
| 138 | |
| 139 | //export_php: process(data string): string |
| 140 | func process(data *go_string) *go_value { |
| 141 | return types.String(fmt.Sprintf("processed: %s", CStringToGoString(data))) |
| 142 | }`), |
| 143 | functions: []phpFunction{ |
| 144 | { |
| 145 | Name: "process", |
| 146 | ReturnType: phpString, |
| 147 | GoFunction: `func process(data *go_string) *go_value { |
nothing calls this directly
no test coverage detected