Skip to content

[11.x] new: ddJson method on TestResponse class#54673

Merged
taylorotwell merged 3 commits into
laravel:11.xfrom
chester-sykes:new/dd-json
Feb 18, 2025
Merged

[11.x] new: ddJson method on TestResponse class#54673
taylorotwell merged 3 commits into
laravel:11.xfrom
chester-sykes:new/dd-json

Conversation

@chester-sykes

@chester-sykes chester-sykes commented Feb 18, 2025

Copy link
Copy Markdown
Contributor

This PR adds a ddJson() method to the TestResponse class. This is a dd() wrapper around the existing json() which would be very handy if you just want to quickly see what the json response is when writing tests.

Instead of doing this:

$response = $this->getJson('/api/test-api');

dd($response->json());

you could just do this:

$this->getJson('/api/test-api')->ddJson();

I wasn't sure it was possible to write a test for this because the function uses dd() but if it is possible could someone please explain how to do it and I'll add a test.

The benefit of this is to reduce the time it takes to see the result of the response when testing, instead of having to use a variable. it won't break any existing logic as its a new function.

@taylorotwell taylorotwell merged commit 3fa65d9 into laravel:11.x Feb 18, 2025
@chester-sykes chester-sykes deleted the new/dd-json branch February 18, 2025 15:27
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