Skip to content

Commit fb1fc1e

Browse files
committed
Bugs in ErrorCollection - fixes #11
1 parent 5b1b08b commit fb1fc1e

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Error/ErrorCollection.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,15 @@ public function getStatus()
149149
$status = $error->getStatus();
150150

151151
if (400 <= $status && 499 >= $status) {
152-
$request = is_null($request) ? $status : 400;
152+
$request = is_null($request) ? $status : ($request == $status) ? $status : 400;
153153
} elseif (500 <= $status && 599 >= $status) {
154-
$internal = is_null($internal) ? $status : 500;
154+
$internal = is_null($internal) ? $status : ($internal == $status) ? $status : 500;
155155
}
156156
}
157157

158-
if (!is_null($internal)) {
158+
if (!is_null($internal) && !is_null($request)) {
159+
return '500';
160+
} elseif (!is_null($internal)) {
159161
return (string) $internal;
160162
}
161163

test/Error/ErrorCollectionTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public function testMerge()
146146
public function testGetStatus5xx()
147147
{
148148
$this->a->setStatus(503);
149+
$this->b->setStatus(503);
149150
$collection = new ErrorCollection([$this->a, $this->b]);
150151
$this->assertEquals(503, $collection->getStatus());
151152
}
@@ -161,6 +162,7 @@ public function testGetStatusMixed5xx()
161162
public function testGetStatus4xx()
162163
{
163164
$this->a->setStatus(422);
165+
$this->b->setStatus(422);
164166
$collection = new ErrorCollection([$this->a, $this->b]);
165167
$this->assertEquals(422, $collection->getStatus());
166168
}
@@ -173,6 +175,14 @@ public function testGetStatusMixed4xx()
173175
$this->assertEquals(400, $collection->getStatus());
174176
}
175177

178+
public function testGetStatusMixed5xxAnd4xx()
179+
{
180+
$this->a->setStatus(405);
181+
$this->b->setStatus(501);
182+
$collection = new ErrorCollection([$this->a, $this->b]);
183+
$this->assertEquals(500, $collection->getStatus());
184+
}
185+
176186
public function testGetStatusUnknown()
177187
{
178188
$collection = new ErrorCollection([$this->a, $this->b, $this->interface]);

0 commit comments

Comments
 (0)