Skip to content

Commit 407890d

Browse files
authored
Merge pull request #25 from adelplace/feature-clear-responses
Implement reset
2 parents 04d4829 + 9c69367 commit 407890d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

spec/ClientSpec.php

+22
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,26 @@ function it_returns_false_when_there_is_no_last_request()
8484
{
8585
$this->getLastRequest()->shouldReturn(false);
8686
}
87+
88+
function it_reset(
89+
ResponseFactory $responseFactory,
90+
RequestInterface $request,
91+
ResponseInterface $response,
92+
ResponseInterface $newResponse
93+
) {
94+
$this->addResponse($response);
95+
$this->setDefaultResponse($response);
96+
$this->addException(new \Exception());
97+
$this->setDefaultException(new \Exception());
98+
99+
$responseFactory->createResponse()->willReturn($newResponse);
100+
101+
$this->reset();
102+
103+
$this->sendRequest($request)->shouldReturn($newResponse);
104+
105+
$this->reset();
106+
107+
$this->getRequests()->shouldReturn([]);
108+
}
87109
}

src/Client.php

+9
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,13 @@ public function getLastRequest()
135135
{
136136
return end($this->requests);
137137
}
138+
139+
public function reset()
140+
{
141+
$this->responses = [];
142+
$this->exceptions = [];
143+
$this->requests = [];
144+
$this->setDefaultException();
145+
$this->setDefaultResponse();
146+
}
138147
}

0 commit comments

Comments
 (0)