Skip to content

Commit cf5d966

Browse files
committed
Use HTTP status helper class in TransportRedirectMock
1 parent 4d150be commit cf5d966

File tree

1 file changed

+2
-51
lines changed

1 file changed

+2
-51
lines changed

tests/Fixtures/TransportRedirectMock.php

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,64 +14,15 @@ final class TransportRedirectMock implements Transport {
1414

1515
public $redirected_transport = null;
1616

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

7122
$redirect_url = 'https://example.com/redirected?url=' . urlencode($url);
7223

73-
$status = isset(self::$messages[$this->code]) ? self::$messages[$this->code] : $this->code . ' unknown';
74-
$response = "HTTP/1.0 $status\r\n";
24+
$text = HttpStatus::is_valid_code($this->code) ? HttpStatus::get_text($this->code) : 'unknown';
25+
$response = "HTTP/1.0 {$this->code} $text\r\n";
7526
$response .= "Content-Type: text/plain\r\n";
7627
if ($this->chunked) {
7728
$response .= "Transfer-Encoding: chunked\r\n";

0 commit comments

Comments
 (0)