Skip to content

Commit 217c8c6

Browse files
committed
Last elements getters
1 parent 7b47440 commit 217c8c6

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

spec/ClientSpec.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,27 @@ function it_creates_an_empty_response_when_none_is_added(
5252

5353
$this->sendRequest($request)->shouldReturn($response);
5454
}
55+
56+
function it_returns_the_last_response(ResponseInterface $response)
57+
{
58+
$this->addResponse($response);
59+
60+
$this->getLastResponse()->shouldReturn($response);
61+
}
62+
63+
function it_returns_the_last_exception()
64+
{
65+
$exception = new \Exception();
66+
$this->addException($exception);
67+
68+
$this->getLastException()->shouldReturn($exception);
69+
}
70+
71+
72+
function it_returns_the_last_request(RequestInterface $request)
73+
{
74+
$this->sendRequest($request);
75+
76+
$this->getLastRequest()->shouldReturn($request);
77+
}
5578
}

src/Client.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,28 @@ public function getRequests()
100100
{
101101
return $this->requests;
102102
}
103+
104+
/**
105+
* @return RequestInterface|false
106+
*/
107+
public function getLastRequest()
108+
{
109+
return end($this->requests);
110+
}
111+
112+
/**
113+
* @return Exception|false
114+
*/
115+
public function getLastException()
116+
{
117+
return end($this->exceptions);
118+
}
119+
120+
/**
121+
* @return ResponseInterface|false
122+
*/
123+
public function getLastResponse()
124+
{
125+
return end($this->responses);
126+
}
103127
}

0 commit comments

Comments
 (0)