Skip to content

Commit 05df33a

Browse files
committed
Rewrite TransportMock to make use of HttpStatus utility class
1 parent a1d8214 commit 05df33a

File tree

1 file changed

+3
-51
lines changed

1 file changed

+3
-51
lines changed

tests/Fixtures/TransportMock.php

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,17 @@
33
namespace WpOrg\Requests\Tests\Fixtures;
44

55
use WpOrg\Requests\Transport;
6+
use WpOrg\Requests\Utility\HttpStatus;
67

78
final class TransportMock implements Transport {
89
public $code = 200;
910
public $chunked = false;
1011
public $body = 'Test Body';
1112
public $raw_headers = '';
1213

13-
private static $messages = [
14-
100 => '100 Continue',
15-
101 => '101 Switching Protocols',
16-
200 => '200 OK',
17-
201 => '201 Created',
18-
202 => '202 Accepted',
19-
203 => '203 Non-Authoritative Information',
20-
204 => '204 No Content',
21-
205 => '205 Reset Content',
22-
206 => '206 Partial Content',
23-
300 => '300 Multiple Choices',
24-
301 => '301 Moved Permanently',
25-
302 => '302 Found',
26-
303 => '303 See Other',
27-
304 => '304 Not Modified',
28-
305 => '305 Use Proxy',
29-
306 => '306 (Unused)',
30-
307 => '307 Temporary Redirect',
31-
400 => '400 Bad Request',
32-
401 => '401 Unauthorized',
33-
402 => '402 Payment Required',
34-
403 => '403 Forbidden',
35-
404 => '404 Not Found',
36-
405 => '405 Method Not Allowed',
37-
406 => '406 Not Acceptable',
38-
407 => '407 Proxy Authentication Required',
39-
408 => '408 Request Timeout',
40-
409 => '409 Conflict',
41-
410 => '410 Gone',
42-
411 => '411 Length Required',
43-
412 => '412 Precondition Failed',
44-
413 => '413 Request Entity Too Large',
45-
414 => '414 Request-URI Too Long',
46-
415 => '415 Unsupported Media Type',
47-
416 => '416 Requested Range Not Satisfiable',
48-
417 => '417 Expectation Failed',
49-
418 => '418 I\'m a teapot',
50-
428 => '428 Precondition Required',
51-
429 => '429 Too Many Requests',
52-
431 => '431 Request Header Fields Too Large',
53-
500 => '500 Internal Server Error',
54-
501 => '501 Not Implemented',
55-
502 => '502 Bad Gateway',
56-
503 => '503 Service Unavailable',
57-
504 => '504 Gateway Timeout',
58-
505 => '505 HTTP Version Not Supported',
59-
511 => '511 Network Authentication Required',
60-
];
61-
6214
public function request($url, $headers = [], $data = [], $options = []) {
63-
$status = isset(self::$messages[$this->code]) ? self::$messages[$this->code] : $this->code . ' unknown';
64-
$response = "HTTP/1.0 $status\r\n";
15+
$text = HttpStatus::is_valid_code($this->code) ? HttpStatus::get_text($this->code) : 'unknown';
16+
$response = "HTTP/1.0 {$this->code} {$text}\r\n";
6517
$response .= "Content-Type: text/plain\r\n";
6618
if ($this->chunked) {
6719
$response .= "Transfer-Encoding: chunked\r\n";

0 commit comments

Comments
 (0)