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

Function TestStubGenerator_Generate

internal/extgen/stub_test.go:11–70  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestStubGenerator_Generate(t *testing.T) {
12 tmpDir := t.TempDir()
13
14 generator := &Generator{
15 BaseName: "test_extension",
16 BuildDir: tmpDir,
17 Functions: []phpFunction{
18 {
19 Name: "greet",
20 Signature: "greet(string $name): string",
21 Params: []phpParameter{
22 {Name: "name", PhpType: phpString},
23 },
24 ReturnType: phpString,
25 },
26 {
27 Name: "calculate",
28 Signature: "calculate(int $a, int $b): int",
29 Params: []phpParameter{
30 {Name: "a", PhpType: phpInt},
31 {Name: "b", PhpType: phpInt},
32 },
33 ReturnType: phpInt,
34 },
35 },
36 Classes: []phpClass{
37 {
38 Name: "User",
39 GoStruct: "UserStruct",
40 },
41 },
42 Constants: []phpConstant{
43 {
44 Name: "GLOBAL_CONST",
45 Value: "42",
46 PhpType: phpInt,
47 },
48 {
49 Name: "USER_STATUS_ACTIVE",
50 Value: "1",
51 PhpType: phpInt,
52 ClassName: "User",
53 },
54 },
55 }
56
57 stubGen := StubGenerator{generator}
58 assert.NoError(t, stubGen.generate(), "generate() failed")
59
60 expectedFile := filepath.Join(tmpDir, "test_extension.stub.php")
61 assert.FileExists(t, expectedFile, "Expected stub file was not created: %s", expectedFile)
62
63 content, err := readFile(expectedFile)
64 assert.NoError(t, err, "Failed to read generated stub file")
65
66 testStubBasicStructure(t, content)
67 testStubFunctions(t, content, generator.Functions)
68 testStubClasses(t, content, generator.Classes)

Callers

nothing calls this directly

Calls 6

generateMethod · 0.95
readFileFunction · 0.85
testStubBasicStructureFunction · 0.85
testStubFunctionsFunction · 0.85
testStubClassesFunction · 0.85
testStubConstantsFunction · 0.85

Tested by

no test coverage detected