Greenlight

Documentation

API reference

On this page

Attributes and conditions API

This reference lists the attributes and conditions that control test discovery and execution.

These signatures are the public API.

After

Namespace: Greenlight\Attribute

Runs at the end of an attempt that has a test instance. It also runs when setup or the test method does not complete.

#[\Attribute(\Attribute::TARGET_METHOD)]
final readonly class After

View source

This type does not declare public members.

AllowParallel

Namespace: Greenlight\Attribute

Allows Greenlight to assign tests from one class to different workers.

Do not use this attribute with per-class harness services or #[Isolated].

#[\Attribute(\Attribute::TARGET_CLASS)]
final readonly class AllowParallel

View source

This type does not declare public members.

Before

Namespace: Greenlight\Attribute

Runs the method before each test attempt in the class.

#[\Attribute(\Attribute::TARGET_METHOD)]
final readonly class Before

View source

This type does not declare public members.

CoverageIgnore

Namespace: Greenlight\Attribute

Excludes the selected lines from coverage totals, coverage exports, and baseline diffs.

#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_FUNCTION)]
final readonly class CoverageIgnore

View source

This type does not declare public members.

DataRow

Namespace: Greenlight\Attribute

Supplies one argument list in an attribute for a test method.

The optional label becomes the data-set key in the test ID. A row without a label uses its position. Use #[DataSet] if an attribute cannot express a value.

#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
final readonly class DataRow

View source

$label

public ?string $label;

PHPDoc:

View source

$arguments

public array $arguments

View source

__construct()

public function __construct(
    public array $arguments,
    ?string $label = null,
)

PHPDoc:

View source

DataSet

Namespace: Greenlight\Attribute

References a pure public static data provider. Greenlight evaluates the provider during discovery and again in the worker for each class assignment. Return the same data for the same inputs. Do not change external state.

#[\Attribute(\Attribute::TARGET_METHOD)]
final readonly class DataSet

View source

$provider

public string $provider;

PHPDoc:

View source

$providerClass

public ?string $providerClass;

PHPDoc:

View source

__construct()

With one argument, $provider names a method on the test class. With two arguments, it names the provider class and $method names the provider method.

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

PHPDoc:

View source

Group

Namespace: Greenlight\Attribute

Adds a group name to a test method or all tests in a class. Class and method groups combine. Repeat the attribute to add more groups.

#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
final readonly class Group

View source

$name

public string $name;

PHPDoc:

View source

__construct()

public function __construct(string $name)

PHPDoc:

View source

Isolated

Namespace: Greenlight\Attribute

Assigns a fresh worker process to each selected test during process-pool execution. In-process execution does not provide process isolation.

#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
final readonly class Isolated

View source

This type does not declare public members.

NoExpectations

Namespace: Greenlight\Attribute

Exempts a test that intentionally verifies no expectations from risky-test detection.

#[\Attribute(\Attribute::TARGET_METHOD)]
final readonly class NoExpectations

View source

This type does not declare public members.

RequiresResource

Namespace: Greenlight\Attribute

Declares a resource that the assignment for the test requires.

#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
final readonly class RequiresResource

View source

$name

public string $name;

PHPDoc:

View source

__construct()

public function __construct(string $name)

PHPDoc:

View source

Retry

Namespace: Greenlight\Attribute

Starts up to $times additional attempts after an unsuccessful test attempt. If $onlyOn specifies a throwable type, Greenlight starts another attempt only when the cause has that type.

#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
final readonly class Retry

View source

$times

public int $times;

PHPDoc:

View source

$onlyOn

public ?string $onlyOn;

PHPDoc:

View source

__construct()

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

PHPDoc:

View source

Skip

Namespace: Greenlight\Attribute

Skips a test method or all tests in a class with the specified reason.

#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
final readonly class Skip

View source

$reason

public string $reason;

PHPDoc:

View source

__construct()

public function __construct(string $reason)

PHPDoc:

View source

SkipUnless

Namespace: Greenlight\Attribute

Skips a test unless the condition returns true.

