Browse documentation

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.

Before

Namespace: Greenlight\Attribute

#[\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

__construct()

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

PHPDoc:

View source

DataSet

Namespace: Greenlight\Attribute

References a pure public static data provider. The provider runs during discovery.

#[\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

#[\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

Greenlight assigns a new worker to each selected test.

#[\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 class 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

#[\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

A worker evaluates the condition. Because the worker protocol transfers the constructor arguments, use only scalar values or null.

#[\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

Greenlight captures test output by default.

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

View source

__construct()

public function __construct(public bool $capture = true)

View source

Timeout

Namespace: Greenlight\Attribute

Fails the test if its run time exceeds the specified number of seconds. A class attribute applies the limit to each test in the class.

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

View source

__construct()

public function __construct(
    public float $seconds,
)

PHPDoc:

View source

ClassAvailable

Namespace: Greenlight\Condition

final readonly class ClassAvailable implements Condition

View source

__construct()

public function __construct(string $class)

PHPDoc:

View source

isSatisfied()

[\Override]
public function isSatisfied(): bool

View source

EnvironmentVariableEquals

Namespace: Greenlight\Condition

final readonly class EnvironmentVariableEquals implements Condition

View source

isSatisfied()

[\Override]
public function isSatisfied(): bool

View source

EnvironmentVariableSet

Namespace: Greenlight\Condition

final readonly class EnvironmentVariableSet implements Condition

View source

__construct()

public function __construct(string $name)

PHPDoc:

View source

isSatisfied()

[\Override]
public function isSatisfied(): bool

View source

ExtensionLoaded

Namespace: Greenlight\Condition

final readonly class ExtensionLoaded implements Condition

View source

__construct()

public function __construct(string $extension)

PHPDoc:

View source

isSatisfied()

[\Override]
public function isSatisfied(): bool

View source

ExtensionMissing

Namespace: Greenlight\Condition

final readonly class ExtensionMissing implements Condition

View source

__construct()

public function __construct(string $extension)

PHPDoc:

View source

isSatisfied()

[\Override]
public function isSatisfied(): bool

View source

FunctionAvailable

Namespace: Greenlight\Condition

final readonly class FunctionAvailable implements Condition

View source

__construct()

public function __construct(string $function)

PHPDoc:

View source

isSatisfied()

[\Override]
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()

[\Override]
public function isSatisfied(): bool

View source

PhpVersionAtLeast

Namespace: Greenlight\Condition

final readonly class PhpVersionAtLeast implements Condition

View source

__construct()

public function __construct(string $version)

PHPDoc:

View source

isSatisfied()

[\Override]
public function isSatisfied(): bool

View source

PhpVersionLessThan

Namespace: Greenlight\Condition

final readonly class PhpVersionLessThan implements Condition

View source

__construct()

public function __construct(string $version)

PHPDoc:

View source

isSatisfied()

[\Override]
public function isSatisfied(): bool

View source