Skip to content

Commit 3eb7cbc

Browse files
committed
Throw invalid argument exception if request is not found
1 parent 708c447 commit 3eb7cbc

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

spec/BatchResultSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function it_has_a_response_for_a_request(RequestInterface $request, ResponseInte
3636
{
3737
$new = $this->addResponse($request, $response);
3838

39-
$this->getResponseFor($request)->shouldReturn(null);
39+
$this->shouldThrow('Http\Client\Exception\InvalidArgumentException')->duringGetResponseFor($request);
4040
$this->hasResponseFor($request)->shouldReturn(false);
4141
$new->getResponseFor($request)->shouldReturn($response);
4242
$new->hasResponseFor($request)->shouldReturn(true);

spec/Exception/BatchExceptionSpec.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function it_throws_an_exception_if_the_result_is_already_set()
3434

3535
function it_has_an_exception_for_a_request(RequestInterface $request, Exception $exception)
3636
{
37-
$this->getExceptionFor($request)->shouldReturn(null);
37+
$this->shouldThrow('Http\Client\Exception\InvalidArgumentException')->duringGetExceptionFor($request);
3838
$this->hasExceptionFor($request)->shouldReturn(false);
3939

4040
$this->addException($request, $exception);

src/BatchResult.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Http\Client;
44

5+
use Http\Client\Exception\InvalidArgumentException;
56
use Psr\Http\Message\RequestInterface;
67
use Psr\Http\Message\ResponseInterface;
78

@@ -39,17 +40,21 @@ public function getResponses()
3940
}
4041

4142
/**
42-
* Returns a response of a request or null if not found
43+
* Returns a response of a request
4344
*
4445
* @param RequestInterface $request
4546
*
46-
* @return ResponseInterface|null
47+
* @return ResponseInterface
48+
*
49+
* @throws InvalidArgumentException
4750
*/
4851
public function getResponseFor(RequestInterface $request)
4952
{
50-
if ($this->responses->contains($request)) {
51-
return $this->responses[$request];
53+
if (!$this->responses->contains($request)) {
54+
throw new InvalidArgumentException('No response can be found for the given request');
5255
}
56+
57+
return $this->responses[$request];
5358
}
5459

5560
/**

src/Exception/BatchException.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,21 @@ public function getExceptions()
105105
}
106106

107107
/**
108-
* Returns an exception for a request or null if not found
108+
* Returns an exception for a request
109109
*
110110
* @param RequestInterface $request
111111
*
112-
* @return Exception|null
112+
* @return Exception
113+
*
114+
* @throws InvalidArgumentException
113115
*/
114116
public function getExceptionFor(RequestInterface $request)
115117
{
116-
if ($this->exceptions->contains($request)) {
117-
return $this->exceptions[$request];
118+
if (!$this->exceptions->contains($request)) {
119+
throw new InvalidArgumentException('No exception can be found for the given request');
118120
}
121+
122+
return $this->exceptions[$request];
119123
}
120124

121125
/**

0 commit comments

Comments
 (0)