Greenlight

Documentation

API reference

On this page

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

View source

Worker

One container belongs to one physical Greenlight worker.

case Worker;

View source

TestAttempt

One container belongs to one test attempt.

case TestAttempt;

View source

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

View source

__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:

View source

source()

public function source(): ?string

View source

services()

public function services(): array

PHPDoc:

View source

resolve()

public function resolve(string $type, array $attributes): ?object

PHPDoc:

View source

onWorkerBootstrap()

public function onWorkerBootstrap(WorkerBootstrapContext $context): void

PHPDoc:

View source

runWorker()

public function runWorker(\Closure $worker): mixed

PHPDoc:

View source

runTestAttempt()

public function runTestAttempt(\Closure $attempt): mixed

PHPDoc:

View source

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

View source

__construct()

public function __construct(
    string|\Closure $application,
    private readonly string $env = 'testing',
    private readonly bool $refreshBetweenTests = true,
    ?string $source = null,
)

PHPDoc:

View source

source()

public function source(): ?string

View source

services()

public function services(): array

PHPDoc:

View source

resolve()

public function resolve(string $type, array $attributes): ?object

PHPDoc:

View source

afterTest()

public function afterTest(TestContext $context, TestResult $result): TestResult

View source

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

View source

__construct()

public function __construct(
    private readonly \Closure $factory,
    private readonly bool $refreshBetweenTests = true,
    private readonly ?\Closure $reset = null,
    ?string $source = null,
)

PHPDoc:

View source

source()

public function source(): ?string

View source

services()

public function services(): array

PHPDoc:

View source

resolve()

public function resolve(string $type, array $attributes): ?object

PHPDoc:

View source

afterTest()

public function afterTest(TestContext $context, TestResult $result): TestResult

PHPDoc:

View source

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

View source

__construct()

public function __construct(
    RequestHandlerInterface|\Closure $handler,
    private readonly ?\Closure $release = null,
)

PHPDoc:

View source

send()

public function send(ServerRequestInterface $request): ResponseInterface

PHPDoc:

View source

dispose()

public function dispose(): void

PHPDoc:

View source

Psr15Error

Namespace: Greenlight\Psr15

Reports a PSR-15 harness failure at its public seam.

final class Psr15Error extends \RuntimeException

View source

factoryFailed()

public static function factoryFailed(\Throwable $cause): self

View source

invalidHandler()

public static function invalidHandler(mixed $handler): self

View source

requestFailed()

public static function requestFailed(
    string $method,
    string $path,
    mixed $handler,
    \Throwable $cause,
): self

View source

releaseFailed()

public static function releaseFailed(mixed $handler, \Throwable $cause): self

View source

disposed()

public static function disposed(): self

View source

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

View source

__construct()

public function __construct(
    RequestHandlerInterface|\Closure $handler,
    private Scope $scope = Scope::PerTest,
    private ?\Closure $release = null,
)

PHPDoc:

View source

services()

public function services(): array

PHPDoc:

View source

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

View source

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';

View source

configure()

public function configure(array $configuration): void

PHPDoc:

View source

getRuleDefinition()

public function getRuleDefinition(): RuleDefinition

View source

getNodeTypes()

public function getNodeTypes(): array

PHPDoc:

View source

refactor()

public function refactor(Node $node): ?Node

View source

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

View source

__construct()

public function __construct(
    string|\Closure $kernel,
    string $env = 'test',
    bool $debug = false,
    private readonly bool $resetBetweenTests = true,
    ?string $source = null,
)

PHPDoc:

View source

source()

public function source(): ?string

View source

services()

public function services(): array

PHPDoc:

View source

resolve()

public function resolve(string $type, array $attributes): ?object

PHPDoc:

View source

afterTest()

public function afterTest(TestContext $context, TestResult $result): TestResult

View source

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

View source

__construct()

public function __construct(
    private readonly string $root,
    private readonly string $environment = 'testing',
    private readonly array $discoveryLocations = [],
    ?string $source = null,
)

PHPDoc:

View source

source()

public function source(): ?string

View source

onWorkerBootstrap()

public function onWorkerBootstrap(WorkerBootstrapContext $context): void

View source

services()

public function services(): array

PHPDoc:

View source

resolve()

public function resolve(string $type, array $attributes): object

PHPDoc:

View source

beforeTest()

public function beforeTest(TestContext $context): void

View source

afterTest()

public function afterTest(TestContext $context, TestResult $result): TestResult

PHPDoc:

View source