Browse documentation

Test contracts API

This reference lists test metadata, skip signals, conditions, and wire contracts.

These signatures are the public API.

Condition

Namespace: Greenlight\Core

A runtime condition that #[SkipUnless] references.

Implementations can receive constructor arguments from #[SkipUnless]. Constructors must only store these arguments. isSatisfied() evaluates the condition and must not cause other changes.

interface Condition

View source

isSatisfied()

public function isSatisfied(): bool;

View source

SkipTest

Namespace: Greenlight\Core\Test

Reports a skipped test with the specified reason.

Throw this signal from a test method, a before hook, or a beforeTest() subscriber.

final class SkipTest extends \Exception

View source

$reason

public readonly string $reason;

PHPDoc:

View source

__construct()

public function __construct(string $reason)

PHPDoc:

View source

TestChannel

Namespace: Greenlight\Core\Test

A live worker owns a unique channel from 1 to the worker count. A replacement worker reuses a free channel. Thus, channel resources remain available when Greenlight replaces a worker. In-process runs use channel 1.

GREENLIGHT_CHANNEL supplies the same value outside the harness. label() adds “gl-” before the number.

final readonly class TestChannel

View source

$number

public int $number;

PHPDoc:

View source

__construct()

public function __construct(int $number)

PHPDoc:

View source

label()

public function label(): string

PHPDoc:

View source

TestId

Namespace: Greenlight\Core\Test

Identifies a test across processes for assignment, rerun selection, and the timing cache.

final readonly class TestId implements WireSerializable, \Stringable

View source

__construct()

public function __construct(
    public string $class,
    public string $method,
    public ?string $dataSetKey = null,
)

PHPDoc:

View source

equals()

public function equals(self $other): bool

View source

__toString()

[\Override]
public function __toString(): string

View source

toWire()

[\Override]
public function toWire(): array

View source

fromWire()

[\Override]
public static function fromWire(array $payload): static

View source

TestMetadata

Namespace: Greenlight\Core\Test

Contains class attributes and method attributes. A method attribute replaces a class attribute when they conflict.

final readonly class TestMetadata implements WireSerializable

View source

$groups

public array $groups;

PHPDoc:

View source

$skipUnlessArguments

public array $skipUnlessArguments;

PHPDoc:

View source

$resources

public array $resources;

PHPDoc:

View source

__construct()

public function __construct(
    public string $class,
    public string $method,
    array $groups = [],
    public ?string $skipReason = null,
    public ?string $skipUnlessCondition = null,
    public ?int $retryTimes = null,
    public ?string $retryOnlyOn = null,
    public ?float $timeoutSeconds = null,
    public bool $isolated = false,
    public ?string $dataSetProvider = null,
    public bool $capture = true,
    public bool $noExpectations = false,
    array $skipUnlessArguments = [],
    array $resources = [],
    public ?string $dataSetProviderClass = null,
)

PHPDoc:

View source

toWire()

[\Override]
public function toWire(): array

View source

fromWire()

[\Override]
public static function fromWire(array $payload): static

View source

InvalidWirePayload

Namespace: Greenlight\Core\Wire

Greenlight raises this error when a decoded wire payload has a missing key or an incorrect value type.

The error always names the applicable key. Thus, its message identifies the protocol error.

final class InvalidWirePayload extends \RuntimeException

View source

missingKey()

public static function missingKey(string $key): self

View source

wrongType()

public static function wrongType(string $key, string $expected, mixed $actual): self

View source

WireSerializable

Namespace: Greenlight\Core\Wire

Defines values that cross the boundary between an orchestrator and a worker.

A JSON encode and decode operation must preserve the payload. Keys are strings. Values are scalars, null, or nested arrays of these types. Do not use PHP serialize().

interface WireSerializable

View source

toWire()

public function toWire(): array;

PHPDoc:

View source

fromWire()

public static function fromWire(array $payload): static;

PHPDoc:

View source