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
isSatisfied()
public function isSatisfied(): bool;
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
$reason
public readonly string $reason;
PHPDoc:
@var non-empty-string
__construct()
public function __construct(string $reason)
PHPDoc:
@throws \InvalidArgumentException If $reason is empty.
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
$number
public int $number;
PHPDoc:
@var positive-int
__construct()
public function __construct(int $number)
PHPDoc:
@throws \InvalidArgumentException
label()
public function label(): string
PHPDoc:
@return non-empty-string
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
__construct()
public function __construct(
public string $class,
public string $method,
public ?string $dataSetKey = null,
)
PHPDoc:
@param non-empty-string $class@param non-empty-string $method
equals()
public function equals(self $other): bool
__toString()
[\Override]
public function __toString(): string
toWire()
[\Override]
public function toWire(): array
fromWire()
[\Override]
public static function fromWire(array $payload): static
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
$groups
public array $groups;
PHPDoc:
@var list<non-empty-string>
$skipUnlessArguments
public array $skipUnlessArguments;
PHPDoc:
@var list<scalar|null>
$resources
public array $resources;
PHPDoc:
@var list<non-empty-string>
__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:
@param non-empty-string $class@param non-empty-string $method@param list<string> $groups@param non-empty-string|null $skipReason@param non-empty-string|null $skipUnlessCondition@param positive-int|null $retryTimes@param non-empty-string|null $retryOnlyOn@param non-empty-string|null $dataSetProvider@param list<mixed> $skipUnlessArguments validated to scalars or null@param list<string> $resources named resources required by this test entry@param non-empty-string|null $dataSetProviderClass@throws \InvalidArgumentException
toWire()
[\Override]
public function toWire(): array
fromWire()
[\Override]
public static function fromWire(array $payload): static
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
missingKey()
public static function missingKey(string $key): self
wrongType()
public static function wrongType(string $key, string $expected, mixed $actual): self
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
toWire()
public function toWire(): array;
PHPDoc:
@return array<string, mixed>
fromWire()
public static function fromWire(array $payload): static;
PHPDoc:
@param array<string, mixed> $payload@throws InvalidWirePayload