Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Drivers/LaravelHttpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ private function handleRequest(AmpRequest $request): Response

$debug = config('app.debug');

// This server reuses one container across a test's requests, so scoped() bindings must be
// released per request (as FPM and Octane do) — otherwise they leak like singletons.
app()->forgetScopedInstances();

try {
config(['app.debug' => false]);

Expand Down
14 changes: 14 additions & 0 deletions tests/Unit/Drivers/Laravel/LaravelHttpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,17 @@
visit('/server-variables')
->assertSee('"test-server-key":"test value"');
});

it('flushes scoped container bindings between requests', function (): void {
// A scoped() binding is released only by Application::forgetScopedInstances(). Since this
// server reuses one container across a test's requests, it must flush per request — otherwise
// the instance resolved in the first request leaks into the second (and would behave like a
// singleton), unlike FPM or Octane. Each request renders the resolved object's id; they differ.
app()->scoped('scoped-probe', fn (): object => new stdClass);
Route::get('/scoped-probe', fn (): string => spl_object_hash(app('scoped-probe')));

$first = visit('/scoped-probe')->content();
$second = visit('/scoped-probe')->content();

expect($first)->not->toBe($second);
});