[HttpFoundation] Fix and test status codes according to IANA's data
This commit is contained in:
parent
34655e69dd
commit
72d25ccca7
@ -158,10 +158,10 @@ class Response
|
||||
410 => 'Gone',
|
||||
411 => 'Length Required',
|
||||
412 => 'Precondition Failed',
|
||||
413 => 'Request Entity Too Large',
|
||||
414 => 'Request-URI Too Long',
|
||||
413 => 'Payload Too Large',
|
||||
414 => 'URI Too Long',
|
||||
415 => 'Unsupported Media Type',
|
||||
416 => 'Requested Range Not Satisfiable',
|
||||
416 => 'Range Not Satisfiable',
|
||||
417 => 'Expectation Failed',
|
||||
418 => 'I\'m a teapot', // RFC2324
|
||||
421 => 'Misdirected Request', // RFC7540
|
||||
@ -180,7 +180,7 @@ class Response
|
||||
503 => 'Service Unavailable',
|
||||
504 => 'Gateway Timeout',
|
||||
505 => 'HTTP Version Not Supported',
|
||||
506 => 'Variant Also Negotiates (Experimental)', // RFC2295
|
||||
506 => 'Variant Also Negotiates', // RFC2295
|
||||
507 => 'Insufficient Storage', // RFC4918
|
||||
508 => 'Loop Detected', // RFC5842
|
||||
510 => 'Not Extended', // RFC2774
|
||||
|
@ -882,6 +882,67 @@ class ResponseTest extends ResponseTestCase
|
||||
{
|
||||
return new Response();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
|
||||
*
|
||||
* @author Fábio Pacheco
|
||||
* @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
public function ianaCodesReasonPhrasesProvider()
|
||||
{
|
||||
if (!in_array('https', stream_get_wrappers(), true)) {
|
||||
$this->markTestSkipped('The "https" wrapper is not available');
|
||||
}
|
||||
|
||||
$ianaHttpStatusCodes = new \DOMDocument();
|
||||
|
||||
libxml_set_streams_context(stream_context_create(array(
|
||||
'http' => array(
|
||||
'method' => 'GET',
|
||||
'timeout' => 30,
|
||||
),
|
||||
)));
|
||||
|
||||
$ianaHttpStatusCodes->load('https://www.iana.org/assignments/http-status-codes/http-status-codes.xml');
|
||||
if (!$ianaHttpStatusCodes->relaxNGValidate('https://www.iana.org/assignments/http-status-codes/http-status-codes.rng')) {
|
||||
self::fail('Invalid IANA\'s HTTP status code list.');
|
||||
}
|
||||
|
||||
$ianaCodesReasonPhrases = array();
|
||||
|
||||
$xpath = new \DomXPath($ianaHttpStatusCodes);
|
||||
$xpath->registerNamespace('ns', 'http://www.iana.org/assignments');
|
||||
|
||||
$records = $xpath->query('//ns:record');
|
||||
foreach ($records as $record) {
|
||||
$value = $xpath->query('.//ns:value', $record)->item(0)->nodeValue;
|
||||
$description = $xpath->query('.//ns:description', $record)->item(0)->nodeValue;
|
||||
|
||||
if (in_array($description, array('Unassigned', '(Unused)'), true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^([0-9]+)\s*\-\s*([0-9]+)$/', $value, $matches)) {
|
||||
for ($value = $matches[1]; $value <= $matches[2]; ++$value) {
|
||||
$ianaCodesReasonPhrases[] = array($value, $description);
|
||||
}
|
||||
} else {
|
||||
$ianaCodesReasonPhrases[] = array($value, $description);
|
||||
}
|
||||
}
|
||||
|
||||
return $ianaCodesReasonPhrases;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider ianaCodesReasonPhrasesProvider
|
||||
*/
|
||||
public function testReasonPhraseDefaultsAgainstIana($code, $reasonPhrase)
|
||||
{
|
||||
$this->assertEquals($reasonPhrase, Response::$statusTexts[$code]);
|
||||
}
|
||||
}
|
||||
|
||||
class StringableObject
|
||||
|
Reference in New Issue
Block a user