Skip to content
This repository was archived by the owner on Jan 16, 2018. It is now read-only.

Commit 1c6d0e1

Browse files
committed
adjust BatchResult to interface cleanup
1 parent a3e6280 commit 1c6d0e1

File tree

2 files changed

+32
-45
lines changed

2 files changed

+32
-45
lines changed

spec/BatchResultSpec.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,21 @@ function it_has_a_response_for_a_request(RequestInterface $request, ResponseInte
3939
$new = $this->addResponse($request, $response);
4040

4141
$this->shouldThrow('UnexpectedValueException')->duringGetResponseFor($request);
42-
$this->hasResponseFor($request)->shouldReturn(false);
42+
$this->isSuccessful($request)->shouldReturn(false);
4343
$new->getResponseFor($request)->shouldReturn($response);
44-
$new->hasResponseFor($request)->shouldReturn(true);
44+
$new->isSuccessful($request)->shouldReturn(true);
4545
}
4646

4747
function it_keeps_exception_after_add_request(RequestInterface $request1, Exception $exception, RequestInterface $request2, ResponseInterface $response)
4848
{
4949
$new = $this->addException($request1, $exception);
5050
$new = $new->addResponse($request2, $response);
5151

52+
$new->isSuccessful($request2)->shouldReturn(true);
53+
$new->isFailed($request2)->shouldReturn(false);
5254
$new->getResponseFor($request2)->shouldReturn($response);
55+
$new->isSuccessful($request1)->shouldReturn(false);
56+
$new->isFailed($request1)->shouldReturn(true);
5357
$new->getExceptionFor($request1)->shouldReturn($exception);
5458
}
5559
}

src/BatchResult.php

Lines changed: 26 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Http\Client\BatchResult as BatchResultInterface;
77
use Psr\Http\Message\RequestInterface;
88
use Psr\Http\Message\ResponseInterface;
9-
use UnexpectedValueException;
109

1110
/**
1211
* Responses and exceptions returned from parallel request execution
@@ -31,6 +30,14 @@ public function __construct()
3130
$this->exceptions = new \SplObjectStorage();
3231
}
3332

33+
/**
34+
* {@inheritDoc}
35+
*/
36+
public function hasResponses()
37+
{
38+
return $this->responses->count() > 0;
39+
}
40+
3441
/**
3542
* {@inheritDoc}
3643
*/
@@ -48,29 +55,21 @@ public function getResponses()
4855
/**
4956
* {@inheritDoc}
5057
*/
51-
public function getResponseFor(RequestInterface $request)
52-
{
53-
try {
54-
return $this->responses[$request];
55-
} catch (\UnexpectedValueException $e) {
56-
throw new \UnexpectedValueException('Request not found', $e->getCode(), $e);
57-
}
58-
}
59-
60-
/**
61-
* {@inheritDoc}
62-
*/
63-
public function hasResponses()
58+
public function isSuccessful(RequestInterface $request)
6459
{
65-
return $this->responses->count() > 0;
60+
return $this->responses->contains($request);
6661
}
6762

6863
/**
6964
* {@inheritDoc}
7065
*/
71-
public function hasResponseFor(RequestInterface $request)
66+
public function getResponseFor(RequestInterface $request)
7267
{
73-
return $this->responses->contains($request);
68+
try {
69+
return $this->responses[$request];
70+
} catch (\UnexpectedValueException $e) {
71+
throw new \UnexpectedValueException('Request not found', $e->getCode(), $e);
72+
}
7473
}
7574

7675
/**
@@ -87,17 +86,9 @@ public function addResponse(RequestInterface $request, ResponseInterface $respon
8786
/**
8887
* {@inheritDoc}
8988
*/
90-
public function isSuccessful(RequestInterface $request)
91-
{
92-
return $this->responses->contains($request);
93-
}
94-
95-
/**
96-
* {@inheritDoc}
97-
*/
98-
public function isFailed(RequestInterface $request)
89+
public function hasExceptions()
9990
{
100-
return $this->exceptions->contains($request);
91+
return $this->exceptions->count() > 0;
10192
}
10293

10394
/**
@@ -117,29 +108,21 @@ public function getExceptions()
117108
/**
118109
* {@inheritDoc}
119110
*/
120-
public function getExceptionFor(RequestInterface $request)
121-
{
122-
try {
123-
return $this->exceptions[$request];
124-
} catch (\UnexpectedValueException $e) {
125-
throw new UnexpectedValueException('Request not found', $e->getCode(), $e);
126-
}
127-
}
128-
129-
/**
130-
* {@inheritDoc}
131-
*/
132-
public function hasExceptions()
111+
public function isFailed(RequestInterface $request)
133112
{
134-
return $this->exceptions->count() > 0;
113+
return $this->exceptions->contains($request);
135114
}
136115

137116
/**
138117
* {@inheritDoc}
139118
*/
140-
public function hasExceptionFor(RequestInterface $request)
119+
public function getExceptionFor(RequestInterface $request)
141120
{
142-
return $this->exceptions->contains($request);
121+
try {
122+
return $this->exceptions[$request];
123+
} catch (\UnexpectedValueException $e) {
124+
throw new \UnexpectedValueException('Request not found', $e->getCode(), $e);
125+
}
143126
}
144127

145128
/**

0 commit comments

Comments
 (0)