Greenlight

Documentation

API reference

On this page

Result API

This reference lists test outcomes, diagnostics, failure details, and result values.

These signatures are the public API.

CapturedOutput

Namespace: Greenlight\Result

Contains standard output, diagnostics, and truncation flags for one attempt. When output exceeds the capture limit, Greenlight keeps the first part.

Greenlight converts captured standard output to valid UTF-8 before it adds the output to a test result.

final readonly class CapturedOutput

View source

$diagnostics

public array $diagnostics;

PHPDoc:

View source

$stdout

public string $stdout

View source

$stdoutTruncated

public bool $stdoutTruncated

View source

$diagnosticsTruncated

public bool $diagnosticsTruncated

View source

__construct()

public function __construct(
    public string $stdout,
    array $diagnostics = [],
    public bool $stdoutTruncated = false,
    public bool $diagnosticsTruncated = false,
)

PHPDoc:

View source

Diagnostic

Namespace: Greenlight\Result

Greenlight converts the message and file to valid UTF-8 before it adds the diagnostic to a test result. These values originate in user code. The line number is greater than zero.

final readonly class Diagnostic

View source

$line

public int $line;

PHPDoc:

View source

$severity

public DiagnosticSeverity $severity

View source

$message

public string $message

View source

$file

public string $file

View source

__construct()

public function __construct(
    public DiagnosticSeverity $severity,
    public string $message,
    public string $file,
    int $line,
)

PHPDoc:

View source

DiagnosticSeverity

Namespace: Greenlight\Result

Greenlight captures only notices, warnings, and deprecations. PHP uses its default behavior for all other error levels.

enum DiagnosticSeverity: string

View source

Notice

case Notice = 'notice';

View source

Warning

case Warning = 'warning';

View source

Deprecation

case Deprecation = 'deprecation';

View source

fromErrorLevel()

Maps an engine error level to a diagnostic severity.

Returns null if Greenlight cannot capture the diagnostic.

public static function fromErrorLevel(int $level): ?self

View source

FailureDetail

Namespace: Greenlight\Result

Expected and actual are strings that the worker renders. Live values never cross the process boundary.

final readonly class FailureDetail

View source

$message

public string $message;

PHPDoc:

View source

$expected

public ?string $expected

View source

$actual

public ?string $actual

View source

$location

public ?SourceLocation $location

View source

__construct()

public function __construct(
    string $message,
    public ?string $expected = null,
    public ?string $actual = null,
    public ?SourceLocation $location = null,
)

PHPDoc:

View source

Outcome

Namespace: Greenlight\Result

A retried test has exactly one of these final outcomes. TestResult contains the attempt count.

enum Outcome: string

View source

Passed

case Passed = 'passed';

View source

Failed

case Failed = 'failed';

View source

Errored

case Errored = 'errored';

View source

Skipped

case Skipped = 'skipped';

View source

isSuccessful()

public function isSuccessful(): bool

View source

OutcomeTransformation

Namespace: Greenlight\Result

Records the source of a plugin change to a test outcome.

final readonly class OutcomeTransformation

View source

$transformedBy

public string $transformedBy;

PHPDoc:

View source

$from

public Outcome $from

View source

$to

public Outcome $to

View source

__construct()

public function __construct(
    string $transformedBy,
    public Outcome $from,
    public Outcome $to,
)

PHPDoc:

View source

ResultSummary

Namespace: Greenlight\Result

Aggregate outcome counts for a run.

final readonly class ResultSummary

View source

$passed

public int $passed;

PHPDoc:

View source

$failed

public int $failed;

PHPDoc:

View source

$errored

public int $errored;

PHPDoc:

View source

$skipped

public int $skipped;

PHPDoc:

View source

__construct()

public function __construct(
    int $passed = 0,
    int $failed = 0,
    int $errored = 0,
    int $skipped = 0,
)

PHPDoc:

View source

add()

public function add(Outcome $outcome): self

View source

total()

public function total(): int

PHPDoc:

View source

isSuccessful()

public function isSuccessful(): bool

View source

SourceLocation

Namespace: Greenlight\Result

final readonly class SourceLocation implements \Stringable

View source

$file

public string $file;

PHPDoc:

View source

$line

public int $line;

PHPDoc:

View source

__construct()

public function __construct(string $file, int $line)

PHPDoc:

View source

__toString()

public function __toString(): string

View source

TestResult

Namespace: Greenlight\Result

A plugin does not change a result object. It uses withOutcome() to produce a replacement and record the source of the change.

The expectations value counts each immediate matcher and each mock expectation that disposal verifies. Each temporal matcher counts once, regardless of the number of polls. Stubs do not add to the count.

The worker records the count after cleanup and per-test service disposal, before afterTest() subscribers. Retries report the final attempt’s count.

final readonly class TestResult

View source

$attempts

public int $attempts;

PHPDoc:

View source

$expectations

public int $expectations;

PHPDoc:

View source

$id

public TestId $id

View source

$outcome

public Outcome $outcome

View source

$durationSeconds

public float $durationSeconds

View source

$memoryDeltaBytes

public int $memoryDeltaBytes

View source

$failures

public array $failures

View source

$error

public ?ThrowableDetail $error

View source

$skipReason

public ?string $skipReason

View source

$transformations

public array $transformations

View source

$output

public ?CapturedOutput $output

View source

$risky

public bool $risky

View source

$attachments

public array $attachments

View source

__construct()

public function __construct(
    public TestId $id,
    public Outcome $outcome,
    public float $durationSeconds,
    public int $memoryDeltaBytes,
    int $attempts = 1,
    public array $failures = [],
    public ?ThrowableDetail $error = null,
    public ?string $skipReason = null,
    public array $transformations = [],
    public ?CapturedOutput $output = null,
    public bool $risky = false,
    int $expectations = 0,
    public array $attachments = [],
)

PHPDoc:

View source

withOutcome()

public function withOutcome(Outcome $outcome, string $transformedBy): self

PHPDoc:

View source

ThrowableDetail

Namespace: Greenlight\Result

Contains a throwable’s class, message, source location, and stack trace.

final readonly class ThrowableDetail

View source

$class

public string $class;

PHPDoc:

View source

$file

public string $file;

PHPDoc:

View source

$line

public int $line;

PHPDoc:

View source

$message

public string $message

View source

$stackFrames

public array $stackFrames

View source

__construct()

public function __construct(
    string $class,
    public string $message,
    string $file,
    int $line,
    public array $stackFrames = [],
)

PHPDoc:

View source

fromThrowable()

Records at most 32 stack frames. Adds a truncation marker if more frames exist.

public static function fromThrowable(\Throwable $throwable): self

View source