Sandbox API
This reference lists the sandboxes that isolate temporary test state.
These signatures are the public API.
Autoloaders
Namespace: Greenlight\Sandbox
Registers autoloaders and unregisters them when the test scope closes.
final class Autoloaders implements Disposable
register()
public function register(callable $autoloader): void
PHPDoc:
@param callable(string): void $autoloader
dispose()
public function dispose(): void
EnvironmentVariables
Namespace: Greenlight\Sandbox
Updates getenv(), $_ENV, and $_SERVER together. It records each original
value one time and restores the value during disposal.
final class EnvironmentVariables 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()
public function dispose(): void
StreamWrapperError
Namespace: Greenlight\Sandbox
A stream-wrapper sandbox cannot register or unregister a wrapper.
final class StreamWrapperError extends \RuntimeException
registrationFailed()
public static function registrationFailed(
string $scheme,
?string $warning,
?\Throwable $previous = null,
): self
unregistrationFailed()
public static function unregistrationFailed(array $failures): self
PHPDoc:
@param non-empty-list<array{non-empty-string, string|null}> $failures
StreamWrappers
Namespace: Greenlight\Sandbox
Registers stream wrappers and unregisters them when the test scope closes.
final class StreamWrappers implements Disposable
register()
public function register(string $scheme, string $wrapper): void
PHPDoc:
@param non-empty-string $scheme@param class-string $wrapper@throws \InvalidArgumentException if the scheme is empty@throws StreamWrapperError
dispose()
public function dispose(): void
PHPDoc:
@throws StreamWrapperError
TemporaryDirectory
Namespace: Greenlight\Sandbox
Creates one root directory on first use. subdirectory() rejects traversal
segments and symbolic links in the requested path.
Disposal removes a symbolic link and leaves its target unchanged.
final class TemporaryDirectory implements Disposable
__construct()
public function __construct(?string $temporaryRoot = null)
PHPDoc:
@throws \InvalidArgumentException If $temporaryRoot contains a null byte.
path()
public function path(): string
PHPDoc:
@throws TemporaryDirectoryError
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@throws \InvalidArgumentException@throws TemporaryDirectoryError
dispose()
public function dispose(): void
PHPDoc:
@throws TemporaryDirectoryError
TemporaryDirectoryError
Namespace: Greenlight\Sandbox
A temporary-directory operation cannot create, validate, or remove a path.
final class TemporaryDirectoryError extends \RuntimeException
rootCreationFailed()
public static function rootCreationFailed(string $path, ?string $warning): self
subdirectoryCreationFailed()
public static function subdirectoryCreationFailed(string $path, ?string $warning): self
symbolicLink()
public static function symbolicLink(string $path): self
rootLinkRemovalFailed()
public static function rootLinkRemovalFailed(string $path, ?string $warning): self
entryRemovalFailed()
public static function entryRemovalFailed(string $entry, string $root): self
rootRemovalFailed()
public static function rootRemovalFailed(string $path, ?string $warning): self