A worker evaluates the condition. Use only scalar values or null for constructor arguments. Use finite float values.

#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
final readonly class SkipUnless

View source

$condition

public string $condition;

PHPDoc:

View source

$arguments

public array $arguments;

PHPDoc:

View source

__construct()

public function __construct(
    string $condition,
    mixed ...$arguments,
)

PHPDoc:

View source

Test

Namespace: Greenlight\Attribute

Identifies a test method. Greenlight captures test output by default.

#[\Attribute(\Attribute::TARGET_METHOD)]
final readonly class Test

View source

$capture

public bool $capture

View source

__construct()

public function __construct(public bool $capture = true)

View source

Timeout

Namespace: Greenlight\Attribute

Fails an otherwise passed attempt if its run time exceeds the specified number of seconds. Greenlight checks elapsed time after per-test service disposal. This check does not interrupt PHP code that is still running. A class attribute applies the limit to each test in the class.

During process-pool execution, the orchestrator also stops a blocked worker after the timeout grace period. In-process execution has no such interrupt.

#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
final readonly class Timeout

View source

$seconds

public float $seconds

View source

__construct()

public function __construct(
    public float $seconds,
)

PHPDoc:

View source

ClassAvailable

Namespace: Greenlight\Condition

Passes when class_exists() finds the named class, with autoloading enabled.

final readonly class ClassAvailable implements Condition

View source

__construct()

public function __construct(string $class)

PHPDoc:

View source

isSatisfied()

public function isSatisfied(): bool

View source

Condition

Namespace: Greenlight\Condition

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

EnvironmentVariableEquals

Namespace: Greenlight\Condition

Passes when getenv() returns the exact expected string for the variable.

final readonly class EnvironmentVariableEquals implements Condition

View source

__construct()

public function __construct(string $name, private string $value)

PHPDoc:

View source

isSatisfied()

public function isSatisfied(): bool

View source

EnvironmentVariableSet

Namespace: Greenlight\Condition

Passes when getenv() finds the variable, including an empty string value.

final readonly class EnvironmentVariableSet implements Condition

View source

__construct()

public function __construct(string $name)

PHPDoc:

View source

isSatisfied()

public function isSatisfied(): bool

View source

ExtensionLoaded

Namespace: Greenlight\Condition

Passes when the named PHP extension is loaded.

final readonly class ExtensionLoaded implements Condition

View source

__construct()

public function __construct(string $extension)

PHPDoc:

View source

isSatisfied()

public function isSatisfied(): bool

View source

ExtensionMissing

Namespace: Greenlight\Condition

Passes when the named PHP extension is not loaded.

final readonly class ExtensionMissing implements Condition

View source

__construct()

public function __construct(string $extension)

PHPDoc:

View source

isSatisfied()

public function isSatisfied(): bool

View source

FunctionAvailable

Namespace: Greenlight\Condition

Passes when function_exists() finds the named function.

final readonly class FunctionAvailable implements Condition

View source

__construct()

public function __construct(string $function)

PHPDoc:

View source

isSatisfied()

public function isSatisfied(): bool

View source

OperatingSystemFamily

Namespace: Greenlight\Condition

Compares the value to PHP_OS_FAMILY without case sensitivity.

final readonly class OperatingSystemFamily implements Condition

View source

__construct()

public function __construct(string $family)

PHPDoc:

View source

isSatisfied()

public function isSatisfied(): bool

View source

PhpVersionAtLeast

Namespace: Greenlight\Condition

Passes when PHP_VERSION is at least the specified version, as compared by version_compare().

final readonly class PhpVersionAtLeast implements Condition

View source

__construct()

public function __construct(string $version)

PHPDoc:

View source

isSatisfied()

public function isSatisfied(): bool

View source

PhpVersionLessThan

Namespace: Greenlight\Condition

Passes when PHP_VERSION is less than the specified version, as compared by version_compare().

final readonly class PhpVersionLessThan implements Condition

View source

__construct()

public function __construct(string $version)

PHPDoc:

View source

isSatisfied()

public function isSatisfied(): bool

View source