Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpAssertSent fails when using withMiddleware() with a middleware that modifies the request #47613

Closed
j3j5 opened this issue Jun 29, 2023 · 0 comments · Fixed by #47614
Closed

Comments

@j3j5
Copy link
Contributor

j3j5 commented Jun 29, 2023

Laravel Version

10.4.1

PHP Version

8.2.7

Database Driver & Version

No response

Description

If you provide middleware that modifies the request on your Http client when using Http::fake(), you can't use Http::assertSent() to test the modifications because the recorder handler is added to the stack before the middlewares are.

I've created a PR on #47614 that should fix this.

Steps To Reproduce

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     */
    public function test_example(): void
    {
        Http::fake();

        $url = 'https://example.com';
        $data = [];
        $response = Http::withMiddleware(
            Middleware::mapRequest(fn(RequestInterface $request) => $request->withHeader('X-Header-A', 'A'))
        )->post($url, $data);

        Http::assertSent(function (Request $request) {
            return $request->hasHeader('X-Header-A', 'A');
        });

    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant