diff --git a/CHANGELOG.md b/CHANGELOG.md index a183e90..734d584 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Yii Framework 2 HTTP client extension Change Log 2.0.16 under development ------------------------ -- no changes in this release. +- Bug #240: Fixed `\yii\httpclient\Response::getIsOk()` to include entire 2xx response code range (rhertogh) 2.0.15 May 22, 2023 diff --git a/src/Response.php b/src/Response.php index cbac62a..7418015 100644 --- a/src/Response.php +++ b/src/Response.php @@ -69,13 +69,14 @@ public function getStatusCode() } /** - * Checks if response status code is OK (status code = 20x) + * Checks if response status code is OK (status code = 2xx) * @return bool whether response is OK. * @throws Exception */ public function getIsOk() { - return strncmp('20', $this->getStatusCode(), 2) === 0; + $statusCode = (int)$this->getStatusCode(); + return $statusCode >= 200 && $statusCode < 300; } /** diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 75af277..a7fb56d 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -199,8 +199,10 @@ public function testUnableToGetStatusCode() public function dataProviderIsOk() { return [ + [100, false], [200, true], [201, true], + [226, true], [400, false], ]; }