- 添加了具有可空字符串类型的属性测试 - 实现了包含状态码短语常量的响应类 - 添加了获取原因方法的测试逻辑 - 验证了空合并操作符的功能 - 测试了不同状态码下的返回值情况pull/1/head
parent
af5442f25e
commit
e869ee49a8
1 changed files with 40 additions and 0 deletions
@ -0,0 +1,40 @@ |
||||
--TEST-- |
||||
Property with nullable type |
||||
--FILE-- |
||||
<?php |
||||
class Response |
||||
{ |
||||
public ?string $reason; |
||||
|
||||
public const PHRASES = [ |
||||
100 => 'Continue', |
||||
101 => 'Switching Protocols', |
||||
102 => 'Processing', // WebDAV; RFC 2518 |
||||
103 => 'Early Hints', // RFC 8297 |
||||
]; |
||||
|
||||
public function __construct() { |
||||
|
||||
} |
||||
|
||||
public function getReason(int $status): string |
||||
{ |
||||
$reason = $this->reason ?: self::PHRASES[$status] ?? 'unknown'; |
||||
return $reason; |
||||
} |
||||
} |
||||
|
||||
function main() { |
||||
$resp = new Response; |
||||
var_dump($resp->getReason(102)); |
||||
var_dump($resp->getReason(200)); |
||||
$resp->reason = 'OK'; |
||||
var_dump($resp->getReason(102)); |
||||
var_dump($resp->getReason(200)); |
||||
} |
||||
?> |
||||
--EXPECT-- |
||||
string(10) "Processing" |
||||
string(7) "unknown" |
||||
string(2) "OK" |
||||
string(2) "OK" |
||||
Loading…
Reference in new issue