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

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

Merged
merged 3 commits into from
Feb 18, 2025

Conversation

chester-sykes
Copy link
Contributor

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

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
3 of 4 checks passed
@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