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

Commit 68986c7

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

File tree

2 files changed

+32
-44
lines changed

2 files changed

+32
-44
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 & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public function __construct()
3131
$this->exceptions = new \SplObjectStorage();
3232
}
3333

34+
/**
35+
* {@inheritDoc}
36+
*/
37+
public function hasResponses()
38+
{
39+
return $this->responses->count() > 0;
40+
}
41+
3442
/**
3543
* {@inheritDoc}
3644
*/
@@ -48,29 +56,21 @@ public function getResponses()
4856
/**
4957
* {@inheritDoc}
5058
*/
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()
59+
public function isSuccessful(RequestInterface $request)
6460
{
65-
return $this->responses->count() > 0;
61+
return $this->responses->contains($request);
6662
}
6763

6864
/**
6965
* {@inheritDoc}
7066
*/
71-
public function hasResponseFor(RequestInterface $request)
67+
public function getResponseFor(RequestInterface $request)
7268
{
73-
return $this->responses->contains($request);
69+
try {
70+
return $this->responses[$request];
71+
} catch (\UnexpectedValueException $e) {
72+
throw new \UnexpectedValueException('Request not found', $e->getCode(), $e);
73+
}
7474
}
7575

7676
/**
@@ -87,17 +87,9 @@ public function addResponse(RequestInterface $request, ResponseInterface $respon
8787
/**
8888
* {@inheritDoc}
8989
*/
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)
90+
public function hasExceptions()
9991
{
100-
return $this->exceptions->contains($request);
92+
return $this->exceptions->count() > 0;
10193
}
10294

10395
/**
@@ -117,29 +109,21 @@ public function getExceptions()
117109
/**
118110
* {@inheritDoc}
119111
*/
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()
112+
public function isFailed(RequestInterface $request)
133113
{
134-
return $this->exceptions->count() > 0;
114+
return $this->exceptions->contains($request);
135115
}
136116

137117
/**
138118
* {@inheritDoc}
139119
*/
140-
public function hasExceptionFor(RequestInterface $request)
120+
public function getExceptionFor(RequestInterface $request)
141121
{
142-
return $this->exceptions->contains($request);
122+
try {
123+
return $this->exceptions[$request];
124+
} catch (\UnexpectedValueException $e) {
125+
throw new UnexpectedValueException('Request not found', $e->getCode(), $e);
126+
}
143127
}
144128

145129
/**

0 commit comments

Comments
 (0)