Skip to content

Commit

Permalink
Merge pull request #30 from sjokkateer/improvement/utils-remove-redun…
Browse files Browse the repository at this point in the history
…dant-check

UTILS: Remove redundant check in `Utils::getStatusCode()`
  • Loading branch information
Ocramius authored Jul 23, 2022
2 parents 29461a7 + c2dd74e commit aa47a70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function getStatusCode(Throwable $error, ResponseInterface $respon
}

$status = $response->getStatusCode();
if (! $status || $status < 400 || $status >= 600) {
if ($status < 400 || $status >= 600) {
$status = 500;
}
return $status;
Expand Down
16 changes: 16 additions & 0 deletions test/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Laminas\Stratigility\Utils;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ResponseInterface;
use ReflectionClass;

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

Assert::assertEquals(418, $actual);
}

public function testGetStatusCodeZeroExpectedStatusCodeFiveHundredReturned(): void
{
$statusCode = 0;

$response = $this->createMock(ResponseInterface::class);
$response
->method('getStatusCode')
->willReturn($statusCode);

$actualStatusCode = Utils::getStatusCode(new Exception(), $response);
$expectedStatusCode = 500;

static::assertEquals($expectedStatusCode, $actualStatusCode);
}
}

0 comments on commit aa47a70

Please sign in to comment.