Greenlight

Documentation

API reference

On this page

Test contracts API

This reference lists test definitions, policies, and skip signals.

These signatures are the public API.

Cleanup

Namespace: Greenlight\Test

Stores cleanup callbacks for one test attempt. Greenlight runs the callbacks in reverse registration order after the After hooks. Per-test service disposal starts after the callbacks finish.

Greenlight runs all callbacks if one fails. An expectation failure during cleanup fails a passed or skipped test. Other cleanup exceptions cause an errored result. Cleanup does not replace an earlier test failure or error.

final class Cleanup

View source

defer()

Register cleanup immediately after the test acquires a resource. This makes cleanup available if a later operation fails. Greenlight ignores the callback return value.

public function defer(\Closure $cleanup): void

PHPDoc:

View source

DataProvider

Namespace: Greenlight\Test

Identifies the method and optional external class that supply test data sets.

final readonly class DataProvider

View source

$method

public ?string $method

View source

$class

public ?string $class

View source

__construct()

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

PHPDoc:

View source

ExecutionPolicy

Namespace: Greenlight\Test

Defines timeout, output capture, and expectation rules for one test.

final readonly class ExecutionPolicy

View source

$timeoutSeconds

public ?float $timeoutSeconds

View source

$capture

public bool $capture

View source

$noExpectations

public bool $noExpectations

View source

__construct()

public function __construct(
    public ?float $timeoutSeconds = null,
    public bool $capture = true,
    public bool $noExpectations = false,
)

PHPDoc:

View source

RetryPolicy

Namespace: Greenlight\Test

Defines the retry limit and the optional throwable filter for a test.

final readonly class RetryPolicy

View source

$times

public ?int $times;

PHPDoc:

View source

$onlyOn

public ?string $onlyOn

View source

__construct()

public function __construct(
    ?int $times = null,
    public ?string $onlyOn = null,
)

PHPDoc:

View source

SchedulingPolicy

Namespace: Greenlight\Test

Defines worker assignment and resource rules for one test.

final readonly class SchedulingPolicy

View source

$resources

public array $resources;

PHPDoc:

View source

$isolated

public bool $isolated

View source

$allowParallel

public bool $allowParallel

View source

__construct()

public function __construct(
    public bool $isolated = false,
    array $resources = [],
    public bool $allowParallel = false,
)

PHPDoc:

View source

SkipPolicy

Namespace: Greenlight\Test

Defines the static reason or condition that skips a test.

final readonly class SkipPolicy

View source

$arguments

public array $arguments;

PHPDoc:

View source

$reason

public ?string $reason

View source

$condition

public ?string $condition

View source

__construct()

public function __construct(
    public ?string $reason = null,
    public ?string $condition = null,
    array $arguments = [],
)

PHPDoc:

View source

SkipTest

Namespace: Greenlight\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\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

TestDefinition

Namespace: Greenlight\Test

Contains one test declaration and its discovery policies.

final readonly class TestDefinition

View source

$class

public string $class;

PHPDoc:

View source

$method

public string $method;

PHPDoc:

View source

$groups

public array $groups;

PHPDoc:

View source

$skip

public SkipPolicy $skip

View source

$retry

public RetryPolicy $retry

View source

$dataProvider

public DataProvider $dataProvider

View source

$execution

public ExecutionPolicy $execution

View source

$scheduling

public SchedulingPolicy $scheduling

View source

__construct()

public function __construct(
    string $class,
    string $method,
    array $groups = [],
    public SkipPolicy $skip = new SkipPolicy(),
    public RetryPolicy $retry = new RetryPolicy(),
    public DataProvider $dataProvider = new DataProvider(),
    public ExecutionPolicy $execution = new ExecutionPolicy(),
    public SchedulingPolicy $scheduling = new SchedulingPolicy(),
)

PHPDoc:

View source

TestId

Namespace: Greenlight\Test

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

final readonly class TestId implements \Stringable

View source

$class

public string $class;

PHPDoc:

View source

$method

public string $method;

PHPDoc:

View source

$dataSetKey

public ?string $dataSetKey

View source

__construct()

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

PHPDoc:

View source

equals()

public function equals(self $other): bool

View source

__toString()

public function __toString(): string

View source