Upgrade 1-11.38

This commit is contained in:
xesmyd
2026-03-30 14:10:30 +02:00
parent f2a7e6d1fc
commit ac648ef29d
24665 changed files with 69682 additions and 2205004 deletions
+127 -81
View File
@@ -21,7 +21,7 @@ class ResponseTest extends ResponseTestCase
{
public function testCreate()
{
$response = Response::create('foo', 301, array('Foo' => 'bar'));
$response = Response::create('foo', 301, ['Foo' => 'bar']);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals(301, $response->getStatusCode());
@@ -33,7 +33,7 @@ class ResponseTest extends ResponseTestCase
$response = new Response();
$response = explode("\r\n", $response);
$this->assertEquals('HTTP/1.0 200 OK', $response[0]);
$this->assertEquals('Cache-Control: no-cache', $response[1]);
$this->assertEquals('Cache-Control: no-cache, private', $response[1]);
}
public function testClone()
@@ -253,10 +253,10 @@ class ResponseTest extends ResponseTestCase
public function testIsValidateable()
{
$response = new Response('', 200, array('Last-Modified' => $this->createDateTimeOneHourAgo()->format(DATE_RFC2822)));
$response = new Response('', 200, ['Last-Modified' => $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822)]);
$this->assertTrue($response->isValidateable(), '->isValidateable() returns true if Last-Modified is present');
$response = new Response('', 200, array('ETag' => '"12345"'));
$response = new Response('', 200, ['ETag' => '"12345"']);
$this->assertTrue($response->isValidateable(), '->isValidateable() returns true if ETag is present');
$response = new Response();
@@ -266,7 +266,7 @@ class ResponseTest extends ResponseTestCase
public function testGetDate()
{
$oneHourAgo = $this->createDateTimeOneHourAgo();
$response = new Response('', 200, array('Date' => $oneHourAgo->format(DATE_RFC2822)));
$response = new Response('', 200, ['Date' => $oneHourAgo->format(\DATE_RFC2822)]);
$date = $response->getDate();
$this->assertEquals($oneHourAgo->getTimestamp(), $date->getTimestamp(), '->getDate() returns the Date header if present');
@@ -274,9 +274,9 @@ class ResponseTest extends ResponseTestCase
$date = $response->getDate();
$this->assertEquals(time(), $date->getTimestamp(), '->getDate() returns the current Date if no Date header present');
$response = new Response('', 200, array('Date' => $this->createDateTimeOneHourAgo()->format(DATE_RFC2822)));
$response = new Response('', 200, ['Date' => $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822)]);
$now = $this->createDateTimeNow();
$response->headers->set('Date', $now->format(DATE_RFC2822));
$response->headers->set('Date', $now->format(\DATE_RFC2822));
$date = $response->getDate();
$this->assertEquals($now->getTimestamp(), $date->getTimestamp(), '->getDate() returns the date when the header has been modified');
@@ -299,13 +299,13 @@ class ResponseTest extends ResponseTestCase
$response = new Response();
$response->headers->set('Cache-Control', 'must-revalidate');
$response->headers->set('Expires', $this->createDateTimeOneHourLater()->format(DATE_RFC2822));
$response->headers->set('Expires', $this->createDateTimeOneHourLater()->format(\DATE_RFC2822));
$this->assertEquals(3600, $response->getMaxAge(), '->getMaxAge() falls back to Expires when no max-age or s-maxage directive present');
$response = new Response();
$response->headers->set('Cache-Control', 'must-revalidate');
$response->headers->set('Expires', -1);
$this->assertEquals('Sat, 01 Jan 00 00:00:00 +0000', $response->getExpires()->format(DATE_RFC822));
$this->assertEquals('Sat, 01 Jan 00 00:00:00 +0000', $response->getExpires()->format(\DATE_RFC822));
$response = new Response();
$this->assertNull($response->getMaxAge(), '->getMaxAge() returns null if no freshness information available');
@@ -364,26 +364,32 @@ class ResponseTest extends ResponseTestCase
$this->assertNull($response->headers->get('Age'), '->expire() does not set the Age when the response is expired');
$response = new Response();
$response->headers->set('Expires', date(DATE_RFC2822, time() + 600));
$response->headers->set('Expires', date(\DATE_RFC2822, time() + 600));
$response->expire();
$this->assertNull($response->headers->get('Expires'), '->expire() removes the Expires header when the response is fresh');
}
public function testNullExpireHeader()
{
$response = new Response(null, 200, ['Expires' => null]);
$this->assertNull($response->getExpires());
}
public function testGetTtl()
{
$response = new Response();
$this->assertNull($response->getTtl(), '->getTtl() returns null when no Expires or Cache-Control headers are present');
$response = new Response();
$response->headers->set('Expires', $this->createDateTimeOneHourLater()->format(DATE_RFC2822));
$response->headers->set('Expires', $this->createDateTimeOneHourLater()->format(\DATE_RFC2822));
$this->assertEquals(3600, $response->getTtl(), '->getTtl() uses the Expires header when no max-age is present');
$response = new Response();
$response->headers->set('Expires', $this->createDateTimeOneHourAgo()->format(DATE_RFC2822));
$response->headers->set('Expires', $this->createDateTimeOneHourAgo()->format(\DATE_RFC2822));
$this->assertLessThan(0, $response->getTtl(), '->getTtl() returns negative values when Expires is in past');
$response = new Response();
$response->headers->set('Expires', $response->getDate()->format(DATE_RFC2822));
$response->headers->set('Expires', $response->getDate()->format(\DATE_RFC2822));
$response->headers->set('Age', 0);
$this->assertSame(0, $response->getTtl(), '->getTtl() correctly handles zero');
@@ -414,21 +420,21 @@ class ResponseTest extends ResponseTestCase
public function testGetVary()
{
$response = new Response();
$this->assertEquals(array(), $response->getVary(), '->getVary() returns an empty array if no Vary header is present');
$this->assertEquals([], $response->getVary(), '->getVary() returns an empty array if no Vary header is present');
$response = new Response();
$response->headers->set('Vary', 'Accept-Language');
$this->assertEquals(array('Accept-Language'), $response->getVary(), '->getVary() parses a single header name value');
$this->assertEquals(['Accept-Language'], $response->getVary(), '->getVary() parses a single header name value');
$response = new Response();
$response->headers->set('Vary', 'Accept-Language User-Agent X-Foo');
$this->assertEquals(array('Accept-Language', 'User-Agent', 'X-Foo'), $response->getVary(), '->getVary() parses multiple header name values separated by spaces');
$this->assertEquals(['Accept-Language', 'User-Agent', 'X-Foo'], $response->getVary(), '->getVary() parses multiple header name values separated by spaces');
$response = new Response();
$response->headers->set('Vary', 'Accept-Language,User-Agent, X-Foo');
$this->assertEquals(array('Accept-Language', 'User-Agent', 'X-Foo'), $response->getVary(), '->getVary() parses multiple header name values separated by commas');
$this->assertEquals(['Accept-Language', 'User-Agent', 'X-Foo'], $response->getVary(), '->getVary() parses multiple header name values separated by commas');
$vary = array('Accept-Language', 'User-Agent', 'X-foo');
$vary = ['Accept-Language', 'User-Agent', 'X-foo'];
$response = new Response();
$response->headers->set('Vary', $vary);
@@ -443,24 +449,24 @@ class ResponseTest extends ResponseTestCase
{
$response = new Response();
$response->setVary('Accept-Language');
$this->assertEquals(array('Accept-Language'), $response->getVary());
$this->assertEquals(['Accept-Language'], $response->getVary());
$response->setVary('Accept-Language, User-Agent');
$this->assertEquals(array('Accept-Language', 'User-Agent'), $response->getVary(), '->setVary() replace the vary header by default');
$this->assertEquals(['Accept-Language', 'User-Agent'], $response->getVary(), '->setVary() replace the vary header by default');
$response->setVary('X-Foo', false);
$this->assertEquals(array('Accept-Language', 'User-Agent', 'X-Foo'), $response->getVary(), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false');
$this->assertEquals(['Accept-Language', 'User-Agent', 'X-Foo'], $response->getVary(), '->setVary() doesn\'t wipe out earlier Vary headers if replace is set to false');
}
public function testDefaultContentType()
{
$headerMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\ResponseHeaderBag')->setMethods(array('set'))->getMock();
$headerMock->expects($this->at(0))
$headerMock = $this->getMockBuilder('Symfony\Component\HttpFoundation\ResponseHeaderBag')->setMethods(['set'])->getMock();
$headerMock->expects($this->exactly(2))
->method('set')
->with('Content-Type', 'text/html');
$headerMock->expects($this->at(1))
->method('set')
->with('Content-Type', 'text/html; charset=UTF-8');
->withConsecutive(
['Content-Type', 'text/html'],
['Content-Type', 'text/html; charset=UTF-8']
);
$response = new Response('foo');
$response->headers = $headerMock;
@@ -532,7 +538,6 @@ class ResponseTest extends ResponseTestCase
$response->prepare($request);
$this->assertEquals('', $response->getContent());
$this->assertFalse($response->headers->has('Content-Type'));
$this->assertFalse($response->headers->has('Content-Type'));
$response->setContent('content');
$response->setStatusCode(304);
@@ -576,50 +581,56 @@ class ResponseTest extends ResponseTestCase
public function testSetCache()
{
$response = new Response();
//array('etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public')
// ['etag', 'last_modified', 'max_age', 's_maxage', 'private', 'public']
try {
$response->setCache(array('wrong option' => 'value'));
$response->setCache(['wrong option' => 'value']);
$this->fail('->setCache() throws an InvalidArgumentException if an option is not supported');
} catch (\Exception $e) {
$this->assertInstanceOf('InvalidArgumentException', $e, '->setCache() throws an InvalidArgumentException if an option is not supported');
$this->assertContains('"wrong option"', $e->getMessage());
$this->assertStringContainsString('"wrong option"', $e->getMessage());
}
$options = array('etag' => '"whatever"');
$options = ['etag' => '"whatever"'];
$response->setCache($options);
$this->assertEquals($response->getEtag(), '"whatever"');
$this->assertEquals('"whatever"', $response->getEtag());
$now = $this->createDateTimeNow();
$options = array('last_modified' => $now);
$options = ['last_modified' => $now];
$response->setCache($options);
$this->assertEquals($response->getLastModified()->getTimestamp(), $now->getTimestamp());
$this->assertEquals($now->getTimestamp(), $response->getLastModified()->getTimestamp());
$options = array('max_age' => 100);
$options = ['max_age' => 100];
$response->setCache($options);
$this->assertEquals($response->getMaxAge(), 100);
$this->assertEquals(100, $response->getMaxAge());
$options = array('s_maxage' => 200);
$options = ['s_maxage' => 200];
$response->setCache($options);
$this->assertEquals($response->getMaxAge(), 200);
$this->assertEquals(200, $response->getMaxAge());
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
$response->setCache(array('public' => true));
$response->setCache(['public' => true]);
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
$response->setCache(array('public' => false));
$response->setCache(['public' => false]);
$this->assertFalse($response->headers->hasCacheControlDirective('public'));
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
$response->setCache(array('private' => true));
$response->setCache(['private' => true]);
$this->assertFalse($response->headers->hasCacheControlDirective('public'));
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
$response->setCache(array('private' => false));
$response->setCache(['private' => false]);
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
$response->setCache(['immutable' => true]);
$this->assertTrue($response->headers->hasCacheControlDirective('immutable'));
$response->setCache(['immutable' => false]);
$this->assertFalse($response->headers->hasCacheControlDirective('immutable'));
}
public function testSendContent()
@@ -629,7 +640,7 @@ class ResponseTest extends ResponseTestCase
ob_start();
$response->sendContent();
$string = ob_get_clean();
$this->assertContains('test response rendering', $string);
$this->assertStringContainsString('test response rendering', $string);
}
public function testSetPublic()
@@ -641,6 +652,22 @@ class ResponseTest extends ResponseTestCase
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
}
public function testSetImmutable()
{
$response = new Response();
$response->setImmutable();
$this->assertTrue($response->headers->hasCacheControlDirective('immutable'));
}
public function testIsImmutable()
{
$response = new Response();
$response->setImmutable();
$this->assertTrue($response->isImmutable());
}
public function testSetExpires()
{
$response = new Response();
@@ -703,14 +730,14 @@ class ResponseTest extends ResponseTestCase
public function getStatusCodeFixtures()
{
return array(
array('200', null, 'OK'),
array('200', false, ''),
array('200', 'foo', 'foo'),
array('199', null, 'unknown status'),
array('199', false, ''),
array('199', 'foo', 'foo'),
);
return [
['200', null, 'OK'],
['200', false, ''],
['200', 'foo', 'foo'],
['199', null, 'unknown status'],
['199', false, ''],
['199', 'foo', 'foo'],
];
}
public function testIsInformational()
@@ -724,7 +751,7 @@ class ResponseTest extends ResponseTestCase
public function testIsRedirectRedirection()
{
foreach (array(301, 302, 303, 307) as $code) {
foreach ([301, 302, 303, 307] as $code) {
$response = new Response('', $code);
$this->assertTrue($response->isRedirection());
$this->assertTrue($response->isRedirect());
@@ -742,7 +769,7 @@ class ResponseTest extends ResponseTestCase
$this->assertFalse($response->isRedirection());
$this->assertFalse($response->isRedirect());
$response = new Response('', 301, array('Location' => '/good-uri'));
$response = new Response('', 301, ['Location' => '/good-uri']);
$this->assertFalse($response->isRedirect('/bad-uri'));
$this->assertTrue($response->isRedirect('/good-uri'));
}
@@ -758,7 +785,7 @@ class ResponseTest extends ResponseTestCase
public function testIsEmpty()
{
foreach (array(204, 304) as $code) {
foreach ([204, 304] as $code) {
$response = new Response('', $code);
$this->assertTrue($response->isEmpty());
}
@@ -807,7 +834,7 @@ class ResponseTest extends ResponseTestCase
public function testSetEtag()
{
$response = new Response('', 200, array('ETag' => '"12345"'));
$response = new Response('', 200, ['ETag' => '"12345"']);
$response->setEtag();
$this->assertNull($response->headers->get('Etag'), '->setEtag() removes Etags when call with null');
@@ -824,11 +851,11 @@ class ResponseTest extends ResponseTestCase
}
/**
* @expectedException \UnexpectedValueException
* @dataProvider invalidContentProvider
*/
public function testSetContentInvalid($content)
{
$this->expectException('UnexpectedValueException');
$response = new Response();
$response->setContent($content);
}
@@ -837,7 +864,7 @@ class ResponseTest extends ResponseTestCase
{
$response = new Response();
$setters = array(
$setters = [
'setProtocolVersion' => '1.0',
'setCharset' => 'UTF-8',
'setPublic' => null,
@@ -848,29 +875,39 @@ class ResponseTest extends ResponseTestCase
'setSharedMaxAge' => 1,
'setTtl' => 1,
'setClientTtl' => 1,
);
];
foreach ($setters as $setter => $arg) {
$this->assertEquals($response, $response->{$setter}($arg));
}
}
public function testNoDeprecationsAreTriggered()
{
new DefaultResponse();
$this->getMockBuilder(Response::class)->getMock();
// we just need to ensure that subclasses of Response can be created without any deprecations
// being triggered if the subclass does not override any final methods
$this->addToAssertionCount(1);
}
public function validContentProvider()
{
return array(
'obj' => array(new StringableObject()),
'string' => array('Foo'),
'int' => array(2),
);
return [
'obj' => [new StringableObject()],
'string' => ['Foo'],
'int' => [2],
];
}
public function invalidContentProvider()
{
return array(
'obj' => array(new \stdClass()),
'array' => array(array()),
'bool' => array(true, '1'),
);
return [
'obj' => [new \stdClass()],
'array' => [[]],
'bool' => [true, '1'],
];
}
protected function createDateTimeOneHourAgo()
@@ -896,11 +933,11 @@ class ResponseTest extends ResponseTestCase
}
/**
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
* @see http://github.com/zendframework/zend-diactoros for the canonical source repository
*
* @author Fábio Pacheco
* @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
* @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
*/
public function ianaCodesReasonPhrasesProvider()
{
@@ -910,19 +947,24 @@ class ResponseTest extends ResponseTestCase
$ianaHttpStatusCodes = new \DOMDocument();
libxml_set_streams_context(stream_context_create(array(
'http' => array(
$context = stream_context_create([
'http' => [
'method' => 'GET',
'timeout' => 30,
),
)));
'user_agent' => __METHOD__,
],
]);
$ianaHttpStatusCodes->load('https://www.iana.org/assignments/http-status-codes/http-status-codes.xml');
if (!$rawStatusCodes = file_get_contents('https://www.iana.org/assignments/http-status-codes/http-status-codes.xml', false, $context)) {
$this->markTestSkipped('The IANA server is throttling the list of status codes');
}
$ianaHttpStatusCodes->loadXML($rawStatusCodes);
if (!$ianaHttpStatusCodes->relaxNGValidate(__DIR__.'/schema/http-status-codes.rng')) {
self::fail('Invalid IANA\'s HTTP status code list.');
}
$ianaCodesReasonPhrases = array();
$ianaCodesReasonPhrases = [];
$xpath = new \DOMXPath($ianaHttpStatusCodes);
$xpath->registerNamespace('ns', 'http://www.iana.org/assignments');
@@ -932,16 +974,16 @@ class ResponseTest extends ResponseTestCase
$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)) {
if (\in_array($description, ['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);
$ianaCodesReasonPhrases[] = [$value, $description];
}
} else {
$ianaCodesReasonPhrases[] = array($value, $description);
$ianaCodesReasonPhrases[] = [$value, $description];
}
}
@@ -964,3 +1006,7 @@ class StringableObject
return 'Foo';
}
}
class DefaultResponse extends Response
{
}