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
This type does not declare public members.
Before
Namespace: Greenlight\Attribute
#[\Attribute(\Attribute::TARGET_METHOD)]
final readonly class Before
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
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
__construct()
public function __construct(
public array $arguments,
public ?string $label = null,
)
PHPDoc:
@param array<mixed> $arguments@param non-empty-string|null $label
DataSet
Namespace: Greenlight\Attribute
References a pure public static data provider. The provider runs during discovery.
#[\Attribute(\Attribute::TARGET_METHOD)]
final readonly class DataSet
$provider
public string $provider;
PHPDoc:
@var non-empty-string
$providerClass
public ?string $providerClass;
PHPDoc:
@var non-empty-string|null
__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:
@throws \InvalidArgumentException
Group
Namespace: Greenlight\Attribute
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
final readonly class Group
$name
public string $name;
PHPDoc:
@var non-empty-string
__construct()
public function __construct(string $name)
PHPDoc:
@throws \InvalidArgumentException
Isolated
Namespace: Greenlight\Attribute
Greenlight assigns a new worker to each selected test.
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
final readonly class Isolated
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
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
$name
public string $name;
PHPDoc:
@var non-empty-string
__construct()
public function __construct(string $name)
PHPDoc:
@throws \InvalidArgumentException
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
$times
public int $times;
PHPDoc:
@var positive-int
$onlyOn
public ?string $onlyOn;
PHPDoc:
@var class-string<\Throwable>|null
__construct()
public function __construct(
int $times,
?string $onlyOn = null,
)
PHPDoc:
@throws \InvalidArgumentException
Skip
Namespace: Greenlight\Attribute
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS)]
final readonly class Skip
$reason
public string $reason;
PHPDoc:
@var non-empty-string
__construct()
public function __construct(string $reason)
PHPDoc:
@throws \InvalidArgumentException If $reason is empty.
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
$condition
public string $condition;
PHPDoc:
@var class-string<Condition>
$arguments
public array $arguments;
PHPDoc:
@var list<mixed>
__construct()
public function __construct(
string $condition,
mixed ...$arguments,
)
PHPDoc:
@throws \InvalidArgumentException
Test
Namespace: Greenlight\Attribute
Greenlight captures test output by default.
#[\Attribute(\Attribute::TARGET_METHOD)]
final readonly class Test
__construct()
public function __construct(public bool $capture = true)
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
__construct()
public function __construct(
public float $seconds,
)
PHPDoc:
@throws \InvalidArgumentException
ClassAvailable
Namespace: Greenlight\Condition
final readonly class ClassAvailable implements Condition
__construct()
public function __construct(string $class)
PHPDoc:
@throws \InvalidArgumentException
isSatisfied()
[\Override]
public function isSatisfied(): bool
EnvironmentVariableEquals
Namespace: Greenlight\Condition
final readonly class EnvironmentVariableEquals implements Condition
isSatisfied()
[\Override]
public function isSatisfied(): bool
EnvironmentVariableSet
Namespace: Greenlight\Condition
final readonly class EnvironmentVariableSet implements Condition
__construct()
public function __construct(string $name)
PHPDoc:
@throws \InvalidArgumentException
isSatisfied()
[\Override]
public function isSatisfied(): bool
ExtensionLoaded
Namespace: Greenlight\Condition
final readonly class ExtensionLoaded implements Condition
__construct()
public function __construct(string $extension)
PHPDoc:
@throws \InvalidArgumentException
isSatisfied()
[\Override]
public function isSatisfied(): bool
ExtensionMissing
Namespace: Greenlight\Condition
final readonly class ExtensionMissing implements Condition
__construct()
public function __construct(string $extension)
PHPDoc:
@throws \InvalidArgumentException
isSatisfied()
[\Override]
public function isSatisfied(): bool
FunctionAvailable
Namespace: Greenlight\Condition
final readonly class FunctionAvailable implements Condition
__construct()
public function __construct(string $function)
PHPDoc:
@throws \InvalidArgumentException
isSatisfied()
[\Override]
public function isSatisfied(): bool
OperatingSystemFamily
Namespace: Greenlight\Condition
Compares the value to PHP_OS_FAMILY without case sensitivity.
final readonly class OperatingSystemFamily implements Condition
__construct()
public function __construct(string $family)
PHPDoc:
@throws \InvalidArgumentException
isSatisfied()
[\Override]
public function isSatisfied(): bool
PhpVersionAtLeast
Namespace: Greenlight\Condition
final readonly class PhpVersionAtLeast implements Condition
__construct()
public function __construct(string $version)
PHPDoc:
@throws \InvalidArgumentException
isSatisfied()
[\Override]
public function isSatisfied(): bool
PhpVersionLessThan
Namespace: Greenlight\Condition
final readonly class PhpVersionLessThan implements Condition
__construct()
public function __construct(string $version)
PHPDoc:
@throws \InvalidArgumentException
isSatisfied()
[\Override]
public function isSatisfied(): bool