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

[8.x] Make Illuminate\Http\Client\Request macroable #37744

Merged

Conversation

funkjedi
Copy link
Contributor

This PR makes the Illuminate\Http\Client\Request class macroable.

Having the Request macroable will allow for the elimination of excess boilerplate code when faking Http requests with body content other than Form or JSON, XML for example.

Request::macro('xml', function () {
    return CustomSuperDuperXmlParser::parse($this->body());
});

Http::fake([
    'example.com/*' => function (Request $request) {
        $this->assertSame($request->xml()->someProperty, 'some value')

        return Http::response();
    },
]);

@taylorotwell taylorotwell merged commit 02aff95 into laravel:8.x Jun 21, 2021
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 this pull request may close these issues.

2 participants