From b7cf455832c29ea8b374e698f73d74025b0000d2 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 22 Feb 2026 12:21:54 +0100 Subject: [PATCH] Add Response::ok() --- src/main/php/webservices/rest/RestResponse.class.php | 3 +++ .../php/webservices/rest/unittest/RestResponseTest.class.php | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/main/php/webservices/rest/RestResponse.class.php b/src/main/php/webservices/rest/RestResponse.class.php index e9db2ff..8b5e0ac 100755 --- a/src/main/php/webservices/rest/RestResponse.class.php +++ b/src/main/php/webservices/rest/RestResponse.class.php @@ -43,6 +43,9 @@ public function __construct($status, $message, $headers= [], $reader= null, $uri /** @return int */ public function status() { return $this->status; } + /** @return bool */ + public function ok() { return $this->status >= 200 && $this->status <= 299; } + /** @return string */ public function message() { return $this->message; } diff --git a/src/test/php/webservices/rest/unittest/RestResponseTest.class.php b/src/test/php/webservices/rest/unittest/RestResponseTest.class.php index 20c15a9..e6e032b 100755 --- a/src/test/php/webservices/rest/unittest/RestResponseTest.class.php +++ b/src/test/php/webservices/rest/unittest/RestResponseTest.class.php @@ -50,6 +50,11 @@ public function status() { Assert::equals(200, (new RestResponse(200, 'OK'))->status()); } + #[Test, Values([[200, true], [202, true], [299, true], [100, false], [300, false], [400, false]])] + public function ok($status, $expected) { + Assert::equals($expected, (new RestResponse($status, 'Status #'.$status))->ok()); + } + #[Test] public function message() { Assert::equals('OK', (new RestResponse(200, 'OK'))->message());