Skip to content

Commit eebd739

Browse files
authored
Release/4.0.2 (#38)
1 parent 5b04afd commit eebd739

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ corresponding messages, and check for various status code ranges using the metho
4747
```php
4848
use TinyBlocks\Http\Code;
4949

50-
Code::OK->message(); # 200 OK
51-
Code::IM_A_TEAPOT->message(); # 418 I'm a teapot
52-
Code::INTERNAL_SERVER_ERROR->message(); # 500 Internal Server Error
50+
Code::OK->value; # 200
51+
Code::OK->message(); # OK
52+
Code::IM_A_TEAPOT->message(); # I'm a teapot
53+
Code::INTERNAL_SERVER_ERROR->message(); # Internal Server Error
5354
```
5455

5556
- **Check if the code is valid**: Determines if the given code is a valid HTTP status code represented by the enum.

src/Code.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace TinyBlocks\Http;
66

7-
use BackedEnum;
8-
97
/**
108
* HTTP response status codes indicate whether a specific HTTP request has been successfully completed.
119
* Responses are grouped in five classes:
@@ -106,10 +104,7 @@ public function message(): string
106104
default => mb_convert_case($this->name, MB_CASE_TITLE)
107105
};
108106

109-
$message = str_replace('_', ' ', $subject);
110-
$template = '%s %s';
111-
112-
return sprintf($template, $this->value, $message);
107+
return str_replace('_', ' ', $subject);
113108
}
114109

115110
/**
@@ -120,7 +115,7 @@ public function message(): string
120115
*/
121116
public static function isValidCode(int $code): bool
122117
{
123-
$mapper = fn(BackedEnum $enum): int => $enum->value;
118+
$mapper = fn(Code $code): int => $code->value;
124119

125120
return in_array($code, array_map($mapper, self::cases()));
126121
}

tests/Drivers/Laminas/LaminasTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,14 @@ public function testResponseEmissionWithLaminas(): void
8282

8383
/** @Then the emitted response content should match the response body */
8484
self::assertSame($response->getBody()->__toString(), $actual);
85+
86+
/** @And the response status code should be 200 */
87+
self::assertSame(200, $response->getStatusCode());
88+
89+
/** @And the reason phrase should be 'OK' */
90+
self::assertSame('OK', $response->getReasonPhrase());
91+
92+
/** @And the response should contain the X-Request-ID header */
93+
self::assertSame('123456', $response->getHeaderLine(name: 'X-Request-ID'));
8594
}
8695
}

tests/Drivers/Slim/SlimTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,14 @@ public function testResponseEmissionWithSlim(): void
8282

8383
/** @Then the emitted response content should match the response body */
8484
self::assertSame($response->getBody()->__toString(), $actual);
85+
86+
/** @And the response status code should be 200 */
87+
self::assertSame(200, $response->getStatusCode());
88+
89+
/** @And the reason phrase should be 'OK' */
90+
self::assertSame('OK', $response->getReasonPhrase());
91+
92+
/** @And the response should contain the X-Request-ID header */
93+
self::assertSame('123456', $response->getHeaderLine(name: 'X-Request-ID'));
8594
}
8695
}

tests/Response/CodeTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,43 +59,43 @@ public static function messagesDataProvider(): array
5959
return [
6060
'OK message' => [
6161
'code' => Code::OK,
62-
'expected' => '200 OK'
62+
'expected' => 'OK'
6363
],
6464
'Created message' => [
6565
'code' => Code::CREATED,
66-
'expected' => '201 Created'
66+
'expected' => 'Created'
6767
],
6868
'IM Used message' => [
6969
'code' => Code::IM_USED,
70-
'expected' => '226 IM Used'
70+
'expected' => 'IM Used'
7171
],
7272
'Continue message' => [
7373
'code' => Code::CONTINUE,
74-
'expected' => '100 Continue'
74+
'expected' => 'Continue'
7575
],
7676
"I'm a teapot message" => [
7777
'code' => Code::IM_A_TEAPOT,
78-
'expected' => "418 I'm a teapot"
78+
'expected' => "I'm a teapot"
7979
],
8080
'Permanent Redirect message' => [
8181
'code' => Code::PERMANENT_REDIRECT,
82-
'expected' => '308 Permanent Redirect'
82+
'expected' => 'Permanent Redirect'
8383
],
8484
'Internal Server Error message' => [
8585
'code' => Code::INTERNAL_SERVER_ERROR,
86-
'expected' => '500 Internal Server Error'
86+
'expected' => 'Internal Server Error'
8787
],
8888
'Non Authoritative Information message' => [
8989
'code' => Code::NON_AUTHORITATIVE_INFORMATION,
90-
'expected' => '203 Non Authoritative Information'
90+
'expected' => 'Non Authoritative Information'
9191
],
9292
'Proxy Authentication Required message' => [
9393
'code' => Code::PROXY_AUTHENTICATION_REQUIRED,
94-
'expected' => '407 Proxy Authentication Required'
94+
'expected' => 'Proxy Authentication Required'
9595
],
9696
'Network Authentication Required message' => [
9797
'code' => Code::NETWORK_AUTHENTICATION_REQUIRED,
98-
'expected' => '511 Network Authentication Required'
98+
'expected' => 'Network Authentication Required'
9999
]
100100
];
101101
}

0 commit comments

Comments
 (0)