Skip to content

Commit aa47a70

Browse files
authored
Merge pull request #30 from sjokkateer/improvement/utils-remove-redundant-check
UTILS: Remove redundant check in `Utils::getStatusCode()`
2 parents 29461a7 + c2dd74e commit aa47a70

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Utils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function getStatusCode(Throwable $error, ResponseInterface $respon
3232
}
3333

3434
$status = $response->getStatusCode();
35-
if (! $status || $status < 400 || $status >= 600) {
35+
if ($status < 400 || $status >= 600) {
3636
$status = 500;
3737
}
3838
return $status;

test/UtilsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Laminas\Stratigility\Utils;
1414
use PHPUnit\Framework\Assert;
1515
use PHPUnit\Framework\TestCase;
16+
use Psr\Http\Message\ResponseInterface;
1617
use ReflectionClass;
1718

1819
class UtilsTest extends TestCase
@@ -32,4 +33,19 @@ public function testGetStatusCodeNotFooledBySneakyStringsWithLeadingDigits(): vo
3233

3334
Assert::assertEquals(418, $actual);
3435
}
36+
37+
public function testGetStatusCodeZeroExpectedStatusCodeFiveHundredReturned(): void
38+
{
39+
$statusCode = 0;
40+
41+
$response = $this->createMock(ResponseInterface::class);
42+
$response
43+
->method('getStatusCode')
44+
->willReturn($statusCode);
45+
46+
$actualStatusCode = Utils::getStatusCode(new Exception(), $response);
47+
$expectedStatusCode = 500;
48+
49+
static::assertEquals($expectedStatusCode, $actualStatusCode);
50+
}
3551
}

0 commit comments

Comments
 (0)