Documentation
¶
Overview ¶
Index ¶
- Variables
- func BindingFunc(name string) any
- func BindingFuncs() map[string]any
- func RegisterBindings(rt *runner.Runtime)
- func ResetCaches()
- func TestMain(m *testing.M)
- func WriteHTMLReport(w io.Writer, results []*TestResult) error
- func WriteJSONReport(w io.Writer, results []*TestResult) error
- type BindingRecord
- type Fixture
- type FixtureRequest
- type FixtureResponse
- type FixtureRunners
- type Record
- type Runner
- type Storage
- type TestResult
Examples ¶
Constants ¶
This section is empty.
Variables ¶
ErrRunnerUnavailable reports that a runner cannot execute on this machine, which is a skip rather than a failure. The php runner returns it when no php binary is installed.
var Runners = []Runner{RunnerFlatstack, RunnerRuntime, RunnerPHP}
Runners lists every backend the test matrix covers, in report order.
Functions ¶
func BindingFunc ¶ added in v0.2.5
BindingFunc returns the raw (unregistered, unadapted) Go function behind a binding name, so benchmarks can measure the reflection return path on its own.
func BindingFuncs ¶ added in v0.2.5
BindingFuncs returns the example bindings keyed by the PHP name they are registered under.
func RegisterBindings ¶ added in v0.2.5
RegisterBindings installs the example bindings. It is passed to stdlib.Register as an extra installer, the same way a host contributes its own symbols.
func ResetCaches ¶ added in v0.2.1
func ResetCaches()
ResetCaches clears all global shared caches between test suites.
func WriteHTMLReport ¶ added in v0.2.1
func WriteHTMLReport(w io.Writer, results []*TestResult) error
WriteHTMLReport outputs an HTML report of the test results.
func WriteJSONReport ¶ added in v0.2.1
func WriteJSONReport(w io.Writer, results []*TestResult) error
WriteJSONReport outputs a JSON report of the test results.
Types ¶
type BindingRecord ¶ added in v0.2.5
BindingRecord is a plain Go struct handed to PHP as an object. Property access goes through runner.helperGet, which reads exported fields by reflection (case-insensitively), so `$r->name` and `$r->Name` both resolve.
func (BindingRecord) Label ¶ added in v0.2.5
func (r BindingRecord) Label() string
Label is an exported method so tests can exercise `$r->label()` dispatch on a forwarded Go value.
type Fixture ¶ added in v0.2.1
type Fixture struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Error string `yaml:"error"` // optional: expected uncaught error substring
Stdin string `yaml:"stdin"` // optional: top-level stdin contents
Options runner.Options `yaml:"options"` // optional: runtime options for both engines (memory_limit, ...)
Root string `yaml:"root"` // optional: include root, relative to the fixture's own directory
Serial bool `yaml:"serial"` // optional: do not overlap this fixture with peers in its area
Runner FixtureRunners `yaml:"runner"` // optional: runners the fixture opts out of
Request FixtureRequest `yaml:"request"`
Response FixtureResponse `yaml:"response"`
PHP string `yaml:"-"`
Expected string `yaml:"-"`
Path string `yaml:"-"`
// contains filtered or unexported fields
}
Fixture is the parsed representation of a .phpt test file.
func FindFixtures ¶ added in v0.2.1
FindFixtures locates all .phpt files in the specified paths (files or directories).
func ParseFixture ¶ added in v0.2.1
ParseFixture splits a .phpt file into its three sections and parses the YAML metadata.
func (*Fixture) Coverage ¶ added in v0.4.0
Coverage returns the collector installed with SetCoverage, or nil.
func (*Fixture) RootDir ¶ added in v0.3.3
RootDir returns the directory a fixture's includes resolve against. That is the directory holding it, which is also where the php runner executes, unless the fixture named another one with `root:`.
func (*Fixture) SetAppRoot ¶ added in v0.4.0
SetAppRoot points the fixture at the application root the test command ran in. The autoload folder convention and the prelude includes resolve there, while the fixture's own relative includes keep resolving against its directory: runnerOptions layers the two, fixture directory first.
An include that is not there is not an error; the flag says what to load when the application provides it, and a tree without an autoload.php simply runs without one.
func (*Fixture) SetCoverage ¶ added in v0.4.0
SetCoverage installs a statement-coverage collector for the fixture's runtime runner. Only that runner reports coverage: flatstack carries no coverage support, and the php runner is another process.
func (*Fixture) SetRootFS ¶ added in v0.3.3
SetRootFS binds the filesystem a fixture's includes resolve against. The directory holding the .phpt is the right answer for every caller: it is what the php runner uses as its working directory, so all three runners resolve a relative include to the same file.
type FixtureRequest ¶ added in v0.2.1
type FixtureRequest struct {
Args any `yaml:"args"` // map[string]string or []string or scalar
Get map[string]string `yaml:"get"`
Post map[string]string `yaml:"post"`
Cookie map[string]string `yaml:"cookie"`
Env map[string]string `yaml:"env"`
Headers map[string]string `yaml:"headers"`
Stdin string `yaml:"stdin"`
Body string `yaml:"body"`
}
FixtureRequest contains request data exposed to PHP as superglobals.
type FixtureResponse ¶ added in v0.2.1
FixtureResponse contains expected response assertions.
type FixtureRunners ¶ added in v0.3.0
FixtureRunners opts a fixture out of individual runners. An absent field means the runner is used; the default runtime can not be opted out of because it defines the fixture's expected output.
type Record ¶
Record is a rich value type returned to PHP. Its exported fields are read from PHP via property access (`$rec->key`, `$rec->value`), matched case-insensitively.
type Runner ¶ added in v0.3.0
type Runner string
Runner names an execution backend a fixture can be checked against.
const ( // RunnerFlatstack executes the fixture through the flat bytecode runtime, // which falls back to the compatibility interpreter for unsupported syntax. RunnerFlatstack Runner = "flatstack" // RunnerRuntime executes the fixture through the default interpreter. RunnerRuntime Runner = "runtime" // RunnerPHP executes the fixture through the php binary found in PATH. RunnerPHP Runner = "php" )
type Storage ¶
type Storage interface {
Set(ctx context.Context, key, value string)
Get(ctx context.Context, key string) (Record, error)
All(ctx context.Context) ([]Record, error)
Len() int64
Tenant() string
}
Storage is a host-provided key/value capability whose context parameters are supplied automatically when PHP invokes its methods.
Example ¶
ctx := context.WithValue(context.Background(), tenantKey, "acme")
storage, err := NewStorage(ctx)
if err != nil {
fmt.Println(err)
return
}
storage.Set(ctx, "color", "blue")
record, err := storage.Get(ctx, "color")
if err != nil {
fmt.Println(err)
return
}
fmt.Println(storage.Tenant())
fmt.Println(record.Key, record.Value)
fmt.Println(storage.Len())
Output: acme color blue 1
func NewFailStorage ¶
NewFailStorage is a constructor that always fails, used to exercise the thrown-error path of `new`.
type TestResult ¶ added in v0.2.1
type TestResult struct {
Name string `json:"name"`
Description string `json:"description"`
Path string `json:"path"`
Passed bool `json:"passed"`
DurationMs int64 `json:"duration_ms"`
FailureReason string `json:"failure_reason,omitempty"`
GotOutput string `json:"got_output,omitempty"`
WantOutput string `json:"want_output,omitempty"`
Error string `json:"error,omitempty"`
Runner Runner `json:"runner,omitempty"`
Skipped bool `json:"skipped,omitempty"`
}
TestResult carries execution outcome for a single fixture.
func RunFixture ¶ added in v0.2.1
func RunFixture(ctx context.Context, f *Fixture) *TestResult
RunFixture executes a single fixture against the default runtime.
func RunFixtureOn ¶ added in v0.3.0
func RunFixtureOn(ctx context.Context, f *Fixture, r Runner) *TestResult
RunFixtureOn executes a single fixture against one runner. Every runner is held to the same expected output; the runner only decides how the source is executed.