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

Function TestConstantParserClassConstants

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

Source from the content-addressed store, hash-verified

469}
470
471func TestConstantParserClassConstants(t *testing.T) {
472 tests := []struct {
473 name string
474 input string
475 expect int
476 assert func(t *testing.T, constants []phpConstant)
477 }{
478 {
479 name: "single class constant",
480 input: `package main
481
482//export_php:classconst MyClass
483const STATUS_ACTIVE = 1`,
484 expect: 1,
485 assert: func(t *testing.T, cs []phpConstant) {
486 c := cs[0]
487 assert.Equal(t, "STATUS_ACTIVE", c.Name)
488 assert.Equal(t, "MyClass", c.ClassName)
489 assert.Equal(t, "1", c.Value)
490 assert.Equal(t, phpInt, c.PhpType)
491 },
492 },
493 {
494 name: "multiple class constants",
495 input: `package main
496
497//export_php:classconst User
498const STATUS_ACTIVE = "active"
499
500//export_php:classconst User
501const STATUS_INACTIVE = "inactive"
502
503//export_php:classconst Order
504const STATE_PENDING = 0`,
505 expect: 3,
506 assert: func(t *testing.T, cs []phpConstant) {
507 classes := []string{"User", "User", "Order"}
508 names := []string{"STATUS_ACTIVE", "STATUS_INACTIVE", "STATE_PENDING"}
509 values := []string{`"active"`, `"inactive"`, "0"}
510 for i, c := range cs {
511 assert.Equal(t, classes[i], c.ClassName)
512 assert.Equal(t, names[i], c.Name)
513 assert.Equal(t, values[i], c.Value)
514 }
515 },
516 },
517 {
518 name: "mixed global and class constants",
519 input: `package main
520
521//export_php:const
522const GLOBAL_CONST = "global"
523
524//export_php:classconst MyClass
525const CLASS_CONST = 42
526
527//export_php:const
528const ANOTHER_GLOBAL = true`,

Callers

nothing calls this directly

Calls 1

parseMethod · 0.95

Tested by

no test coverage detected