Integration API
This reference lists public integration types for Hyperf, Laravel, PSR standards, Rector, Symfony, and Tempest.
These signatures are the public API.
ContainerLifetime
Namespace: Greenlight\Hyperf
Selects the lifetime of the Hyperf application container.
enum ContainerLifetime
Worker
One container belongs to one physical Greenlight worker.
case Worker;
TestAttempt
One container belongs to one test attempt.
case TestAttempt;
HyperfPlugin
Namespace: Greenlight\Hyperf
Initializes the Hyperf class loader once in each worker. It creates a coroutine context for each test attempt.
The default worker container lifetime matches a long-running Hyperf worker.
#[Service] selects a container ID or a named source. Isolate external test
resources by GREENLIGHT_CHANNEL.
Requires hyperf/framework and hyperf/di 3.2. It also requires Swoole 5
or later and the pcntl extension. It does not support Swow.
final class HyperfPlugin implements HarnessProvider, ServiceResolver, ServiceSource, TestAttemptRunner, WorkerBootstrapSubscriber, WorkerRuntimeRunner
__construct()
public function __construct(
string $basePath,
private readonly ContainerLifetime $containerLifetime = ContainerLifetime::Worker,
private readonly ?\Closure $reset = null,
private readonly ?\Closure $dispose = null,
private readonly ?int $hookFlags = null,
?string $source = null,
)
PHPDoc:
@param null|\Closure(ContainerInterface): void $reset Resets project-owned request state after each test attempt. The callback runs inside the test coroutine.@param null|\Closure(ContainerInterface): void $dispose Releases project-owned resources when the selected container lifetime ends. The callback runs inside a coroutine.@throws \InvalidArgumentException
source()
public function source(): ?string
services()
public function services(): array
PHPDoc:
@return list<ServiceDefinition>
resolve()
public function resolve(string $type, array $attributes): ?object
PHPDoc:
@param class-string $type@param list<object> $attributes@throws ServiceResolutionFailed
onWorkerBootstrap()
public function onWorkerBootstrap(WorkerBootstrapContext $context): void
PHPDoc:
@throws ServiceResolutionFailed
runWorker()
public function runWorker(\Closure $worker): mixed
PHPDoc:
@template T@param \Closure(): T $worker@return T@throws ServiceResolutionFailed
runTestAttempt()
public function runTestAttempt(\Closure $attempt): mixed
PHPDoc:
@template T@param \Closure(): T $attempt@return T@throws ServiceResolutionFailed
LaravelPlugin
Namespace: Greenlight\Laravel
Boots a Laravel application on first use and resolves bound services. By default, Greenlight releases the application after each test attempt.
#[Service] selects a binding ID or a named source. Isolate external test resources
by GREENLIGHT_CHANNEL.
final class LaravelPlugin implements AfterTestSubscriber, HarnessProvider, ServiceResolver, ServiceSource
__construct()
public function __construct(
string|\Closure $application,
private readonly string $env = 'testing',
private readonly bool $refreshBetweenTests = true,
?string $source = null,
)
PHPDoc:
@param string|\Closure(): Application $application A path to a file that returns the application, usually bootstrap/app.php. For other application setup, pass a closure that returns the application.@param non-empty-string $env@param bool $refreshBetweenTests Set to false only when no service keeps state between tests. Tests on one worker then share one application without resets.@throws \InvalidArgumentException
source()
public function source(): ?string
services()
public function services(): array
PHPDoc:
@return list<ServiceDefinition>
resolve()
public function resolve(string $type, array $attributes): ?object
PHPDoc:
@param class-string $type@param list<object> $attributes@throws ServiceResolutionFailed
afterTest()
public function afterTest(TestContext $context, TestResult $result): TestResult
Psr11Plugin
Namespace: Greenlight\Psr11
Creates a PSR-11 container lazily and resolves its services. By default, the plugin discards the container after each test that uses it.
#[Service] selects a service ID or a named source. Isolate external test resources by
GREENLIGHT_CHANNEL.
final class Psr11Plugin implements AfterTestSubscriber, HarnessProvider, ServiceResolver, ServiceSource
__construct()
public function __construct(
private readonly \Closure $factory,
private readonly bool $refreshBetweenTests = true,
private readonly ?\Closure $reset = null,
?string $source = null,
)
PHPDoc:
@param \Closure():ContainerInterface $factory A factory that returns the application container.@param bool $refreshBetweenTests Set to false only when the reset callback removes all container state, or when services do not keep state.@param (\Closure(ContainerInterface): void)|null $reset An optional callback that resets the active container after each test.@throws \InvalidArgumentException
source()
public function source(): ?string
services()
public function services(): array
PHPDoc:
@return list<ServiceDefinition>
resolve()
public function resolve(string $type, array $attributes): ?object
PHPDoc:
@param class-string $type@param list<object> $attributes@throws ServiceResolutionFailed
afterTest()
public function afterTest(TestContext $context, TestResult $result): TestResult
PHPDoc:
@throws ServiceResolutionFailed
HttpHarness
Namespace: Greenlight\Psr15
Sends PSR-7 server requests directly to one PSR-15 request handler. If a factory supplies the handler, the first request creates it.
Disposal calls the optional release callback only if a handler exists.
final class HttpHarness implements Disposable
__construct()
public function __construct(
RequestHandlerInterface|\Closure $handler,
private readonly ?\Closure $release = null,
)
PHPDoc:
@param RequestHandlerInterface|\Closure(): RequestHandlerInterface $handler@param null|\Closure(RequestHandlerInterface): void $release
send()
public function send(ServerRequestInterface $request): ResponseInterface
PHPDoc:
@throws Psr15Error
dispose()
public function dispose(): void
PHPDoc:
@throws Psr15Error
Psr15Error
Namespace: Greenlight\Psr15
Reports a PSR-15 harness failure at its public seam.
final class Psr15Error extends \RuntimeException
factoryFailed()
public static function factoryFailed(\Throwable $cause): self
invalidHandler()
public static function invalidHandler(mixed $handler): self
requestFailed()
public static function requestFailed(
string $method,
string $path,
mixed $handler,
\Throwable $cause,
): self
releaseFailed()
public static function releaseFailed(mixed $handler, \Throwable $cause): self
disposed()
public static function disposed(): self
Psr15Plugin
Namespace: Greenlight\Psr15
Supplies one HTTP harness in the configured service scope. Each harness calls its handler factory on the first request.
For a new application handler in each test attempt, use the per-test scope. Supply a factory that creates a new handler each time.
final readonly class Psr15Plugin implements HarnessProvider
__construct()
public function __construct(
RequestHandlerInterface|\Closure $handler,
private Scope $scope = Scope::PerTest,
private ?\Closure $release = null,
)
PHPDoc:
@param RequestHandlerInterface|\Closure(): RequestHandlerInterface $handler A handler or a factory that returns a handler.@param null|\Closure(RequestHandlerInterface): void $release A callback that releases the active handler when its scope closes.
services()
public function services(): array
PHPDoc:
@return list<ServiceDefinition>
PhpUnitToGreenlightRector
Namespace: Greenlight\Rector
Converts a final PHPUnit test class to Greenlight: the TestCase parent,
lifecycle hooks, attributes, assertions, and expectException() blocks. The
rule converts a class only when every member has a faithful Greenlight
equivalent. It does not change other classes.
final class PhpUnitToGreenlightRector extends AbstractRector implements ConfigurableRectorInterface, DocumentedRuleInterface
DROP_ASSERTION_MESSAGES
Configuration key: remove PHPUnit failure-message arguments. Without
this option, a custom message rejects the class. A manual migration can
preserve the message with because().
public const string DROP_ASSERTION_MESSAGES = 'drop_assertion_messages';
configure()
public function configure(array $configuration): void
PHPDoc:
@param mixed[] $configuration@throws \InvalidArgumentException if a key is unknown or \drop_assertion_messages` is not a boolean`
getRuleDefinition()
public function getRuleDefinition(): RuleDefinition
getNodeTypes()
public function getNodeTypes(): array
PHPDoc:
@return array<class-string<Node>>
refactor()
public function refactor(Node $node): ?Node
SymfonyPlugin
Namespace: Greenlight\Symfony
Greenlight boots the kernel when it is first necessary. The kernel then stays active for the worker lifetime.
The container must expose Symfony’s test container. If the configuration
does not disable resets, the container must expose services_resetter. If a
service keeps state between tests, do not disable resets.
#[Service] selects a service ID or a named source. Isolate external
resources with GREENLIGHT_CHANNEL.
final class SymfonyPlugin implements AfterTestSubscriber, HarnessProvider, ServiceResolver, ServiceSource
__construct()
public function __construct(
string|\Closure $kernel,
string $env = 'test',
bool $debug = false,
private readonly bool $resetBetweenTests = true,
?string $source = null,
)
PHPDoc:
@param class-string<KernelInterface>|\Closure(): KernelInterface $kernel A kernel class name that Greenlight constructs as new $kernel($env, $debug), or a closure that constructs the kernel. Use a closure for other constructor requirements.@param non-empty-string $env@param bool $resetBetweenTests For a container without stateful services, use false to disable resets. Tests on one worker then reuse the container without resets. Symfony service configuration determines which instances are shared.@throws \InvalidArgumentException
source()
public function source(): ?string
services()
public function services(): array
PHPDoc:
@return list<ServiceDefinition>
resolve()
public function resolve(string $type, array $attributes): ?object
PHPDoc:
@param class-string $type@param list<object> $attributes@throws ServiceResolutionFailed
afterTest()
public function afterTest(TestContext $context, TestResult $result): TestResult
TempestPlugin
Namespace: Greenlight\Tempest
Boots one Tempest long-running kernel for each worker. Tempest discovery, configuration, container reset, deferred tasks, and shutdown events stay under kernel control.
The bridge uses the testing environment by default. #[Service] selects
a tagged Tempest binding.
Isolate external test resources by GREENLIGHT_CHANNEL.
final class TempestPlugin implements AfterTestSubscriber, BeforeTestSubscriber, HarnessProvider, ServiceSource, TerminalServiceResolver, WorkerBootstrapSubscriber
__construct()
public function __construct(
private readonly string $root,
private readonly string $environment = 'testing',
private readonly array $discoveryLocations = [],
?string $source = null,
)
PHPDoc:
@param string $root The directory that contains the Tempest composer.json file.@param list<DiscoveryLocation> $discoveryLocations Additional locations for Tempest discovery.@throws \InvalidArgumentException
source()
public function source(): ?string
onWorkerBootstrap()
public function onWorkerBootstrap(WorkerBootstrapContext $context): void
services()
public function services(): array
PHPDoc:
@return list<ServiceDefinition>
resolve()
public function resolve(string $type, array $attributes): object
PHPDoc:
@param class-string $type@param list<object> $attributes@throws ServiceResolutionFailed
beforeTest()
public function beforeTest(TestContext $context): void
afterTest()
public function afterTest(TestContext $context, TestResult $result): TestResult
PHPDoc:
@throws ServiceResolutionFailed