Skip to content

Add method to get last request sent #23

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions spec/HttpMethodsClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ function it_sends_request_with_underlying_client(HttpClient $client, MessageFact
$this->beConstructedWith($client, $messageFactory);
$this->sendRequest($request)->shouldReturn($response);
}

function it_returns_last_request(HttpClient $client, MessageFactory $messageFactory, RequestInterface $request, ResponseInterface $response)
{
$client->sendRequest($request)->shouldBeCalled()->willReturn($response);

$this->beConstructedWith($client, $messageFactory);
$this->getLastRequest()->shouldReturn(null);
$this->sendRequest($request)->shouldReturn($response);
$this->getLastRequest()->shouldReturn($request);
}
}

class HttpMethodsClientStub extends HttpMethodsClient
Expand Down
19 changes: 19 additions & 0 deletions src/HttpMethodsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ class HttpMethodsClient implements HttpClient
*/
private $messageFactory;

/**
* @var RequestInterface
*/
private $lastRequest;

/**
* @param HttpClient $httpClient The client to send requests with.
* @param MessageFactory $messageFactory The message factory to create requests.
Expand Down Expand Up @@ -200,6 +205,20 @@ public function send($method, $uri, array $headers = [], $body = null)
*/
public function sendRequest(RequestInterface $request)
{
$this->lastRequest = $request;

return $this->httpClient->sendRequest($request);
}

/**
* Get the last request that was sent via this client.
*
* Note that this will not return requests made directly through the underlying client's sendRequest method.
*
* @return RequestInterface|null
*/
public function getLastRequest()
{
return $this->lastRequest;
}
}