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] Call on_stats handler in Http stub callbacks #37738

Merged

Conversation

funkjedi
Copy link
Contributor

This updates the Http::fake() method to call the on_stats handler if possible when executing the stub callbacks. This change ensures that transferStats property gets populated on the faked Http response.

The transferStats property is a critical/vital component to some production code as it provides access to the underlying request that precipitated the response. For example if you have the following mixin.

use Psr\Http\Message\RequestInterface;

/** @mixin \Illuminate\Http\Client\Response */
class ResponseMixin
{
    public function getRequest()
    {
        return function (): ?RequestInterface {
            return optional($this->transferStats)->getRequest();
        };
    }
}

If the transferStats property is always null any code which is dependant on getting the request in this fashion becomes untestable without additional stubbing to call the on_stats handler.

@GrahamCampbell GrahamCampbell changed the title Call on_stats handler in Http stub callbacks [8.x] Call on_stats handler in Http stub callbacks Jun 19, 2021
@taylorotwell taylorotwell merged commit 7acafac 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