cerbero/octane-testbench
A testbench for Laravel Octane applications, providing helpers to exercise Octane-specific request lifecycles and long-running worker behavior in your test suite. It helps you verify that your app behaves correctly under Octane's persistent workers and server integrations before deploying.
composer require --dev cerbero/octane-testbench. It is test-only tooling; nothing is added to your production runtime.config/octane.php), and your test environment needs whatever the selected driver requires (Swoole extension or the RoadRunner binary), because the package simulates Octane's worker lifecycle in-process rather than stubbing it out.Tests\OctaneTestCase) that pulls in the package's testing concern, and have only Octane-specific tests extend it. Regular feature tests are cheaper and less surprising without the Octane boot overhead.src/ first. The package is deliberately small — a handful of classes — and the README is terse. The source is the actual API documentation; you can read the whole thing in a few minutes.public function test_singleton_is_reset_between_requests(): void
{
$this->octane()->handle($this->makeRequest('/mutate'));
$response = $this->octane()->handle($this->makeRequest('/read-state'));
$this->assertSame('clean', $response->getContent());
}
(Check the trait for the exact method names; the package exposes worker boot, request handling, termination, and tick helpers rather than a full HTTP kernel.)
bootstrap → request → terminate → next request without a real Swoole server. Use it to test that listeners on Octane events (WorkerStarting, WorkerStopping, RequestReceived, RequestHandled, RequestTerminated, TickReceived, TaskReceived) actually fire and do what you expect.config/octane.php, then handle a simulated request and assert on side effects (a log write, a cache bump, an injected header) rather than on the presence of the event itself. Combining Event::fake() with Octane bootstrapping is fragile; prefer observable effects.Octane::tick(...) closures are otherwise almost impossible to unit test. Use the package to invoke a tick and assert the callback ran, the interval logic is honored, and the callback is idempotent.terminate middleware behavior under Octane semantics, where termination happens after the response is sent and the container is reused.Octane::concurrently(...), test that the task results merge correctly and that failures inside a task propagate the way you expect. The worker helpers let you exercise this without a live server.tests/Octane/) and a separate PHPUnit test suite so CI can run them only on the PHP/extension combination that matches production.phpunit image without Swoole will fail before your assertions run. Gate the suite in CI.composer.json and check compatibility with your Laravel/Octane major version before upgrading either.Event::fake() intercepts the very dispatch you're trying to observe. If you need to confirm a listener ran, assert the side effect; if you need to confirm an event was dispatched, use a targeted Event::fake([...]) that excludes the Octane events.warm/flush lists. If your listener isn't firing, verify it's actually registered in the config file the test resolves — cached config in the test bootstrap is a common culprit.src/ will show you exactly which Octane primitive to call yourself.How can I help you explore Laravel packages today?