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

Function TestConstantParserClassConstBlock

internal/extgen/constparser_test.go:378–407  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

376}
377
378func TestConstantParserClassConstBlock(t *testing.T) {
379 input := `package main
380
381// export_php:classconst Config
382const (
383 MODE_DEBUG = 1
384 MODE_PRODUCTION = 2
385 MODE_TEST = 3
386)`
387
388 tmpDir := t.TempDir()
389 fileName := filepath.Join(tmpDir, "test.go")
390 require.NoError(t, os.WriteFile(fileName, []byte(input), 0644))
391
392 parser := &ConstantParser{}
393 constants, err := parser.parse(fileName)
394 assert.NoError(t, err, "parse() error")
395
396 assert.Len(t, constants, 3, "Expected 3 class constants")
397
398 expectedNames := []string{"MODE_DEBUG", "MODE_PRODUCTION", "MODE_TEST"}
399 expectedValues := []string{"1", "2", "3"}
400
401 for i, c := range constants {
402 assert.Equal(t, expectedNames[i], c.Name, "Expected constant %d name to be '%s'", i, expectedNames[i])
403 assert.Equal(t, "Config", c.ClassName, "Expected constant %d to belong to Config class", i)
404 assert.Equal(t, expectedValues[i], c.Value, "Expected constant %d value to be '%s'", i, expectedValues[i])
405 assert.Equal(t, phpInt, c.PhpType, "Expected constant %d to be phpInt type", i)
406 }
407}
408
409func TestConstantParserClassConstBlockWithIota(t *testing.T) {
410 input := `package main

Callers

nothing calls this directly

Calls 1

parseMethod · 0.95

Tested by

no test coverage detected