Fixtures and harness API
This reference lists fixtures and harness service contracts.
These signatures are the public API.
EnvironmentSandbox
Namespace: Greenlight\Fixture
Updates getenv(), $_ENV, and $_SERVER together. It records each original
value one time and restores the value during disposal.
final class EnvironmentSandbox implements Disposable
set()
public function set(string $name, string $value): void
PHPDoc:
@throws \InvalidArgumentException If $name is invalid or $value contains a null byte.
unset()
public function unset(string $name): void
PHPDoc:
@throws \InvalidArgumentException If $name is empty or contains "=" or a null byte.
dispose()
[\Override]
public function dispose(): void
TempDirectory
Namespace: Greenlight\Fixture
Creates one root directory on first use. A path inside it cannot escape the root. Disposal removes a symbolic link and leaves its target unchanged.
final class TempDirectory implements Disposable
path()
public function path(): string
subdirectory()
public function subdirectory(string $name): string
PHPDoc:
@param string $name A relative path of plain segments. The path can contain separators but cannot contain traversal segments.@return non-empty-string
dispose()
[\Override]
public function dispose(): void
Disposable
Namespace: Greenlight\Harness
A harness service that Greenlight disposes when its service scope closes.
Greenlight disposes services in reverse creation order. An exception from one service does not prevent disposal of the remaining services.
interface Disposable
dispose()
public function dispose(): void;
Scope
Namespace: Greenlight\Harness
Defines the lifetime of a harness service.
PerRun matches the worker lifetime.
enum Scope: string
PerTest
case PerTest = 'per-test';
PerClass
case PerClass = 'per-class';
PerSuite
case PerSuite = 'per-suite';
PerRun
case PerRun = 'per-run';
ServiceDefinition
Namespace: Greenlight\Harness
Defines one harness service. It contains the exact injected type, service scope, and factory.
final readonly class ServiceDefinition
$type
public string $type;
PHPDoc:
@var class-string
__construct()
public function __construct(
string $type,
public Scope $scope,
public \Closure $factory,
)
PHPDoc:
@template T of object@param class-string<T>|'' $type@param \Closure(): T $factory@throws \InvalidArgumentException
ServiceResolver
Namespace: Greenlight\Harness
Greenlight calls service resolvers in registration order. If a resolver returns null, Greenlight calls the next resolver. A nonnull result must have the requested type.
Objects from a service resolver do not belong to a harness service scope. Greenlight does not dispose them. The source of an object controls its lifetime.
interface ServiceResolver
resolve()
public function resolve(string $type, array $attributes): ?object;
PHPDoc:
@param class-string $type@param list<object> $attributes