laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

Add dd method to the testing HTTP chain #2511

Closed duncanmcclean closed 3 years ago

duncanmcclean commented 3 years ago

I've been writing some HTTP tests today and I've had an idea. I'm posting here to see if it's something others would be interested in..

Right now, when you're writing HTTP tests in Laravel and you want to dd (to debug the response), you'll have to assign your HTTP test chain to a variable and then do dd($response) or whatever.

$response = $this
  ->actingAs($user)
  ->post('/endpoint', $data);

dd($response);

This can sometimes be a bit annoying and tedious. Especially if you have methods that are added after the ->post(), like assertSee or assertRedirect as you have to comment those lines out, then add the semicolon into the right place. It's a faff (I think so anyway).

$response = $this
  ->actingAs($user)
  ->post('/endpoint', $data);
//  ->assertRedirect('/all-good');

dd($response);

However, to get round this, maybe Laravel could have a ->dd() method on the HTTP testing chain? Similar to the way it works with Collections, where it would die dump the response body for debugging.

$this
  ->actingAs($user)
  ->post('/endpoint', $data)
  ->dd()
  ->assertRedirect('/all-good');

Let me know what you think, if it's something people are interested in, I'm happy to look at PR'ing it into the framework.

duncanmcclean commented 3 years ago

Closing as I've opened a PR for this: laravel/framework#36378