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

Function TestCFileGenerator_Generate

internal/extgen/cfile_test.go:12–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestCFileGenerator_Generate(t *testing.T) {
13 tmpDir := t.TempDir()
14
15 generator := &Generator{
16 BaseName: "test_extension",
17 BuildDir: tmpDir,
18 Functions: []phpFunction{
19 {
20 Name: "simpleFunction",
21 ReturnType: phpString,
22 Params: []phpParameter{
23 {Name: "input", PhpType: phpString},
24 },
25 },
26 {
27 Name: "complexFunction",
28 ReturnType: phpArray,
29 Params: []phpParameter{
30 {Name: "data", PhpType: phpString},
31 {Name: "count", PhpType: phpInt, IsNullable: true},
32 {Name: "options", PhpType: phpArray, HasDefault: true, DefaultValue: "[]"},
33 },
34 },
35 },
36 Classes: []phpClass{
37 {
38 Name: "TestClass",
39 GoStruct: "TestStruct",
40 Properties: []phpClassProperty{
41 {Name: "id", PhpType: phpInt},
42 {Name: "name", PhpType: phpString},
43 },
44 },
45 },
46 }
47
48 cGen := cFileGenerator{generator}
49 require.NoError(t, cGen.generate())
50
51 expectedFile := filepath.Join(tmpDir, "test_extension.c")
52 require.FileExists(t, expectedFile, "Expected C file was not created: %s", expectedFile)
53
54 content, err := readFile(expectedFile)
55 require.NoError(t, err)
56
57 testCFileBasicStructure(t, content, "test_extension")
58 testCFileFunctions(t, content, generator.Functions)
59 testCFileClasses(t, content, generator.Classes)
60}
61
62func TestCFileGenerator_BuildContent(t *testing.T) {
63 tests := []struct {

Callers

nothing calls this directly

Calls 5

generateMethod · 0.95
readFileFunction · 0.85
testCFileBasicStructureFunction · 0.85
testCFileFunctionsFunction · 0.85
testCFileClassesFunction · 0.85

Tested by

no test coverage detected