Skip to content

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