updated packages
This commit is contained in:
@@ -220,13 +220,13 @@ class EsiTest extends TestCase
|
||||
$response1 = new Response('foo');
|
||||
$response1->setStatusCode(404);
|
||||
$response2 = new Response('bar');
|
||||
$cache = $this->getCache(Request::create('/'), array($response1, $response2));
|
||||
$cache = $this->getCache(Request::create('/'), [$response1, $response2]);
|
||||
$this->assertEquals('bar', $esi->handle($cache, '/', '/alt', false));
|
||||
}
|
||||
|
||||
protected function getCache($request, $response)
|
||||
{
|
||||
$cache = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpCache\HttpCache')->setMethods(array('getRequest', 'handle'))->disableOriginalConstructor()->getMock();
|
||||
$cache = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpCache\HttpCache')->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock();
|
||||
$cache->expects($this->any())
|
||||
->method('getRequest')
|
||||
->will($this->returnValue($request))
|
||||
|
||||
@@ -39,7 +39,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
// implements TerminableInterface
|
||||
$kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(array('terminate', 'registerBundles', 'registerContainerConfiguration'))
|
||||
->setMethods(['terminate', 'registerBundles', 'registerContainerConfiguration'])
|
||||
->getMock();
|
||||
|
||||
$kernelMock->expects($this->once())
|
||||
@@ -61,7 +61,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testInvalidatesOnPostPutDeleteRequests()
|
||||
{
|
||||
foreach (array('post', 'put', 'delete') as $method) {
|
||||
foreach (['post', 'put', 'delete'] as $method) {
|
||||
$this->setNextResponse(200);
|
||||
$this->request($method, '/');
|
||||
|
||||
@@ -74,8 +74,8 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testDoesNotCacheWithAuthorizationRequestHeaderAndNonPublicResponse()
|
||||
{
|
||||
$this->setNextResponse(200, array('ETag' => '"Foo"'));
|
||||
$this->request('GET', '/', array('HTTP_AUTHORIZATION' => 'basic foobarbaz'));
|
||||
$this->setNextResponse(200, ['ETag' => '"Foo"']);
|
||||
$this->request('GET', '/', ['HTTP_AUTHORIZATION' => 'basic foobarbaz']);
|
||||
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertResponseOk();
|
||||
@@ -88,8 +88,8 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testDoesCacheWithAuthorizationRequestHeaderAndPublicResponse()
|
||||
{
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public', 'ETag' => '"Foo"'));
|
||||
$this->request('GET', '/', array('HTTP_AUTHORIZATION' => 'basic foobarbaz'));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public', 'ETag' => '"Foo"']);
|
||||
$this->request('GET', '/', ['HTTP_AUTHORIZATION' => 'basic foobarbaz']);
|
||||
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertResponseOk();
|
||||
@@ -101,8 +101,8 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testDoesNotCacheWithCookieHeaderAndNonPublicResponse()
|
||||
{
|
||||
$this->setNextResponse(200, array('ETag' => '"Foo"'));
|
||||
$this->request('GET', '/', array(), array('foo' => 'bar'));
|
||||
$this->setNextResponse(200, ['ETag' => '"Foo"']);
|
||||
$this->request('GET', '/', [], ['foo' => 'bar']);
|
||||
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertResponseOk();
|
||||
@@ -115,7 +115,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testDoesNotCacheRequestsWithACookieHeader()
|
||||
{
|
||||
$this->setNextResponse(200);
|
||||
$this->request('GET', '/', array(), array('foo' => 'bar'));
|
||||
$this->request('GET', '/', [], ['foo' => 'bar']);
|
||||
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertResponseOk();
|
||||
@@ -129,8 +129,8 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public', 'Last-Modified' => $time->format(DATE_RFC2822), 'Content-Type' => 'text/plain'), 'Hello World');
|
||||
$this->request('GET', '/', array('HTTP_IF_MODIFIED_SINCE' => $time->format(DATE_RFC2822)));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public', 'Last-Modified' => $time->format(DATE_RFC2822), 'Content-Type' => 'text/plain'], 'Hello World');
|
||||
$this->request('GET', '/', ['HTTP_IF_MODIFIED_SINCE' => $time->format(DATE_RFC2822)]);
|
||||
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(304, $this->response->getStatusCode());
|
||||
@@ -142,8 +142,8 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testRespondsWith304WhenIfNoneMatchMatchesETag()
|
||||
{
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public', 'ETag' => '12345', 'Content-Type' => 'text/plain'), 'Hello World');
|
||||
$this->request('GET', '/', array('HTTP_IF_NONE_MATCH' => '12345'));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public', 'ETag' => '12345', 'Content-Type' => 'text/plain'], 'Hello World');
|
||||
$this->request('GET', '/', ['HTTP_IF_NONE_MATCH' => '12345']);
|
||||
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(304, $this->response->getStatusCode());
|
||||
@@ -158,7 +158,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
|
||||
$this->setNextResponse(200, array(), '', function ($request, $response) use ($time) {
|
||||
$this->setNextResponse(200, [], '', function ($request, $response) use ($time) {
|
||||
$response->setStatusCode(200);
|
||||
$response->headers->set('ETag', '12345');
|
||||
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
|
||||
@@ -168,17 +168,17 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
// only ETag matches
|
||||
$t = \DateTime::createFromFormat('U', time() - 3600);
|
||||
$this->request('GET', '/', array('HTTP_IF_NONE_MATCH' => '12345', 'HTTP_IF_MODIFIED_SINCE' => $t->format(DATE_RFC2822)));
|
||||
$this->request('GET', '/', ['HTTP_IF_NONE_MATCH' => '12345', 'HTTP_IF_MODIFIED_SINCE' => $t->format(DATE_RFC2822)]);
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
|
||||
// only Last-Modified matches
|
||||
$this->request('GET', '/', array('HTTP_IF_NONE_MATCH' => '1234', 'HTTP_IF_MODIFIED_SINCE' => $time->format(DATE_RFC2822)));
|
||||
$this->request('GET', '/', ['HTTP_IF_NONE_MATCH' => '1234', 'HTTP_IF_MODIFIED_SINCE' => $time->format(DATE_RFC2822)]);
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
|
||||
// Both matches
|
||||
$this->request('GET', '/', array('HTTP_IF_NONE_MATCH' => '12345', 'HTTP_IF_MODIFIED_SINCE' => $time->format(DATE_RFC2822)));
|
||||
$this->request('GET', '/', ['HTTP_IF_NONE_MATCH' => '12345', 'HTTP_IF_MODIFIED_SINCE' => $time->format(DATE_RFC2822)]);
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(304, $this->response->getStatusCode());
|
||||
}
|
||||
@@ -187,10 +187,10 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$this->setNextResponse(
|
||||
200,
|
||||
array(
|
||||
[
|
||||
'ETag' => '1234',
|
||||
'Cache-Control' => 'public, s-maxage=60',
|
||||
)
|
||||
]
|
||||
);
|
||||
|
||||
$this->request('GET', '/');
|
||||
@@ -210,7 +210,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testValidatesPrivateResponsesCachedOnTheClient()
|
||||
{
|
||||
$this->setNextResponse(200, array(), '', function ($request, $response) {
|
||||
$this->setNextResponse(200, [], '', function ($request, $response) {
|
||||
$etags = preg_split('/\s*,\s*/', $request->headers->get('IF_NONE_MATCH'));
|
||||
if ($request->cookies->has('authenticated')) {
|
||||
$response->headers->set('Cache-Control', 'private, no-store');
|
||||
@@ -243,7 +243,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertTraceContains('miss');
|
||||
$this->assertTraceContains('store');
|
||||
|
||||
$this->request('GET', '/', array(), array('authenticated' => ''));
|
||||
$this->request('GET', '/', [], ['authenticated' => '']);
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('"private tag"', $this->response->headers->get('ETag'));
|
||||
@@ -257,8 +257,8 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time() + 5);
|
||||
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public', 'Expires' => $time->format(DATE_RFC2822)));
|
||||
$this->request('GET', '/', array('HTTP_CACHE_CONTROL' => 'no-cache'));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public', 'Expires' => $time->format(DATE_RFC2822)]);
|
||||
$this->request('GET', '/', ['HTTP_CACHE_CONTROL' => 'no-cache']);
|
||||
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertTraceContains('store');
|
||||
@@ -269,7 +269,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$count = 0;
|
||||
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public, max-age=10000'), '', function ($request, $response) use (&$count) {
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public, max-age=10000'], '', function ($request, $response) use (&$count) {
|
||||
++$count;
|
||||
$response->setContent(1 == $count ? 'Hello World' : 'Goodbye World');
|
||||
});
|
||||
@@ -285,7 +285,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertTraceContains('fresh');
|
||||
|
||||
$this->cacheConfig['allow_reload'] = true;
|
||||
$this->request('GET', '/', array('HTTP_CACHE_CONTROL' => 'no-cache'));
|
||||
$this->request('GET', '/', ['HTTP_CACHE_CONTROL' => 'no-cache']);
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Goodbye World', $this->response->getContent());
|
||||
$this->assertTraceContains('reload');
|
||||
@@ -296,7 +296,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$count = 0;
|
||||
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public, max-age=10000'), '', function ($request, $response) use (&$count) {
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public, max-age=10000'], '', function ($request, $response) use (&$count) {
|
||||
++$count;
|
||||
$response->setContent(1 == $count ? 'Hello World' : 'Goodbye World');
|
||||
});
|
||||
@@ -312,12 +312,12 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertTraceContains('fresh');
|
||||
|
||||
$this->cacheConfig['allow_reload'] = false;
|
||||
$this->request('GET', '/', array('HTTP_CACHE_CONTROL' => 'no-cache'));
|
||||
$this->request('GET', '/', ['HTTP_CACHE_CONTROL' => 'no-cache']);
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceNotContains('reload');
|
||||
|
||||
$this->request('GET', '/', array('HTTP_CACHE_CONTROL' => 'no-cache'));
|
||||
$this->request('GET', '/', ['HTTP_CACHE_CONTROL' => 'no-cache']);
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceNotContains('reload');
|
||||
@@ -327,7 +327,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$count = 0;
|
||||
|
||||
$this->setNextResponse(200, array(), '', function ($request, $response) use (&$count) {
|
||||
$this->setNextResponse(200, [], '', function ($request, $response) use (&$count) {
|
||||
++$count;
|
||||
$response->headers->set('Cache-Control', 'public, max-age=10000');
|
||||
$response->setETag($count);
|
||||
@@ -345,7 +345,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertTraceContains('fresh');
|
||||
|
||||
$this->cacheConfig['allow_revalidate'] = true;
|
||||
$this->request('GET', '/', array('HTTP_CACHE_CONTROL' => 'max-age=0'));
|
||||
$this->request('GET', '/', ['HTTP_CACHE_CONTROL' => 'max-age=0']);
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Goodbye World', $this->response->getContent());
|
||||
$this->assertTraceContains('stale');
|
||||
@@ -357,7 +357,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$count = 0;
|
||||
|
||||
$this->setNextResponse(200, array(), '', function ($request, $response) use (&$count) {
|
||||
$this->setNextResponse(200, [], '', function ($request, $response) use (&$count) {
|
||||
++$count;
|
||||
$response->headers->set('Cache-Control', 'public, max-age=10000');
|
||||
$response->setETag($count);
|
||||
@@ -375,14 +375,14 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertTraceContains('fresh');
|
||||
|
||||
$this->cacheConfig['allow_revalidate'] = false;
|
||||
$this->request('GET', '/', array('HTTP_CACHE_CONTROL' => 'max-age=0'));
|
||||
$this->request('GET', '/', ['HTTP_CACHE_CONTROL' => 'max-age=0']);
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceNotContains('stale');
|
||||
$this->assertTraceNotContains('invalid');
|
||||
$this->assertTraceContains('fresh');
|
||||
|
||||
$this->request('GET', '/', array('HTTP_CACHE_CONTROL' => 'max-age=0'));
|
||||
$this->request('GET', '/', ['HTTP_CACHE_CONTROL' => 'max-age=0']);
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
$this->assertTraceNotContains('stale');
|
||||
@@ -393,7 +393,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testFetchesResponseFromBackendWhenCacheMisses()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time() + 5);
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public', 'Expires' => $time->format(DATE_RFC2822)));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public', 'Expires' => $time->format(DATE_RFC2822)]);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
@@ -405,7 +405,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
foreach (array_merge(range(201, 202), range(204, 206), range(303, 305), range(400, 403), range(405, 409), range(411, 417), range(500, 505)) as $code) {
|
||||
$time = \DateTime::createFromFormat('U', time() + 5);
|
||||
$this->setNextResponse($code, array('Expires' => $time->format(DATE_RFC2822)));
|
||||
$this->setNextResponse($code, ['Expires' => $time->format(DATE_RFC2822)]);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertEquals($code, $this->response->getStatusCode());
|
||||
@@ -417,7 +417,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testDoesNotCacheResponsesWithExplicitNoStoreDirective()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time() + 5);
|
||||
$this->setNextResponse(200, array('Expires' => $time->format(DATE_RFC2822), 'Cache-Control' => 'no-store'));
|
||||
$this->setNextResponse(200, ['Expires' => $time->format(DATE_RFC2822), 'Cache-Control' => 'no-store']);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertTraceNotContains('store');
|
||||
@@ -436,7 +436,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testCachesResponsesWithExplicitNoCacheDirective()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time() + 5);
|
||||
$this->setNextResponse(200, array('Expires' => $time->format(DATE_RFC2822), 'Cache-Control' => 'public, no-cache'));
|
||||
$this->setNextResponse(200, ['Expires' => $time->format(DATE_RFC2822), 'Cache-Control' => 'public, no-cache']);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertTraceContains('store');
|
||||
@@ -446,7 +446,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testCachesResponsesWithAnExpirationHeader()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time() + 5);
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public', 'Expires' => $time->format(DATE_RFC2822)));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public', 'Expires' => $time->format(DATE_RFC2822)]);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
@@ -462,7 +462,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testCachesResponsesWithAMaxAgeDirective()
|
||||
{
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public, max-age=5'));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public, max-age=5']);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
@@ -478,7 +478,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testCachesResponsesWithASMaxAgeDirective()
|
||||
{
|
||||
$this->setNextResponse(200, array('Cache-Control' => 's-maxage=5'));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 's-maxage=5']);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
@@ -495,7 +495,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testCachesResponsesWithALastModifiedValidatorButNoFreshnessInformation()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public', 'Last-Modified' => $time->format(DATE_RFC2822)));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public', 'Last-Modified' => $time->format(DATE_RFC2822)]);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
@@ -506,7 +506,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testCachesResponsesWithAnETagValidatorButNoFreshnessInformation()
|
||||
{
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public', 'ETag' => '"123456"'));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public', 'ETag' => '"123456"']);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
@@ -519,7 +519,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$time1 = \DateTime::createFromFormat('U', time() - 5);
|
||||
$time2 = \DateTime::createFromFormat('U', time() + 5);
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public', 'Date' => $time1->format(DATE_RFC2822), 'Expires' => $time2->format(DATE_RFC2822)));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public', 'Date' => $time1->format(DATE_RFC2822), 'Expires' => $time2->format(DATE_RFC2822)]);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
@@ -543,7 +543,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testHitsCachedResponseWithMaxAgeDirective()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time() - 5);
|
||||
$this->setNextResponse(200, array('Date' => $time->format(DATE_RFC2822), 'Cache-Control' => 'public, max-age=10'));
|
||||
$this->setNextResponse(200, ['Date' => $time->format(DATE_RFC2822), 'Cache-Control' => 'public, max-age=10']);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
@@ -573,7 +573,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->cacheConfig['stale_while_revalidate'] = 10;
|
||||
|
||||
// The prescence of Last-Modified makes this cacheable (because Response::isValidateable() then).
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public, s-maxage=5', 'Last-Modified' => 'some while ago'), 'Old response');
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public, s-maxage=5', 'Last-Modified' => 'some while ago'], 'Old response');
|
||||
$this->request('GET', '/'); // warm the cache
|
||||
|
||||
// Now, lock the cache
|
||||
@@ -607,7 +607,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testHitsCachedResponseWithSMaxAgeDirective()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time() - 5);
|
||||
$this->setNextResponse(200, array('Date' => $time->format(DATE_RFC2822), 'Cache-Control' => 's-maxage=10, max-age=0'));
|
||||
$this->setNextResponse(200, ['Date' => $time->format(DATE_RFC2822), 'Cache-Control' => 's-maxage=10, max-age=0']);
|
||||
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
@@ -752,7 +752,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testDoesNotAssignDefaultTtlWhenResponseHasMustRevalidateDirective()
|
||||
{
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'must-revalidate'));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'must-revalidate']);
|
||||
|
||||
$this->cacheConfig['default_ttl'] = 10;
|
||||
$this->request('GET', '/');
|
||||
@@ -767,7 +767,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testFetchesFullResponseWhenCacheStaleAndNoValidatorsPresent()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time() + 5);
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public', 'Expires' => $time->format(DATE_RFC2822)));
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public', 'Expires' => $time->format(DATE_RFC2822)]);
|
||||
|
||||
// build initial request
|
||||
$this->request('GET', '/');
|
||||
@@ -807,7 +807,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testValidatesCachedResponsesWithLastModifiedAndNoFreshnessInformation()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($time) {
|
||||
$this->setNextResponse(200, [], 'Hello World', function ($request, $response) use ($time) {
|
||||
$response->headers->set('Cache-Control', 'public');
|
||||
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
|
||||
if ($time->format(DATE_RFC2822) == $request->headers->get('IF_MODIFIED_SINCE')) {
|
||||
@@ -845,7 +845,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$test = $this;
|
||||
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($test) {
|
||||
$this->setNextResponse(200, [], 'Hello World', function ($request, $response) use ($test) {
|
||||
$test->assertSame('OPTIONS', $request->getMethod());
|
||||
});
|
||||
|
||||
@@ -858,7 +858,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testValidatesCachedResponsesWithETagAndNoFreshnessInformation()
|
||||
{
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {
|
||||
$this->setNextResponse(200, [], 'Hello World', function ($request, $response) {
|
||||
$response->headers->set('Cache-Control', 'public');
|
||||
$response->headers->set('ETag', '"12345"');
|
||||
if ($response->getETag() == $request->headers->get('IF_NONE_MATCH')) {
|
||||
@@ -895,7 +895,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
|
||||
$this->setNextResponse(200, array(), 'Hello World', function (Request $request, Response $response) use ($time) {
|
||||
$this->setNextResponse(200, [], 'Hello World', function (Request $request, Response $response) use ($time) {
|
||||
$response->setSharedMaxAge(10);
|
||||
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
|
||||
});
|
||||
@@ -913,7 +913,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
sleep(15); // expire the cache
|
||||
|
||||
$this->setNextResponse(304, array(), '', function (Request $request, Response $response) use ($time) {
|
||||
$this->setNextResponse(304, [], '', function (Request $request, Response $response) use ($time) {
|
||||
$this->assertEquals($time->format(DATE_RFC2822), $request->headers->get('IF_MODIFIED_SINCE'));
|
||||
});
|
||||
|
||||
@@ -929,7 +929,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
$count = 0;
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($time, &$count) {
|
||||
$this->setNextResponse(200, [], 'Hello World', function ($request, $response) use ($time, &$count) {
|
||||
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
|
||||
$response->headers->set('Cache-Control', 'public');
|
||||
switch (++$count) {
|
||||
@@ -966,20 +966,20 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testPassesHeadRequestsThroughDirectlyOnPass()
|
||||
{
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {
|
||||
$this->setNextResponse(200, [], 'Hello World', function ($request, $response) {
|
||||
$response->setContent('');
|
||||
$response->setStatusCode(200);
|
||||
$this->assertEquals('HEAD', $request->getMethod());
|
||||
});
|
||||
|
||||
$this->request('HEAD', '/', array('HTTP_EXPECT' => 'something ...'));
|
||||
$this->request('HEAD', '/', ['HTTP_EXPECT' => 'something ...']);
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals('', $this->response->getContent());
|
||||
}
|
||||
|
||||
public function testUsesCacheToRespondToHeadRequestsWhenFresh()
|
||||
{
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {
|
||||
$this->setNextResponse(200, [], 'Hello World', function ($request, $response) {
|
||||
$response->headers->set('Cache-Control', 'public, max-age=10');
|
||||
$response->setContent('Hello World');
|
||||
$response->setStatusCode(200);
|
||||
@@ -1000,7 +1000,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testSendsNoContentWhenFresh()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) use ($time) {
|
||||
$this->setNextResponse(200, [], 'Hello World', function ($request, $response) use ($time) {
|
||||
$response->headers->set('Cache-Control', 'public, max-age=10');
|
||||
$response->headers->set('Last-Modified', $time->format(DATE_RFC2822));
|
||||
});
|
||||
@@ -1009,7 +1009,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals('Hello World', $this->response->getContent());
|
||||
|
||||
$this->request('GET', '/', array('HTTP_IF_MODIFIED_SINCE' => $time->format(DATE_RFC2822)));
|
||||
$this->request('GET', '/', ['HTTP_IF_MODIFIED_SINCE' => $time->format(DATE_RFC2822)]);
|
||||
$this->assertHttpKernelIsNotCalled();
|
||||
$this->assertEquals(304, $this->response->getStatusCode());
|
||||
$this->assertEquals('', $this->response->getContent());
|
||||
@@ -1017,7 +1017,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testInvalidatesCachedResponsesOnPost()
|
||||
{
|
||||
$this->setNextResponse(200, array(), 'Hello World', function ($request, $response) {
|
||||
$this->setNextResponse(200, [], 'Hello World', function ($request, $response) {
|
||||
if ('GET' == $request->getMethod()) {
|
||||
$response->setStatusCode(200);
|
||||
$response->headers->set('Cache-Control', 'public, max-age=500');
|
||||
@@ -1066,20 +1066,20 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testServesFromCacheWhenHeadersMatch()
|
||||
{
|
||||
$count = 0;
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'max-age=10000'), '', function ($request, $response) use (&$count) {
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'max-age=10000'], '', function ($request, $response) use (&$count) {
|
||||
$response->headers->set('Vary', 'Accept User-Agent Foo');
|
||||
$response->headers->set('Cache-Control', 'public, max-age=10');
|
||||
$response->headers->set('X-Response-Count', ++$count);
|
||||
$response->setContent($request->headers->get('USER_AGENT'));
|
||||
});
|
||||
|
||||
$this->request('GET', '/', array('HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/1.0'));
|
||||
$this->request('GET', '/', ['HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/1.0']);
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Bob/1.0', $this->response->getContent());
|
||||
$this->assertTraceContains('miss');
|
||||
$this->assertTraceContains('store');
|
||||
|
||||
$this->request('GET', '/', array('HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/1.0'));
|
||||
$this->request('GET', '/', ['HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/1.0']);
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Bob/1.0', $this->response->getContent());
|
||||
$this->assertTraceContains('fresh');
|
||||
@@ -1090,36 +1090,36 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testStoresMultipleResponsesWhenHeadersDiffer()
|
||||
{
|
||||
$count = 0;
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'max-age=10000'), '', function ($request, $response) use (&$count) {
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'max-age=10000'], '', function ($request, $response) use (&$count) {
|
||||
$response->headers->set('Vary', 'Accept User-Agent Foo');
|
||||
$response->headers->set('Cache-Control', 'public, max-age=10');
|
||||
$response->headers->set('X-Response-Count', ++$count);
|
||||
$response->setContent($request->headers->get('USER_AGENT'));
|
||||
});
|
||||
|
||||
$this->request('GET', '/', array('HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/1.0'));
|
||||
$this->request('GET', '/', ['HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/1.0']);
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertEquals('Bob/1.0', $this->response->getContent());
|
||||
$this->assertEquals(1, $this->response->headers->get('X-Response-Count'));
|
||||
|
||||
$this->request('GET', '/', array('HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/2.0'));
|
||||
$this->request('GET', '/', ['HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/2.0']);
|
||||
$this->assertEquals(200, $this->response->getStatusCode());
|
||||
$this->assertTraceContains('miss');
|
||||
$this->assertTraceContains('store');
|
||||
$this->assertEquals('Bob/2.0', $this->response->getContent());
|
||||
$this->assertEquals(2, $this->response->headers->get('X-Response-Count'));
|
||||
|
||||
$this->request('GET', '/', array('HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/1.0'));
|
||||
$this->request('GET', '/', ['HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/1.0']);
|
||||
$this->assertTraceContains('fresh');
|
||||
$this->assertEquals('Bob/1.0', $this->response->getContent());
|
||||
$this->assertEquals(1, $this->response->headers->get('X-Response-Count'));
|
||||
|
||||
$this->request('GET', '/', array('HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/2.0'));
|
||||
$this->request('GET', '/', ['HTTP_ACCEPT' => 'text/html', 'HTTP_USER_AGENT' => 'Bob/2.0']);
|
||||
$this->assertTraceContains('fresh');
|
||||
$this->assertEquals('Bob/2.0', $this->response->getContent());
|
||||
$this->assertEquals(2, $this->response->headers->get('X-Response-Count'));
|
||||
|
||||
$this->request('GET', '/', array('HTTP_USER_AGENT' => 'Bob/2.0'));
|
||||
$this->request('GET', '/', ['HTTP_USER_AGENT' => 'Bob/2.0']);
|
||||
$this->assertTraceContains('miss');
|
||||
$this->assertEquals('Bob/2.0', $this->response->getContent());
|
||||
$this->assertEquals(3, $this->response->headers->get('X-Response-Count'));
|
||||
@@ -1141,7 +1141,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
$this->setNextResponse();
|
||||
$this->cacheConfig['allow_reload'] = true;
|
||||
$this->request('GET', '/', array(), array(), false, array('Pragma' => 'no-cache'));
|
||||
$this->request('GET', '/', [], [], false, ['Pragma' => 'no-cache']);
|
||||
|
||||
$this->assertExceptionsAreCaught();
|
||||
}
|
||||
@@ -1158,30 +1158,30 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testEsiCacheSendsTheLowestTtl()
|
||||
{
|
||||
$responses = array(
|
||||
array(
|
||||
$responses = [
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => '<esi:include src="/foo" /> <esi:include src="/bar" />',
|
||||
'headers' => array(
|
||||
'headers' => [
|
||||
'Cache-Control' => 's-maxage=300',
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'Hello World!',
|
||||
'headers' => array('Cache-Control' => 's-maxage=200'),
|
||||
),
|
||||
array(
|
||||
'headers' => ['Cache-Control' => 's-maxage=200'],
|
||||
],
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'My name is Bobby.',
|
||||
'headers' => array('Cache-Control' => 's-maxage=100'),
|
||||
),
|
||||
);
|
||||
'headers' => ['Cache-Control' => 's-maxage=100'],
|
||||
],
|
||||
];
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('GET', '/', array(), array(), true);
|
||||
$this->request('GET', '/', [], [], true);
|
||||
$this->assertEquals('Hello World! My name is Bobby.', $this->response->getContent());
|
||||
|
||||
$this->assertEquals(100, $this->response->getTtl());
|
||||
@@ -1189,25 +1189,25 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testEsiCacheSendsTheLowestTtlForHeadRequests()
|
||||
{
|
||||
$responses = array(
|
||||
array(
|
||||
$responses = [
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'I am a long-lived master response, but I embed a short-lived resource: <esi:include src="/foo" />',
|
||||
'headers' => array(
|
||||
'headers' => [
|
||||
'Cache-Control' => 's-maxage=300',
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'I am a short-lived resource',
|
||||
'headers' => array('Cache-Control' => 's-maxage=100'),
|
||||
),
|
||||
);
|
||||
'headers' => ['Cache-Control' => 's-maxage=100'],
|
||||
],
|
||||
];
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('HEAD', '/', array(), array(), true);
|
||||
$this->request('HEAD', '/', [], [], true);
|
||||
|
||||
$this->assertEmpty($this->response->getContent());
|
||||
$this->assertEquals(100, $this->response->getTtl());
|
||||
@@ -1215,30 +1215,30 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testEsiCacheForceValidation()
|
||||
{
|
||||
$responses = array(
|
||||
array(
|
||||
$responses = [
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => '<esi:include src="/foo" /> <esi:include src="/bar" />',
|
||||
'headers' => array(
|
||||
'headers' => [
|
||||
'Cache-Control' => 's-maxage=300',
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'Hello World!',
|
||||
'headers' => array('ETag' => 'foobar'),
|
||||
),
|
||||
array(
|
||||
'headers' => ['ETag' => 'foobar'],
|
||||
],
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'My name is Bobby.',
|
||||
'headers' => array('Cache-Control' => 's-maxage=100'),
|
||||
),
|
||||
);
|
||||
'headers' => ['Cache-Control' => 's-maxage=100'],
|
||||
],
|
||||
];
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('GET', '/', array(), array(), true);
|
||||
$this->request('GET', '/', [], [], true);
|
||||
$this->assertEquals('Hello World! My name is Bobby.', $this->response->getContent());
|
||||
$this->assertNull($this->response->getTtl());
|
||||
$this->assertTrue($this->response->mustRevalidate());
|
||||
@@ -1248,25 +1248,25 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testEsiCacheForceValidationForHeadRequests()
|
||||
{
|
||||
$responses = array(
|
||||
array(
|
||||
$responses = [
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'I am the master response and use expiration caching, but I embed another resource: <esi:include src="/foo" />',
|
||||
'headers' => array(
|
||||
'headers' => [
|
||||
'Cache-Control' => 's-maxage=300',
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'I am the embedded resource and use validation caching',
|
||||
'headers' => array('ETag' => 'foobar'),
|
||||
),
|
||||
);
|
||||
'headers' => ['ETag' => 'foobar'],
|
||||
],
|
||||
];
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('HEAD', '/', array(), array(), true);
|
||||
$this->request('HEAD', '/', [], [], true);
|
||||
|
||||
// The response has been assembled from expiration and validation based resources
|
||||
// This can neither be cached nor revalidated, so it should be private/no cache
|
||||
@@ -1279,50 +1279,50 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testEsiRecalculateContentLengthHeader()
|
||||
{
|
||||
$responses = array(
|
||||
array(
|
||||
$responses = [
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => '<esi:include src="/foo" />',
|
||||
'headers' => array(
|
||||
'headers' => [
|
||||
'Content-Length' => 26,
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'Hello World!',
|
||||
'headers' => array(),
|
||||
),
|
||||
);
|
||||
'headers' => [],
|
||||
],
|
||||
];
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('GET', '/', array(), array(), true);
|
||||
$this->request('GET', '/', [], [], true);
|
||||
$this->assertEquals('Hello World!', $this->response->getContent());
|
||||
$this->assertEquals(12, $this->response->headers->get('Content-Length'));
|
||||
}
|
||||
|
||||
public function testEsiRecalculateContentLengthHeaderForHeadRequest()
|
||||
{
|
||||
$responses = array(
|
||||
array(
|
||||
$responses = [
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => '<esi:include src="/foo" />',
|
||||
'headers' => array(
|
||||
'headers' => [
|
||||
'Content-Length' => 26,
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'Hello World!',
|
||||
'headers' => array(),
|
||||
),
|
||||
);
|
||||
'headers' => [],
|
||||
],
|
||||
];
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('HEAD', '/', array(), array(), true);
|
||||
$this->request('HEAD', '/', [], [], true);
|
||||
|
||||
// https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13
|
||||
// "The Content-Length entity-header field indicates the size of the entity-body,
|
||||
@@ -1336,7 +1336,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testClientIpIsAlwaysLocalhostForForwardedRequests()
|
||||
{
|
||||
$this->setNextResponse();
|
||||
$this->request('GET', '/', array('REMOTE_ADDR' => '10.0.0.1'));
|
||||
$this->request('GET', '/', ['REMOTE_ADDR' => '10.0.0.1']);
|
||||
|
||||
$this->kernel->assert(function ($backendRequest) {
|
||||
$this->assertSame('127.0.0.1', $backendRequest->server->get('REMOTE_ADDR'));
|
||||
@@ -1351,25 +1351,25 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
Request::setTrustedProxies($existing, Request::HEADER_X_FORWARDED_ALL);
|
||||
|
||||
$this->setNextResponse();
|
||||
$this->request('GET', '/', array('REMOTE_ADDR' => '10.0.0.1'));
|
||||
$this->request('GET', '/', ['REMOTE_ADDR' => '10.0.0.1']);
|
||||
$this->assertSame($existing, Request::getTrustedProxies());
|
||||
|
||||
$existing = array_unique(array_merge($existing, array('127.0.0.1')));
|
||||
$existing = array_unique(array_merge($existing, ['127.0.0.1']));
|
||||
$this->kernel->assert(function ($backendRequest) use ($existing) {
|
||||
$this->assertSame($existing, Request::getTrustedProxies());
|
||||
$this->assertsame('10.0.0.1', $backendRequest->getClientIp());
|
||||
});
|
||||
|
||||
Request::setTrustedProxies(array(), -1);
|
||||
Request::setTrustedProxies([], -1);
|
||||
}
|
||||
|
||||
public function getTrustedProxyData()
|
||||
{
|
||||
return array(
|
||||
array(array()),
|
||||
array(array('10.0.0.2')),
|
||||
array(array('10.0.0.2', '127.0.0.1')),
|
||||
);
|
||||
return [
|
||||
[[]],
|
||||
[['10.0.0.2']],
|
||||
[['10.0.0.2', '127.0.0.1']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1378,7 +1378,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
public function testForwarderHeaderForForwardedRequests($forwarded, $expected)
|
||||
{
|
||||
$this->setNextResponse();
|
||||
$server = array('REMOTE_ADDR' => '10.0.0.1');
|
||||
$server = ['REMOTE_ADDR' => '10.0.0.1'];
|
||||
if (null !== $forwarded) {
|
||||
Request::setTrustedProxies($server, -1);
|
||||
$server['HTTP_FORWARDED'] = $forwarded;
|
||||
@@ -1389,42 +1389,42 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertSame($expected, $backendRequest->headers->get('Forwarded'));
|
||||
});
|
||||
|
||||
Request::setTrustedProxies(array(), -1);
|
||||
Request::setTrustedProxies([], -1);
|
||||
}
|
||||
|
||||
public function getForwardedData()
|
||||
{
|
||||
return array(
|
||||
array(null, 'for="10.0.0.1";host="localhost";proto=http'),
|
||||
array('for=10.0.0.2', 'for="10.0.0.2";host="localhost";proto=http, for="10.0.0.1"'),
|
||||
array('for=10.0.0.2, for=10.0.0.3', 'for="10.0.0.2";host="localhost";proto=http, for="10.0.0.3", for="10.0.0.1"'),
|
||||
);
|
||||
return [
|
||||
[null, 'for="10.0.0.1";host="localhost";proto=http'],
|
||||
['for=10.0.0.2', 'for="10.0.0.2";host="localhost";proto=http, for="10.0.0.1"'],
|
||||
['for=10.0.0.2, for=10.0.0.3', 'for="10.0.0.2";host="localhost";proto=http, for="10.0.0.3", for="10.0.0.1"'],
|
||||
];
|
||||
}
|
||||
|
||||
public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponses()
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
|
||||
$responses = array(
|
||||
array(
|
||||
$responses = [
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => '<esi:include src="/hey" />',
|
||||
'headers' => array(
|
||||
'headers' => [
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
'ETag' => 'hey',
|
||||
'Last-Modified' => $time->format(DATE_RFC2822),
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'Hey!',
|
||||
'headers' => array(),
|
||||
),
|
||||
);
|
||||
'headers' => [],
|
||||
],
|
||||
];
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('GET', '/', array(), array(), true);
|
||||
$this->request('GET', '/', [], [], true);
|
||||
$this->assertNull($this->response->getETag());
|
||||
$this->assertNull($this->response->getLastModified());
|
||||
}
|
||||
@@ -1433,26 +1433,26 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
{
|
||||
$time = \DateTime::createFromFormat('U', time());
|
||||
|
||||
$responses = array(
|
||||
array(
|
||||
$responses = [
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => '<esi:include src="/hey" />',
|
||||
'headers' => array(
|
||||
'headers' => [
|
||||
'Surrogate-Control' => 'content="ESI/1.0"',
|
||||
'ETag' => 'hey',
|
||||
'Last-Modified' => $time->format(DATE_RFC2822),
|
||||
),
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
[
|
||||
'status' => 200,
|
||||
'body' => 'Hey!',
|
||||
'headers' => array(),
|
||||
),
|
||||
);
|
||||
'headers' => [],
|
||||
],
|
||||
];
|
||||
|
||||
$this->setNextResponses($responses);
|
||||
|
||||
$this->request('HEAD', '/', array(), array(), true);
|
||||
$this->request('HEAD', '/', [], [], true);
|
||||
$this->assertEmpty($this->response->getContent());
|
||||
$this->assertNull($this->response->getETag());
|
||||
$this->assertNull($this->response->getLastModified());
|
||||
@@ -1460,11 +1460,11 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
public function testDoesNotCacheOptionsRequest()
|
||||
{
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public, s-maxage=60'), 'get');
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public, s-maxage=60'], 'get');
|
||||
$this->request('GET', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
|
||||
$this->setNextResponse(200, array('Cache-Control' => 'public, s-maxage=60'), 'options');
|
||||
$this->setNextResponse(200, ['Cache-Control' => 'public, s-maxage=60'], 'options');
|
||||
$this->request('OPTIONS', '/');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
|
||||
|
||||
@@ -41,12 +41,12 @@ class HttpCacheTestCase extends TestCase
|
||||
|
||||
$this->cache = null;
|
||||
$this->esi = null;
|
||||
$this->caches = array();
|
||||
$this->cacheConfig = array();
|
||||
$this->caches = [];
|
||||
$this->cacheConfig = [];
|
||||
|
||||
$this->request = null;
|
||||
$this->response = null;
|
||||
$this->responses = array();
|
||||
$this->responses = [];
|
||||
|
||||
$this->catch = false;
|
||||
|
||||
@@ -112,7 +112,7 @@ class HttpCacheTestCase extends TestCase
|
||||
$this->assertFalse($this->kernel->isCatchingExceptions());
|
||||
}
|
||||
|
||||
public function request($method, $uri = '/', $server = array(), $cookies = array(), $esi = false, $headers = array())
|
||||
public function request($method, $uri = '/', $server = [], $cookies = [], $esi = false, $headers = [])
|
||||
{
|
||||
if (null === $this->kernel) {
|
||||
throw new \LogicException('You must call setNextResponse() before calling request().');
|
||||
@@ -126,7 +126,7 @@ class HttpCacheTestCase extends TestCase
|
||||
|
||||
$this->esi = $esi ? new Esi() : null;
|
||||
$this->cache = new HttpCache($this->kernel, $this->store, $this->esi, $this->cacheConfig);
|
||||
$this->request = Request::create($uri, $method, array(), $cookies, array(), $server);
|
||||
$this->request = Request::create($uri, $method, [], $cookies, [], $server);
|
||||
$this->request->headers->add($headers);
|
||||
|
||||
$this->response = $this->cache->handle($this->request, HttpKernelInterface::MASTER_REQUEST, $this->catch);
|
||||
@@ -136,7 +136,7 @@ class HttpCacheTestCase extends TestCase
|
||||
|
||||
public function getMetaStorageValues()
|
||||
{
|
||||
$values = array();
|
||||
$values = [];
|
||||
foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(sys_get_temp_dir().'/http_cache/md', \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
|
||||
$values[] = file_get_contents($file);
|
||||
}
|
||||
@@ -145,7 +145,7 @@ class HttpCacheTestCase extends TestCase
|
||||
}
|
||||
|
||||
// A basic response with 200 status code and a tiny body.
|
||||
public function setNextResponse($statusCode = 200, array $headers = array(), $body = 'Hello World', \Closure $customizer = null)
|
||||
public function setNextResponse($statusCode = 200, array $headers = [], $body = 'Hello World', \Closure $customizer = null)
|
||||
{
|
||||
$this->kernel = new TestHttpKernel($body, $statusCode, $headers, $customizer);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class HttpCacheTestCase extends TestCase
|
||||
|
||||
$fp = opendir($directory);
|
||||
while (false !== $file = readdir($fp)) {
|
||||
if (!\in_array($file, array('.', '..'))) {
|
||||
if (!\in_array($file, ['.', '..'])) {
|
||||
if (is_link($directory.'/'.$file)) {
|
||||
unlink($directory.'/'.$file);
|
||||
} elseif (is_dir($directory.'/'.$file)) {
|
||||
|
||||
@@ -237,4 +237,233 @@ class ResponseCacheStrategyTest extends TestCase
|
||||
$this->assertSame('60', $masterResponse->headers->getCacheControlDirective('s-maxage'));
|
||||
$this->assertFalse($masterResponse->isValidateable());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider cacheControlMergingProvider
|
||||
*/
|
||||
public function testCacheControlMerging(array $expects, array $master, array $surrogates)
|
||||
{
|
||||
$cacheStrategy = new ResponseCacheStrategy();
|
||||
$buildResponse = function ($config) {
|
||||
$response = new Response();
|
||||
|
||||
foreach ($config as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'age':
|
||||
$response->headers->set('Age', $value);
|
||||
break;
|
||||
|
||||
case 'expires':
|
||||
$expires = clone $response->getDate();
|
||||
$expires->modify('+'.$value.' seconds');
|
||||
$response->setExpires($expires);
|
||||
break;
|
||||
|
||||
case 'max-age':
|
||||
$response->setMaxAge($value);
|
||||
break;
|
||||
|
||||
case 's-maxage':
|
||||
$response->setSharedMaxAge($value);
|
||||
break;
|
||||
|
||||
case 'private':
|
||||
$response->setPrivate();
|
||||
break;
|
||||
|
||||
case 'public':
|
||||
$response->setPublic();
|
||||
break;
|
||||
|
||||
default:
|
||||
$response->headers->addCacheControlDirective($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
};
|
||||
|
||||
foreach ($surrogates as $config) {
|
||||
$cacheStrategy->add($buildResponse($config));
|
||||
}
|
||||
|
||||
$response = $buildResponse($master);
|
||||
$cacheStrategy->update($response);
|
||||
|
||||
foreach ($expects as $key => $value) {
|
||||
if ('expires' === $key) {
|
||||
$this->assertSame($value, $response->getExpires()->format('U') - $response->getDate()->format('U'));
|
||||
} elseif ('age' === $key) {
|
||||
$this->assertSame($value, $response->getAge());
|
||||
} elseif (true === $value) {
|
||||
$this->assertTrue($response->headers->hasCacheControlDirective($key), sprintf('Cache-Control header must have "%s" flag', $key));
|
||||
} elseif (false === $value) {
|
||||
$this->assertFalse(
|
||||
$response->headers->hasCacheControlDirective($key),
|
||||
sprintf('Cache-Control header must NOT have "%s" flag', $key)
|
||||
);
|
||||
} else {
|
||||
$this->assertSame($value, $response->headers->getCacheControlDirective($key), sprintf('Cache-Control flag "%s" should be "%s"', $key, $value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function cacheControlMergingProvider()
|
||||
{
|
||||
yield 'result is public if all responses are public' => [
|
||||
['private' => false, 'public' => true],
|
||||
['public' => true],
|
||||
[
|
||||
['public' => true],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'result is private by default' => [
|
||||
['private' => true, 'public' => false],
|
||||
['public' => true],
|
||||
[
|
||||
[],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'combines public and private responses' => [
|
||||
['must-revalidate' => false, 'private' => true, 'public' => false],
|
||||
['public' => true],
|
||||
[
|
||||
['private' => true],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'inherits no-cache from surrogates' => [
|
||||
['no-cache' => true, 'public' => false],
|
||||
['public' => true],
|
||||
[
|
||||
['no-cache' => true],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'inherits no-store from surrogate' => [
|
||||
['no-store' => true, 'public' => false],
|
||||
['public' => true],
|
||||
[
|
||||
['no-store' => true],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'resolve to lowest possible max-age' => [
|
||||
['public' => false, 'private' => true, 's-maxage' => false, 'max-age' => '60'],
|
||||
['public' => true, 'max-age' => 3600],
|
||||
[
|
||||
['private' => true, 'max-age' => 60],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'resolves multiple max-age' => [
|
||||
['public' => false, 'private' => true, 's-maxage' => false, 'max-age' => '60'],
|
||||
['private' => true, 'max-age' => 100],
|
||||
[
|
||||
['private' => true, 'max-age' => 3600],
|
||||
['public' => true, 'max-age' => 60, 's-maxage' => 60],
|
||||
['private' => true, 'max-age' => 60],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'merge max-age and s-maxage' => [
|
||||
['public' => true, 's-maxage' => '60', 'max-age' => null],
|
||||
['public' => true, 's-maxage' => 3600],
|
||||
[
|
||||
['public' => true, 'max-age' => 60],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'result is private when combining private responses' => [
|
||||
['no-cache' => false, 'must-revalidate' => false, 'private' => true],
|
||||
['s-maxage' => 60, 'private' => true],
|
||||
[
|
||||
['s-maxage' => 60, 'private' => true],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'result can have s-maxage and max-age' => [
|
||||
['public' => true, 'private' => false, 's-maxage' => '60', 'max-age' => '30'],
|
||||
['s-maxage' => 100, 'max-age' => 2000],
|
||||
[
|
||||
['s-maxage' => 1000, 'max-age' => 30],
|
||||
['s-maxage' => 500, 'max-age' => 500],
|
||||
['s-maxage' => 60, 'max-age' => 1000],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'does not set headers without value' => [
|
||||
['max-age' => null, 's-maxage' => null, 'public' => null],
|
||||
['private' => true],
|
||||
[
|
||||
['private' => true],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'max-age 0 is sent to the client' => [
|
||||
['private' => true, 'max-age' => '0'],
|
||||
['max-age' => 0, 'private' => true],
|
||||
[
|
||||
['max-age' => 60, 'private' => true],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'max-age is relative to age' => [
|
||||
['max-age' => '240', 'age' => 60],
|
||||
['max-age' => 180],
|
||||
[
|
||||
['max-age' => 600, 'age' => 60],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'retains lowest age of all responses' => [
|
||||
['max-age' => '160', 'age' => 60],
|
||||
['max-age' => 600, 'age' => 60],
|
||||
[
|
||||
['max-age' => 120, 'age' => 20],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'max-age can be less than age, essentially expiring the response' => [
|
||||
['age' => 120, 'max-age' => '90'],
|
||||
['max-age' => 90, 'age' => 120],
|
||||
[
|
||||
['max-age' => 120, 'age' => 60],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'max-age is 0 regardless of age' => [
|
||||
['max-age' => '0'],
|
||||
['max-age' => 60],
|
||||
[
|
||||
['max-age' => 0, 'age' => 60],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'max-age is not negative' => [
|
||||
['max-age' => '0'],
|
||||
['max-age' => 0],
|
||||
[
|
||||
['max-age' => 0, 'age' => 60],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'calculates lowest Expires header' => [
|
||||
['expires' => 60],
|
||||
['expires' => 60],
|
||||
[
|
||||
['expires' => 120],
|
||||
],
|
||||
];
|
||||
|
||||
yield 'calculates Expires header relative to age' => [
|
||||
['expires' => 210, 'age' => 120],
|
||||
['expires' => 90],
|
||||
[
|
||||
['expires' => 600, 'age' => '120'],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,13 +187,13 @@ class SsiTest extends TestCase
|
||||
$response1 = new Response('foo');
|
||||
$response1->setStatusCode(404);
|
||||
$response2 = new Response('bar');
|
||||
$cache = $this->getCache(Request::create('/'), array($response1, $response2));
|
||||
$cache = $this->getCache(Request::create('/'), [$response1, $response2]);
|
||||
$this->assertEquals('bar', $ssi->handle($cache, '/', '/alt', false));
|
||||
}
|
||||
|
||||
protected function getCache($request, $response)
|
||||
{
|
||||
$cache = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpCache\HttpCache')->setMethods(array('getRequest', 'handle'))->disableOriginalConstructor()->getMock();
|
||||
$cache = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpCache\HttpCache')->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock();
|
||||
$cache->expects($this->any())
|
||||
->method('getRequest')
|
||||
->will($this->returnValue($request))
|
||||
|
||||
@@ -29,7 +29,7 @@ class StoreTest extends TestCase
|
||||
protected function setUp()
|
||||
{
|
||||
$this->request = Request::create('/');
|
||||
$this->response = new Response('hello world', 200, array());
|
||||
$this->response = new Response('hello world', 200, []);
|
||||
|
||||
HttpCacheTestCase::clearDirectory(sys_get_temp_dir().'/http_cache');
|
||||
|
||||
@@ -108,7 +108,7 @@ class StoreTest extends TestCase
|
||||
|
||||
public function testDoesNotFindAnEntryWithLookupWhenNoneExists()
|
||||
{
|
||||
$request = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
|
||||
$request = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
|
||||
|
||||
$this->assertNull($this->store->lookup($request));
|
||||
}
|
||||
@@ -137,7 +137,7 @@ class StoreTest extends TestCase
|
||||
$this->storeSimpleEntry();
|
||||
$response = $this->store->lookup($this->request);
|
||||
|
||||
$this->assertEquals($response->headers->all(), array_merge(array('content-length' => 4, 'x-body-file' => array($this->getStorePath($response->headers->get('X-Content-Digest')))), $this->response->headers->all()));
|
||||
$this->assertEquals($response->headers->all(), array_merge(['content-length' => 4, 'x-body-file' => [$this->getStorePath($response->headers->get('X-Content-Digest'))]], $this->response->headers->all()));
|
||||
}
|
||||
|
||||
public function testRestoresResponseContentFromEntityStoreWithLookup()
|
||||
@@ -165,9 +165,9 @@ class StoreTest extends TestCase
|
||||
|
||||
public function testDoesNotReturnEntriesThatVaryWithLookup()
|
||||
{
|
||||
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
|
||||
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam'));
|
||||
$res = new Response('test', 200, array('Vary' => 'Foo Bar'));
|
||||
$req1 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
|
||||
$req2 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam']);
|
||||
$res = new Response('test', 200, ['Vary' => 'Foo Bar']);
|
||||
$this->store->write($req1, $res);
|
||||
|
||||
$this->assertNull($this->store->lookup($req2));
|
||||
@@ -175,9 +175,9 @@ class StoreTest extends TestCase
|
||||
|
||||
public function testDoesNotReturnEntriesThatSlightlyVaryWithLookup()
|
||||
{
|
||||
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
|
||||
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bam'));
|
||||
$res = new Response('test', 200, array('Vary' => array('Foo', 'Bar')));
|
||||
$req1 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
|
||||
$req2 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bam']);
|
||||
$res = new Response('test', 200, ['Vary' => ['Foo', 'Bar']]);
|
||||
$this->store->write($req1, $res);
|
||||
|
||||
$this->assertNull($this->store->lookup($req2));
|
||||
@@ -185,16 +185,16 @@ class StoreTest extends TestCase
|
||||
|
||||
public function testStoresMultipleResponsesForEachVaryCombination()
|
||||
{
|
||||
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
|
||||
$res1 = new Response('test 1', 200, array('Vary' => 'Foo Bar'));
|
||||
$req1 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
|
||||
$res1 = new Response('test 1', 200, ['Vary' => 'Foo Bar']);
|
||||
$key = $this->store->write($req1, $res1);
|
||||
|
||||
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam'));
|
||||
$res2 = new Response('test 2', 200, array('Vary' => 'Foo Bar'));
|
||||
$req2 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam']);
|
||||
$res2 = new Response('test 2', 200, ['Vary' => 'Foo Bar']);
|
||||
$this->store->write($req2, $res2);
|
||||
|
||||
$req3 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Baz', 'HTTP_BAR' => 'Boom'));
|
||||
$res3 = new Response('test 3', 200, array('Vary' => 'Foo Bar'));
|
||||
$req3 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Baz', 'HTTP_BAR' => 'Boom']);
|
||||
$res3 = new Response('test 3', 200, ['Vary' => 'Foo Bar']);
|
||||
$this->store->write($req3, $res3);
|
||||
|
||||
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 3')), $this->store->lookup($req3)->getContent());
|
||||
@@ -206,18 +206,18 @@ class StoreTest extends TestCase
|
||||
|
||||
public function testOverwritesNonVaryingResponseWithStore()
|
||||
{
|
||||
$req1 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
|
||||
$res1 = new Response('test 1', 200, array('Vary' => 'Foo Bar'));
|
||||
$req1 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
|
||||
$res1 = new Response('test 1', 200, ['Vary' => 'Foo Bar']);
|
||||
$key = $this->store->write($req1, $res1);
|
||||
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 1')), $this->store->lookup($req1)->getContent());
|
||||
|
||||
$req2 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam'));
|
||||
$res2 = new Response('test 2', 200, array('Vary' => 'Foo Bar'));
|
||||
$req2 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Bling', 'HTTP_BAR' => 'Bam']);
|
||||
$res2 = new Response('test 2', 200, ['Vary' => 'Foo Bar']);
|
||||
$this->store->write($req2, $res2);
|
||||
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 2')), $this->store->lookup($req2)->getContent());
|
||||
|
||||
$req3 = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
|
||||
$res3 = new Response('test 3', 200, array('Vary' => 'Foo Bar'));
|
||||
$req3 = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
|
||||
$res3 = new Response('test 3', 200, ['Vary' => 'Foo Bar']);
|
||||
$key = $this->store->write($req3, $res3);
|
||||
$this->assertEquals($this->getStorePath('en'.hash('sha256', 'test 3')), $this->store->lookup($req3)->getContent());
|
||||
|
||||
@@ -226,7 +226,7 @@ class StoreTest extends TestCase
|
||||
|
||||
public function testLocking()
|
||||
{
|
||||
$req = Request::create('/test', 'get', array(), array(), array(), array('HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar'));
|
||||
$req = Request::create('/test', 'get', [], [], [], ['HTTP_FOO' => 'Foo', 'HTTP_BAR' => 'Bar']);
|
||||
$this->assertTrue($this->store->lock($req));
|
||||
|
||||
$path = $this->store->lock($req);
|
||||
@@ -263,14 +263,14 @@ class StoreTest extends TestCase
|
||||
$this->assertEmpty($this->getStoreMetadata($requestHttps));
|
||||
}
|
||||
|
||||
protected function storeSimpleEntry($path = null, $headers = array())
|
||||
protected function storeSimpleEntry($path = null, $headers = [])
|
||||
{
|
||||
if (null === $path) {
|
||||
$path = '/test';
|
||||
}
|
||||
|
||||
$this->request = Request::create($path, 'get', array(), array(), array(), $headers);
|
||||
$this->response = new Response('test', 200, array('Cache-Control' => 'max-age=420'));
|
||||
$this->request = Request::create($path, 'get', [], [], [], $headers);
|
||||
$this->response = new Response('test', 200, ['Cache-Control' => 'max-age=420']);
|
||||
|
||||
return $this->store->write($this->request, $this->response);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class SubRequestHandlerTest extends TestCase
|
||||
|
||||
public function testTrustedHeadersAreKept()
|
||||
{
|
||||
Request::setTrustedProxies(array('10.0.0.1'), -1);
|
||||
Request::setTrustedProxies(['10.0.0.1'], -1);
|
||||
$globalState = $this->getGlobalState();
|
||||
|
||||
$request = Request::create('/');
|
||||
@@ -82,7 +82,7 @@ class SubRequestHandlerTest extends TestCase
|
||||
|
||||
public function testTrustedForwardedHeader()
|
||||
{
|
||||
Request::setTrustedProxies(array('10.0.0.1'), -1);
|
||||
Request::setTrustedProxies(['10.0.0.1'], -1);
|
||||
$globalState = $this->getGlobalState();
|
||||
|
||||
$request = Request::create('/');
|
||||
@@ -104,7 +104,7 @@ class SubRequestHandlerTest extends TestCase
|
||||
|
||||
public function testTrustedXForwardedForHeader()
|
||||
{
|
||||
Request::setTrustedProxies(array('10.0.0.1'), -1);
|
||||
Request::setTrustedProxies(['10.0.0.1'], -1);
|
||||
$globalState = $this->getGlobalState();
|
||||
|
||||
$request = Request::create('/');
|
||||
@@ -127,10 +127,10 @@ class SubRequestHandlerTest extends TestCase
|
||||
|
||||
private function getGlobalState()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
Request::getTrustedProxies(),
|
||||
Request::getTrustedHeaderSet(),
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface,
|
||||
|
||||
public function assert(\Closure $callback)
|
||||
{
|
||||
$trustedConfig = array(Request::getTrustedProxies(), Request::getTrustedHeaderSet());
|
||||
$trustedConfig = [Request::getTrustedProxies(), Request::getTrustedHeaderSet()];
|
||||
|
||||
list($trustedProxies, $trustedHeaderSet, $backendRequest) = $this->backendRequest;
|
||||
Request::setTrustedProxies($trustedProxies, $trustedHeaderSet);
|
||||
@@ -57,7 +57,7 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface,
|
||||
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false)
|
||||
{
|
||||
$this->catch = $catch;
|
||||
$this->backendRequest = array(Request::getTrustedProxies(), Request::getTrustedHeaderSet(), $request);
|
||||
$this->backendRequest = [Request::getTrustedProxies(), Request::getTrustedHeaderSet(), $request];
|
||||
|
||||
return parent::handle($request, $type, $catch);
|
||||
}
|
||||
@@ -69,12 +69,12 @@ class TestHttpKernel extends HttpKernel implements ControllerResolverInterface,
|
||||
|
||||
public function getController(Request $request)
|
||||
{
|
||||
return array($this, 'callController');
|
||||
return [$this, 'callController'];
|
||||
}
|
||||
|
||||
public function getArguments(Request $request, $controller)
|
||||
{
|
||||
return array($request);
|
||||
return [$request];
|
||||
}
|
||||
|
||||
public function callController(Request $request)
|
||||
|
||||
@@ -21,9 +21,9 @@ use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
|
||||
class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInterface, ArgumentResolverInterface
|
||||
{
|
||||
protected $bodies = array();
|
||||
protected $statuses = array();
|
||||
protected $headers = array();
|
||||
protected $bodies = [];
|
||||
protected $statuses = [];
|
||||
protected $headers = [];
|
||||
protected $called = false;
|
||||
protected $backendRequest;
|
||||
|
||||
@@ -52,12 +52,12 @@ class TestMultipleHttpKernel extends HttpKernel implements ControllerResolverInt
|
||||
|
||||
public function getController(Request $request)
|
||||
{
|
||||
return array($this, 'callController');
|
||||
return [$this, 'callController'];
|
||||
}
|
||||
|
||||
public function getArguments(Request $request, $controller)
|
||||
{
|
||||
return array($request);
|
||||
return [$request];
|
||||
}
|
||||
|
||||
public function callController(Request $request)
|
||||
|
||||
Reference in New Issue
Block a user