Skip to content

Context not flushed on a test HTTP request #57776

@alecpl

Description

@alecpl

Laravel Version

11.46.1

PHP Version

8.2.29

Database Driver & Version

No response

Description

I'm using Laravel Context in my controller via Context::addHidden() and Context::getHidden(). Then in tests I execute HTTP requests multiple times in one test method.

$this->call($method, $url, [], [], [], $server, $xml);

I suppose the issue will be also with post, get and other methods.

And the issue is that context data is not flushed between requests. So, a value added to Context in the first request is accessible in the following ones.

I can workaround that by using Context::flush() before every request made in tests, but I think it might be a bug that needs a fix.

Steps To Reproduce

In a route handler do

use Illuminate\Support\Facades\Context;

echo Context::getHidden('test');
Context::addHidden('test', 'test');

In a test make two HTTP requests to this route. The second request will output 'test', but it should not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions