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] Add dd() method to TestResponse class #36378

Closed
wants to merge 1 commit into from
Closed

[8.x] Add dd() method to TestResponse class #36378

wants to merge 1 commit into from

Conversation

duncanmcclean
Copy link
Contributor

@duncanmcclean duncanmcclean commented Feb 24, 2021

This PR adds a new dd method to the fluent TestResponse class.

Example

Previously... you'd have to comment out any assertions at the end of your chain, assign it to a variable and finally actually dd it.

$response = $this
  ->get('/posts');
//  ->assertOk()
//  ->assertSee('foo');

dd($response);

Now... with this PR, you'll be able to simply add the ->dd() method anywhere in your chain and the HTTP response will be die dumped.

$this
  ->get('/posts')
  ->dd()
  ->assertOk()
  ->assertSee('foo');

I've reviewed the dd methods available in other places in the codebase, like in the Builder class and the Stringable class and I couldn't find any tests that cover the dd method so I was unsure on how to actually add tests for this addition. Please let me know if I've missed anything.

@duncanmcclean duncanmcclean changed the title Add dd method to TestResponse Add dd() method to TestResponse class Feb 24, 2021
@GrahamCampbell GrahamCampbell changed the title Add dd() method to TestResponse class [8.x] Add dd() method to TestResponse class Feb 24, 2021
@GrahamCampbell
Copy link
Member

You should probably have this instead call the dump method.

Also, I think this will make a mess for parallel testing... // cc @nunomaduro

@derekmd
Copy link
Contributor

derekmd commented Feb 24, 2021

You should probably have this instead call the dump method.

A TestResponse@dump() method already exists:

/**
* Dump the content from the response.
*
* @return $this
*/
public function dump()
{
$content = $this->getContent();
$json = json_decode($content);
if (json_last_error() === JSON_ERROR_NONE) {
$content = $json;
}
dump($content);
return $this;
}

That method originally called dd() but it was changed to dump() to allow database teardown, PHPUnit script cleanup, etc.

To short-circuit a test being dumped, maybe throwing a PHPUnit\Framework\SkippedTestError exception is more appropriate instead of calling dd() which immediately exits the test runner.

@taylorotwell
Copy link
Member

I would just call dump() and run that single test.

@duncanmcclean duncanmcclean deleted the add-dd-method-to-http-testing-chain branch February 24, 2021 22:10
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.

4 participants