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

Function TestGoFileGenerator_ComplexScenario

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

Source from the content-addressed store, hash-verified

359}
360
361func TestGoFileGenerator_ComplexScenario(t *testing.T) {
362 sourceContent := `package example
363
364import (
365 "fmt"
366 "strings"
367 "encoding/json"
368 "github.com/dunglas/frankenphp/internal/extensions/types"
369)
370
371//export_php: processData(input string, options array): array
372func processData(input *go_string, options *go_nullable) *go_value {
373 data := CStringToGoString(input)
374 processed := internalProcess(data)
375 return types.Array([]any{processed})
376}
377
378//export_php: validateInput(data string): bool
379func validateInput(data *go_string) *go_value {
380 input := CStringToGoString(data)
381 isValid := len(input) > 0 && validateFormat(input)
382 return types.Bool(isValid)
383}
384
385func internalProcess(data string) string {
386 return strings.ToUpper(data)
387}
388
389func validateFormat(input string) bool {
390 return !strings.Contains(input, "invalid")
391}
392
393func jsonHelper(data any) ([]byte, error) {
394 return json.Marshal(data)
395}
396
397func debugPrint(msg string) {
398 fmt.Printf("DEBUG: %s\n", msg)
399}`
400
401 sourceFile := createTempSourceFile(t, sourceContent)
402
403 functions := []phpFunction{
404 {
405 Name: "processData",
406 ReturnType: phpArray,
407 GoFunction: `func processData(input *go_string, options *go_nullable) *go_value {
408 data := CStringToGoString(input)
409 processed := internalProcess(data)
410 return Array([]any{processed})
411}`,
412 },
413 {
414 Name: "validateInput",
415 ReturnType: phpBool,
416 GoFunction: `func validateInput(data *go_string) *go_value {
417 input := CStringToGoString(data)
418 isValid := len(input) > 0 && validateFormat(input)

Callers

nothing calls this directly

Calls 2

buildContentMethod · 0.95
createTempSourceFileFunction · 0.85

Tested by

no test coverage detected