updated packages

This commit is contained in:
2019-05-18 09:06:43 +00:00
parent 901d16349e
commit e9487fa58a
2025 changed files with 30366 additions and 49653 deletions

View File

@@ -35,7 +35,7 @@ class ChainCacheClearerTest extends TestCase
->expects($this->once())
->method('clear');
$chainClearer = new ChainCacheClearer(array($clearer));
$chainClearer = new ChainCacheClearer([$clearer]);
$chainClearer->clear(self::$cacheDir);
}

View File

@@ -24,7 +24,7 @@ class Psr6CacheClearerTest extends TestCase
->expects($this->once())
->method('clear');
(new Psr6CacheClearer(array('pool' => $pool)))->clear('');
(new Psr6CacheClearer(['pool' => $pool]))->clear('');
}
public function testClearPool()
@@ -34,7 +34,7 @@ class Psr6CacheClearerTest extends TestCase
->expects($this->once())
->method('clear');
(new Psr6CacheClearer(array('pool' => $pool)))->clearPool('pool');
(new Psr6CacheClearer(['pool' => $pool]))->clearPool('pool');
}
/**

View File

@@ -34,7 +34,7 @@ class CacheWarmerAggregateTest extends TestCase
$warmer
->expects($this->once())
->method('warmUp');
$aggregate = new CacheWarmerAggregate(array($warmer));
$aggregate = new CacheWarmerAggregate([$warmer]);
$aggregate->warmUp(self::$cacheDir);
}
@@ -48,7 +48,7 @@ class CacheWarmerAggregateTest extends TestCase
->expects($this->once())
->method('warmUp');
$aggregate = new CacheWarmerAggregate(array($warmer));
$aggregate = new CacheWarmerAggregate([$warmer]);
$aggregate->enableOptionalWarmers();
$aggregate->warmUp(self::$cacheDir);
}
@@ -64,7 +64,7 @@ class CacheWarmerAggregateTest extends TestCase
->expects($this->never())
->method('warmUp');
$aggregate = new CacheWarmerAggregate(array($warmer));
$aggregate = new CacheWarmerAggregate([$warmer]);
$aggregate->warmUp(self::$cacheDir);
}

View File

@@ -70,7 +70,7 @@ class ClientTest extends TestCase
$response->headers->setCookie($cookie2 = new Cookie('foo1', 'bar1', \DateTime::createFromFormat('j-M-Y H:i:s T', '15-Feb-2009 20:00:00 GMT')->format('U'), '/foo', 'http://example.com', true, true, false, null));
$domResponse = $m->invoke($client, $response);
$this->assertSame((string) $cookie1, $domResponse->getHeader('Set-Cookie'));
$this->assertSame(array((string) $cookie1, (string) $cookie2), $domResponse->getHeader('Set-Cookie', false));
$this->assertSame([(string) $cookie1, (string) $cookie2], $domResponse->getHeader('Set-Cookie', false));
}
public function testFilterResponseSupportsStreamedResponses()
@@ -99,14 +99,14 @@ class ClientTest extends TestCase
$kernel = new TestHttpKernel();
$client = new Client($kernel);
$files = array(
array('tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => null, 'error' => UPLOAD_ERR_OK),
$files = [
['tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => null, 'error' => UPLOAD_ERR_OK],
new UploadedFile($source, 'original', 'mime/original', UPLOAD_ERR_OK, true),
);
];
$file = null;
foreach ($files as $file) {
$client->request('POST', '/', array(), array('foo' => $file));
$client->request('POST', '/', [], ['foo' => $file]);
$files = $client->getRequest()->files->all();
@@ -130,9 +130,9 @@ class ClientTest extends TestCase
$kernel = new TestHttpKernel();
$client = new Client($kernel);
$file = array('tmp_name' => '', 'name' => '', 'type' => '', 'size' => 0, 'error' => UPLOAD_ERR_NO_FILE);
$file = ['tmp_name' => '', 'name' => '', 'type' => '', 'size' => 0, 'error' => UPLOAD_ERR_NO_FILE];
$client->request('POST', '/', array(), array('foo' => $file));
$client->request('POST', '/', [], ['foo' => $file]);
$files = $client->getRequest()->files->all();
@@ -149,8 +149,8 @@ class ClientTest extends TestCase
$file = $this
->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
->setConstructorArgs(array($source, 'original', 'mime/original', UPLOAD_ERR_OK, true))
->setMethods(array('getSize', 'getClientSize'))
->setConstructorArgs([$source, 'original', 'mime/original', UPLOAD_ERR_OK, true])
->setMethods(['getSize', 'getClientSize'])
->getMock()
;
/* should be modified when the getClientSize will be removed */
@@ -163,7 +163,7 @@ class ClientTest extends TestCase
->will($this->returnValue(INF))
;
$client->request('POST', '/', array(), array($file));
$client->request('POST', '/', [], [$file]);
$files = $client->getRequest()->files->all();

View File

@@ -23,86 +23,86 @@ class ServiceValueResolverTest extends TestCase
{
public function testDoNotSupportWhenControllerDoNotExists()
{
$resolver = new ServiceValueResolver(new ServiceLocator(array()));
$resolver = new ServiceValueResolver(new ServiceLocator([]));
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
$request = $this->requestWithAttributes(array('_controller' => 'my_controller'));
$request = $this->requestWithAttributes(['_controller' => 'my_controller']);
$this->assertFalse($resolver->supports($request, $argument));
}
public function testExistingController()
{
$resolver = new ServiceValueResolver(new ServiceLocator(array(
$resolver = new ServiceValueResolver(new ServiceLocator([
'App\\Controller\\Mine::method' => function () {
return new ServiceLocator(array(
return new ServiceLocator([
'dummy' => function () {
return new DummyService();
},
));
]);
},
)));
]));
$request = $this->requestWithAttributes(array('_controller' => 'App\\Controller\\Mine::method'));
$request = $this->requestWithAttributes(['_controller' => 'App\\Controller\\Mine::method']);
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
$this->assertTrue($resolver->supports($request, $argument));
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
$this->assertYieldEquals([new DummyService()], $resolver->resolve($request, $argument));
}
public function testExistingControllerWithATrailingBackSlash()
{
$resolver = new ServiceValueResolver(new ServiceLocator(array(
$resolver = new ServiceValueResolver(new ServiceLocator([
'App\\Controller\\Mine::method' => function () {
return new ServiceLocator(array(
return new ServiceLocator([
'dummy' => function () {
return new DummyService();
},
));
]);
},
)));
]));
$request = $this->requestWithAttributes(array('_controller' => '\\App\\Controller\\Mine::method'));
$request = $this->requestWithAttributes(['_controller' => '\\App\\Controller\\Mine::method']);
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
$this->assertTrue($resolver->supports($request, $argument));
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
$this->assertYieldEquals([new DummyService()], $resolver->resolve($request, $argument));
}
public function testExistingControllerWithMethodNameStartUppercase()
{
$resolver = new ServiceValueResolver(new ServiceLocator(array(
$resolver = new ServiceValueResolver(new ServiceLocator([
'App\\Controller\\Mine::method' => function () {
return new ServiceLocator(array(
return new ServiceLocator([
'dummy' => function () {
return new DummyService();
},
));
]);
},
)));
$request = $this->requestWithAttributes(array('_controller' => 'App\\Controller\\Mine::Method'));
]));
$request = $this->requestWithAttributes(['_controller' => 'App\\Controller\\Mine::Method']);
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
$this->assertTrue($resolver->supports($request, $argument));
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
$this->assertYieldEquals([new DummyService()], $resolver->resolve($request, $argument));
}
public function testControllerNameIsAnArray()
{
$resolver = new ServiceValueResolver(new ServiceLocator(array(
$resolver = new ServiceValueResolver(new ServiceLocator([
'App\\Controller\\Mine::method' => function () {
return new ServiceLocator(array(
return new ServiceLocator([
'dummy' => function () {
return new DummyService();
},
));
]);
},
)));
]));
$request = $this->requestWithAttributes(array('_controller' => array('App\\Controller\\Mine', 'method')));
$request = $this->requestWithAttributes(['_controller' => ['App\\Controller\\Mine', 'method']]);
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
$this->assertTrue($resolver->supports($request, $argument));
$this->assertYieldEquals(array(new DummyService()), $resolver->resolve($request, $argument));
$this->assertYieldEquals([new DummyService()], $resolver->resolve($request, $argument));
}
/**
@@ -119,7 +119,7 @@ class ServiceValueResolverTest extends TestCase
$container->compile();
$request = $this->requestWithAttributes(array('_controller' => array(DummyController::class, 'index')));
$request = $this->requestWithAttributes(['_controller' => [DummyController::class, 'index']]);
$argument = new ArgumentMetadata('dummy', DummyService::class, false, false, null);
$container->get('argument_resolver.service')->resolve($request, $argument)->current();
}
@@ -137,7 +137,7 @@ class ServiceValueResolverTest extends TestCase
private function assertYieldEquals(array $expected, \Generator $generator)
{
$args = array();
$args = [];
foreach ($generator as $arg) {
$args[] = $arg;
}

View File

@@ -40,33 +40,33 @@ class ArgumentResolverTest extends TestCase
public function testDefaultState()
{
$this->assertEquals(self::$resolver, new ArgumentResolver());
$this->assertNotEquals(self::$resolver, new ArgumentResolver(null, array(new RequestAttributeValueResolver())));
$this->assertNotEquals(self::$resolver, new ArgumentResolver(null, [new RequestAttributeValueResolver()]));
}
public function testGetArguments()
{
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$controller = array(new self(), 'controllerWithFoo');
$controller = [new self(), 'controllerWithFoo'];
$this->assertEquals(array('foo'), self::$resolver->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');
$this->assertEquals(['foo'], self::$resolver->getArguments($request, $controller), '->getArguments() returns an array of arguments for the controller method');
}
public function testGetArgumentsReturnsEmptyArrayWhenNoArguments()
{
$request = Request::create('/');
$controller = array(new self(), 'controllerWithoutArguments');
$controller = [new self(), 'controllerWithoutArguments'];
$this->assertEquals(array(), self::$resolver->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');
$this->assertEquals([], self::$resolver->getArguments($request, $controller), '->getArguments() returns an empty array if the method takes no arguments');
}
public function testGetArgumentsUsesDefaultValue()
{
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$controller = array(new self(), 'controllerWithFooAndDefaultBar');
$controller = [new self(), 'controllerWithFooAndDefaultBar'];
$this->assertEquals(array('foo', null), self::$resolver->getArguments($request, $controller), '->getArguments() uses default values if present');
$this->assertEquals(['foo', null], self::$resolver->getArguments($request, $controller), '->getArguments() uses default values if present');
}
public function testGetArgumentsOverrideDefaultValueByRequestAttribute()
@@ -74,9 +74,9 @@ class ArgumentResolverTest extends TestCase
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$request->attributes->set('bar', 'bar');
$controller = array(new self(), 'controllerWithFooAndDefaultBar');
$controller = [new self(), 'controllerWithFooAndDefaultBar'];
$this->assertEquals(array('foo', 'bar'), self::$resolver->getArguments($request, $controller), '->getArguments() overrides default values if provided in the request attributes');
$this->assertEquals(['foo', 'bar'], self::$resolver->getArguments($request, $controller), '->getArguments() overrides default values if provided in the request attributes');
}
public function testGetArgumentsFromClosure()
@@ -85,7 +85,7 @@ class ArgumentResolverTest extends TestCase
$request->attributes->set('foo', 'foo');
$controller = function ($foo) {};
$this->assertEquals(array('foo'), self::$resolver->getArguments($request, $controller));
$this->assertEquals(['foo'], self::$resolver->getArguments($request, $controller));
}
public function testGetArgumentsUsesDefaultValueFromClosure()
@@ -94,7 +94,7 @@ class ArgumentResolverTest extends TestCase
$request->attributes->set('foo', 'foo');
$controller = function ($foo, $bar = 'bar') {};
$this->assertEquals(array('foo', 'bar'), self::$resolver->getArguments($request, $controller));
$this->assertEquals(['foo', 'bar'], self::$resolver->getArguments($request, $controller));
}
public function testGetArgumentsFromInvokableObject()
@@ -103,12 +103,12 @@ class ArgumentResolverTest extends TestCase
$request->attributes->set('foo', 'foo');
$controller = new self();
$this->assertEquals(array('foo', null), self::$resolver->getArguments($request, $controller));
$this->assertEquals(['foo', null], self::$resolver->getArguments($request, $controller));
// Test default bar overridden by request attribute
$request->attributes->set('bar', 'bar');
$this->assertEquals(array('foo', 'bar'), self::$resolver->getArguments($request, $controller));
$this->assertEquals(['foo', 'bar'], self::$resolver->getArguments($request, $controller));
}
public function testGetArgumentsFromFunctionName()
@@ -118,7 +118,7 @@ class ArgumentResolverTest extends TestCase
$request->attributes->set('foobar', 'foobar');
$controller = __NAMESPACE__.'\controller_function';
$this->assertEquals(array('foo', 'foobar'), self::$resolver->getArguments($request, $controller));
$this->assertEquals(['foo', 'foobar'], self::$resolver->getArguments($request, $controller));
}
public function testGetArgumentsFailsOnUnresolvedValue()
@@ -126,7 +126,7 @@ class ArgumentResolverTest extends TestCase
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$request->attributes->set('foobar', 'foobar');
$controller = array(new self(), 'controllerWithFooBarFoobar');
$controller = [new self(), 'controllerWithFooBarFoobar'];
try {
self::$resolver->getArguments($request, $controller);
@@ -139,27 +139,27 @@ class ArgumentResolverTest extends TestCase
public function testGetArgumentsInjectsRequest()
{
$request = Request::create('/');
$controller = array(new self(), 'controllerWithRequest');
$controller = [new self(), 'controllerWithRequest'];
$this->assertEquals(array($request), self::$resolver->getArguments($request, $controller), '->getArguments() injects the request');
$this->assertEquals([$request], self::$resolver->getArguments($request, $controller), '->getArguments() injects the request');
}
public function testGetArgumentsInjectsExtendingRequest()
{
$request = ExtendingRequest::create('/');
$controller = array(new self(), 'controllerWithExtendingRequest');
$controller = [new self(), 'controllerWithExtendingRequest'];
$this->assertEquals(array($request), self::$resolver->getArguments($request, $controller), '->getArguments() injects the request when extended');
$this->assertEquals([$request], self::$resolver->getArguments($request, $controller), '->getArguments() injects the request when extended');
}
public function testGetVariadicArguments()
{
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$request->attributes->set('bar', array('foo', 'bar'));
$controller = array(new VariadicController(), 'action');
$request->attributes->set('bar', ['foo', 'bar']);
$controller = [new VariadicController(), 'action'];
$this->assertEquals(array('foo', 'foo', 'bar'), self::$resolver->getArguments($request, $controller));
$this->assertEquals(['foo', 'foo', 'bar'], self::$resolver->getArguments($request, $controller));
}
/**
@@ -170,7 +170,7 @@ class ArgumentResolverTest extends TestCase
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$request->attributes->set('bar', 'foo');
$controller = array(new VariadicController(), 'action');
$controller = [new VariadicController(), 'action'];
self::$resolver->getArguments($request, $controller);
}
@@ -182,7 +182,7 @@ class ArgumentResolverTest extends TestCase
{
$factory = new ArgumentMetadataFactory();
$valueResolver = $this->getMockBuilder(ArgumentValueResolverInterface::class)->getMock();
$resolver = new ArgumentResolver($factory, array($valueResolver));
$resolver = new ArgumentResolver($factory, [$valueResolver]);
$valueResolver->expects($this->any())->method('supports')->willReturn(true);
$valueResolver->expects($this->any())->method('resolve')->willReturn('foo');
@@ -190,7 +190,7 @@ class ArgumentResolverTest extends TestCase
$request = Request::create('/');
$request->attributes->set('foo', 'foo');
$request->attributes->set('bar', 'foo');
$controller = array($this, 'controllerWithFooAndDefaultBar');
$controller = [$this, 'controllerWithFooAndDefaultBar'];
$resolver->getArguments($request, $controller);
}
@@ -200,7 +200,7 @@ class ArgumentResolverTest extends TestCase
public function testIfExceptionIsThrownWhenMissingAnArgument()
{
$request = Request::create('/');
$controller = array($this, 'controllerWithFoo');
$controller = [$this, 'controllerWithFoo'];
self::$resolver->getArguments($request, $controller);
}
@@ -211,18 +211,18 @@ class ArgumentResolverTest extends TestCase
$request->attributes->set('foo', 'foo');
$request->attributes->set('bar', new \stdClass());
$request->attributes->set('mandatory', 'mandatory');
$controller = array(new NullableController(), 'action');
$controller = [new NullableController(), 'action'];
$this->assertEquals(array('foo', new \stdClass(), 'value', 'mandatory'), self::$resolver->getArguments($request, $controller));
$this->assertEquals(['foo', new \stdClass(), 'value', 'mandatory'], self::$resolver->getArguments($request, $controller));
}
public function testGetNullableArgumentsWithDefaults()
{
$request = Request::create('/');
$request->attributes->set('mandatory', 'mandatory');
$controller = array(new NullableController(), 'action');
$controller = [new NullableController(), 'action'];
$this->assertEquals(array(null, null, 'value', 'mandatory'), self::$resolver->getArguments($request, $controller));
$this->assertEquals([null, null, 'value', 'mandatory'], self::$resolver->getArguments($request, $controller));
}
public function testGetSessionArguments()
@@ -230,9 +230,9 @@ class ArgumentResolverTest extends TestCase
$session = new Session(new MockArraySessionStorage());
$request = Request::create('/');
$request->setSession($session);
$controller = array($this, 'controllerWithSession');
$controller = [$this, 'controllerWithSession'];
$this->assertEquals(array($session), self::$resolver->getArguments($request, $controller));
$this->assertEquals([$session], self::$resolver->getArguments($request, $controller));
}
public function testGetSessionArgumentsWithExtendedSession()
@@ -240,9 +240,9 @@ class ArgumentResolverTest extends TestCase
$session = new ExtendingSession(new MockArraySessionStorage());
$request = Request::create('/');
$request->setSession($session);
$controller = array($this, 'controllerWithExtendingSession');
$controller = [$this, 'controllerWithExtendingSession'];
$this->assertEquals(array($session), self::$resolver->getArguments($request, $controller));
$this->assertEquals([$session], self::$resolver->getArguments($request, $controller));
}
public function testGetSessionArgumentsWithInterface()
@@ -250,9 +250,9 @@ class ArgumentResolverTest extends TestCase
$session = $this->getMockBuilder(SessionInterface::class)->getMock();
$request = Request::create('/');
$request->setSession($session);
$controller = array($this, 'controllerWithSessionInterface');
$controller = [$this, 'controllerWithSessionInterface'];
$this->assertEquals(array($session), self::$resolver->getArguments($request, $controller));
$this->assertEquals([$session], self::$resolver->getArguments($request, $controller));
}
/**
@@ -263,7 +263,7 @@ class ArgumentResolverTest extends TestCase
$session = $this->getMockBuilder(SessionInterface::class)->getMock();
$request = Request::create('/');
$request->setSession($session);
$controller = array($this, 'controllerWithExtendingSession');
$controller = [$this, 'controllerWithExtendingSession'];
self::$resolver->getArguments($request, $controller);
}
@@ -276,7 +276,7 @@ class ArgumentResolverTest extends TestCase
$session = new Session(new MockArraySessionStorage());
$request = Request::create('/');
$request->setSession($session);
$controller = array($this, 'controllerWithExtendingSession');
$controller = [$this, 'controllerWithExtendingSession'];
self::$resolver->getArguments($request, $controller);
}
@@ -287,7 +287,7 @@ class ArgumentResolverTest extends TestCase
public function testGetSessionMissMatchOnNull()
{
$request = Request::create('/');
$controller = array($this, 'controllerWithExtendingSession');
$controller = [$this, 'controllerWithExtendingSession'];
self::$resolver->getArguments($request, $controller);
}

View File

@@ -137,12 +137,12 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$container->expects($this->atLeastOnce())
->method('getRemovedIds')
->with()
->will($this->returnValue(array(ControllerTestService::class => true)))
->will($this->returnValue([ControllerTestService::class => true]))
;
$resolver = $this->createControllerResolver(null, $container);
$request = Request::create('/');
$request->attributes->set('_controller', array(ControllerTestService::class, 'action'));
$request->attributes->set('_controller', [ControllerTestService::class, 'action']);
$resolver->getController($request);
}
@@ -165,7 +165,7 @@ class ContainerControllerResolverTest extends ControllerResolverTest
$container->expects($this->atLeastOnce())
->method('getRemovedIds')
->with()
->will($this->returnValue(array('app.my_controller' => true)))
->will($this->returnValue(['app.my_controller' => true]))
;
$resolver = $this->createControllerResolver(null, $container);
@@ -178,23 +178,23 @@ class ContainerControllerResolverTest extends ControllerResolverTest
public function getUndefinedControllers()
{
$tests = parent::getUndefinedControllers();
$tests[0] = array('foo', \InvalidArgumentException::class, 'Controller "foo" does neither exist as service nor as class');
$tests[1] = array('oof::bar', \InvalidArgumentException::class, 'Controller "oof" does neither exist as service nor as class');
$tests[2] = array(array('oof', 'bar'), \InvalidArgumentException::class, 'Controller "oof" does neither exist as service nor as class');
$tests[] = array(
array(ControllerTestService::class, 'action'),
$tests[0] = ['foo', \InvalidArgumentException::class, 'Controller "foo" does neither exist as service nor as class'];
$tests[1] = ['oof::bar', \InvalidArgumentException::class, 'Controller "oof" does neither exist as service nor as class'];
$tests[2] = [['oof', 'bar'], \InvalidArgumentException::class, 'Controller "oof" does neither exist as service nor as class'];
$tests[] = [
[ControllerTestService::class, 'action'],
\InvalidArgumentException::class,
'Controller "Symfony\Component\HttpKernel\Tests\Controller\ControllerTestService" has required constructor arguments and does not exist in the container. Did you forget to define such a service?',
);
$tests[] = array(
];
$tests[] = [
ControllerTestService::class.'::action',
\InvalidArgumentException::class, 'Controller "Symfony\Component\HttpKernel\Tests\Controller\ControllerTestService" has required constructor arguments and does not exist in the container. Did you forget to define such a service?',
);
$tests[] = array(
];
$tests[] = [
InvokableControllerService::class,
\InvalidArgumentException::class,
'Controller "Symfony\Component\HttpKernel\Tests\Controller\InvokableControllerService" has required constructor arguments and does not exist in the container. Did you forget to define such a service?',
);
];
return $tests;
}

View File

@@ -55,9 +55,9 @@ class ControllerResolverTest extends TestCase
$object = new ControllerTest();
$request = Request::create('/');
$request->attributes->set('_controller', array($object, 'publicAction'));
$request->attributes->set('_controller', [$object, 'publicAction']);
$controller = $resolver->getController($request);
$this->assertSame(array($object, 'publicAction'), $controller);
$this->assertSame([$object, 'publicAction'], $controller);
}
public function testGetControllerWithClassAndMethodAsArray()
@@ -65,7 +65,7 @@ class ControllerResolverTest extends TestCase
$resolver = $this->createControllerResolver();
$request = Request::create('/');
$request->attributes->set('_controller', array(ControllerTest::class, 'publicAction'));
$request->attributes->set('_controller', [ControllerTest::class, 'publicAction']);
$controller = $resolver->getController($request);
$this->assertInstanceOf(ControllerTest::class, $controller[0]);
$this->assertSame('publicAction', $controller[1]);
@@ -145,12 +145,12 @@ class ControllerResolverTest extends TestCase
public function getStaticControllers()
{
return array(
array(TestAbstractController::class.'::staticAction', 'foo'),
array(array(TestAbstractController::class, 'staticAction'), 'foo'),
array(PrivateConstructorController::class.'::staticAction', 'bar'),
array(array(PrivateConstructorController::class, 'staticAction'), 'bar'),
);
return [
[TestAbstractController::class.'::staticAction', 'foo'],
[[TestAbstractController::class, 'staticAction'], 'foo'],
[PrivateConstructorController::class.'::staticAction', 'bar'],
[[PrivateConstructorController::class, 'staticAction'], 'bar'],
];
}
/**
@@ -175,22 +175,22 @@ class ControllerResolverTest extends TestCase
{
$controller = new ControllerTest();
return array(
array('foo', \Error::class, 'Class \'foo\' not found'),
array('oof::bar', \Error::class, 'Class \'oof\' not found'),
array(array('oof', 'bar'), \Error::class, 'Class \'oof\' not found'),
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::staticsAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "staticsAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest", did you mean "staticAction"?'),
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::privateAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "privateAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::protectedAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::undefinedAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "undefinedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest". Available methods: "publicAction", "staticAction"'),
array('Symfony\Component\HttpKernel\Tests\Controller\ControllerTest', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Controller class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" cannot be called without a method name. You need to implement "__invoke" or use one of the available methods: "publicAction", "staticAction".'),
array(array($controller, 'staticsAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "staticsAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest", did you mean "staticAction"?'),
array(array($controller, 'privateAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "privateAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
array(array($controller, 'protectedAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'),
array(array($controller, 'undefinedAction'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "undefinedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest". Available methods: "publicAction", "staticAction"'),
array($controller, \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Controller class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" cannot be called without a method name. You need to implement "__invoke" or use one of the available methods: "publicAction", "staticAction".'),
array(array('a' => 'foo', 'b' => 'bar'), \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Invalid array callable, expected array(controller, method).'),
);
return [
['foo', \Error::class, 'Class \'foo\' not found'],
['oof::bar', \Error::class, 'Class \'oof\' not found'],
[['oof', 'bar'], \Error::class, 'Class \'oof\' not found'],
['Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::staticsAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "staticsAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest", did you mean "staticAction"?'],
['Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::privateAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "privateAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'],
['Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::protectedAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'],
['Symfony\Component\HttpKernel\Tests\Controller\ControllerTest::undefinedAction', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "undefinedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest". Available methods: "publicAction", "staticAction"'],
['Symfony\Component\HttpKernel\Tests\Controller\ControllerTest', \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Controller class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" cannot be called without a method name. You need to implement "__invoke" or use one of the available methods: "publicAction", "staticAction".'],
[[$controller, 'staticsAction'], \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "staticsAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest", did you mean "staticAction"?'],
[[$controller, 'privateAction'], \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "privateAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'],
[[$controller, 'protectedAction'], \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Method "protectedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" should be public and non-abstract'],
[[$controller, 'undefinedAction'], \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Expected method "undefinedAction" on class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest". Available methods: "publicAction", "staticAction"'],
[$controller, \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Controller class "Symfony\Component\HttpKernel\Tests\Controller\ControllerTest" cannot be called without a method name. You need to implement "__invoke" or use one of the available methods: "publicAction", "staticAction".'],
[['a' => 'foo', 'b' => 'bar'], \InvalidArgumentException::class, 'The controller for URI "/" is not callable. Invalid array callable, expected [controller, method].'],
];
}
protected function createControllerResolver(LoggerInterface $logger = null)

View File

@@ -33,88 +33,88 @@ class ArgumentMetadataFactoryTest extends TestCase
public function testSignature1()
{
$arguments = $this->factory->createArgumentMetadata(array($this, 'signature1'));
$arguments = $this->factory->createArgumentMetadata([$this, 'signature1']);
$this->assertEquals(array(
$this->assertEquals([
new ArgumentMetadata('foo', self::class, false, false, null),
new ArgumentMetadata('bar', 'array', false, false, null),
new ArgumentMetadata('baz', 'callable', false, false, null),
), $arguments);
], $arguments);
}
public function testSignature2()
{
$arguments = $this->factory->createArgumentMetadata(array($this, 'signature2'));
$arguments = $this->factory->createArgumentMetadata([$this, 'signature2']);
$this->assertEquals(array(
$this->assertEquals([
new ArgumentMetadata('foo', self::class, false, true, null, true),
new ArgumentMetadata('bar', __NAMESPACE__.'\FakeClassThatDoesNotExist', false, true, null, true),
new ArgumentMetadata('baz', 'Fake\ImportedAndFake', false, true, null, true),
), $arguments);
], $arguments);
}
public function testSignature3()
{
$arguments = $this->factory->createArgumentMetadata(array($this, 'signature3'));
$arguments = $this->factory->createArgumentMetadata([$this, 'signature3']);
$this->assertEquals(array(
$this->assertEquals([
new ArgumentMetadata('bar', __NAMESPACE__.'\FakeClassThatDoesNotExist', false, false, null),
new ArgumentMetadata('baz', 'Fake\ImportedAndFake', false, false, null),
), $arguments);
], $arguments);
}
public function testSignature4()
{
$arguments = $this->factory->createArgumentMetadata(array($this, 'signature4'));
$arguments = $this->factory->createArgumentMetadata([$this, 'signature4']);
$this->assertEquals(array(
$this->assertEquals([
new ArgumentMetadata('foo', null, false, true, 'default'),
new ArgumentMetadata('bar', null, false, true, 500),
new ArgumentMetadata('baz', null, false, true, array()),
), $arguments);
new ArgumentMetadata('baz', null, false, true, []),
], $arguments);
}
public function testSignature5()
{
$arguments = $this->factory->createArgumentMetadata(array($this, 'signature5'));
$arguments = $this->factory->createArgumentMetadata([$this, 'signature5']);
$this->assertEquals(array(
$this->assertEquals([
new ArgumentMetadata('foo', 'array', false, true, null, true),
new ArgumentMetadata('bar', null, false, false, null),
), $arguments);
], $arguments);
}
public function testVariadicSignature()
{
$arguments = $this->factory->createArgumentMetadata(array(new VariadicController(), 'action'));
$arguments = $this->factory->createArgumentMetadata([new VariadicController(), 'action']);
$this->assertEquals(array(
$this->assertEquals([
new ArgumentMetadata('foo', null, false, false, null),
new ArgumentMetadata('bar', null, true, false, null),
), $arguments);
], $arguments);
}
public function testBasicTypesSignature()
{
$arguments = $this->factory->createArgumentMetadata(array(new BasicTypesController(), 'action'));
$arguments = $this->factory->createArgumentMetadata([new BasicTypesController(), 'action']);
$this->assertEquals(array(
$this->assertEquals([
new ArgumentMetadata('foo', 'string', false, false, null),
new ArgumentMetadata('bar', 'int', false, false, null),
new ArgumentMetadata('baz', 'float', false, false, null),
), $arguments);
], $arguments);
}
public function testNullableTypesSignature()
{
$arguments = $this->factory->createArgumentMetadata(array(new NullableController(), 'action'));
$arguments = $this->factory->createArgumentMetadata([new NullableController(), 'action']);
$this->assertEquals(array(
$this->assertEquals([
new ArgumentMetadata('foo', 'string', false, false, null, true),
new ArgumentMetadata('bar', \stdClass::class, false, false, null, true),
new ArgumentMetadata('baz', 'string', false, true, 'value', true),
new ArgumentMetadata('mandatory', null, false, false, null, true),
), $arguments);
], $arguments);
}
private function signature1(self $foo, array $bar, callable $baz)
@@ -129,7 +129,7 @@ class ArgumentMetadataFactoryTest extends TestCase
{
}
private function signature4($foo = 'default', $bar = 500, $baz = array())
private function signature4($foo = 'default', $bar = 500, $baz = [])
{
}

View File

@@ -67,7 +67,7 @@ class KernelForTest extends Kernel
public function getBundles()
{
return array();
return [];
}
public function registerContainerConfiguration(LoaderInterface $loader)

View File

@@ -30,7 +30,7 @@ class DataCollectorTest extends TestCase
public function testCloneVarExistingFilePath()
{
$c = new CloneVarDataCollector(array($filePath = tempnam(sys_get_temp_dir(), 'clone_var_data_collector_')));
$c = new CloneVarDataCollector([$filePath = tempnam(sys_get_temp_dir(), 'clone_var_data_collector_')]);
$c->collect(new Request(), new Response());
$this->assertSame($filePath, $c->getData()[0]);

View File

@@ -26,7 +26,7 @@ class DumpDataCollectorTest extends TestCase
{
public function testDump()
{
$data = new Data(array(array(123)));
$data = new Data([[123]]);
$collector = new DumpDataCollector();
@@ -41,15 +41,15 @@ class DumpDataCollectorTest extends TestCase
$dump[0]['data'] = preg_replace('/^.*?<pre/', '<pre', $dump[0]['data']);
$dump[0]['data'] = preg_replace('/sf-dump-\d+/', 'sf-dump', $dump[0]['data']);
$xDump = array(
array(
$xDump = [
[
'data' => "<pre class=sf-dump id=sf-dump data-indent-pad=\" \"><span class=sf-dump-num>123</span>\n</pre><script>Sfdump(\"sf-dump\")</script>\n",
'name' => 'DumpDataCollectorTest.php',
'file' => __FILE__,
'line' => $line,
'fileExcerpt' => false,
),
);
],
];
$this->assertEquals($xDump, $dump);
$this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
@@ -59,7 +59,7 @@ class DumpDataCollectorTest extends TestCase
public function testDumpWithServerConnection()
{
$data = new Data(array(array(123)));
$data = new Data([[123]]);
// Server is up, server dumper is used
$serverDumper = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
@@ -77,7 +77,7 @@ class DumpDataCollectorTest extends TestCase
public function testCollectDefault()
{
$data = new Data(array(array(123)));
$data = new Data([[123]]);
$collector = new DumpDataCollector();
@@ -95,7 +95,7 @@ class DumpDataCollectorTest extends TestCase
public function testCollectHtml()
{
$data = new Data(array(array(123)));
$data = new Data([[123]]);
$collector = new DumpDataCollector(null, 'test://%f:%l');
@@ -123,7 +123,7 @@ EOTXT;
public function testFlush()
{
$data = new Data(array(array(456)));
$data = new Data([[456]]);
$collector = new DumpDataCollector();
$collector->dump($data);
$line = __LINE__ - 1;
@@ -136,7 +136,7 @@ EOTXT;
public function testFlushNothingWhenDataDumperIsProvided()
{
$data = new Data(array(array(456)));
$data = new Data([[456]]);
$dumper = new CliDumper('php://output');
$collector = new DumpDataCollector(null, null, null, null, $dumper);

View File

@@ -25,24 +25,24 @@ class LoggerDataCollectorTest extends TestCase
{
$logger = $this
->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
->setMethods(array('countErrors', 'getLogs', 'clear'))
->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock();
$logger->expects($this->once())->method('countErrors')->will($this->returnValue('foo'));
$logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue(array()));
$logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue([]));
$c = new LoggerDataCollector($logger, __DIR__.'/');
$c->lateCollect();
$compilerLogs = $c->getCompilerLogs()->getValue('message');
$this->assertSame(array(
array('message' => 'Removed service "Psr\Container\ContainerInterface"; reason: private alias.'),
array('message' => 'Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias.'),
), $compilerLogs['Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass']);
$this->assertSame([
['message' => 'Removed service "Psr\Container\ContainerInterface"; reason: private alias.'],
['message' => 'Removed service "Symfony\Component\DependencyInjection\ContainerInterface"; reason: private alias.'],
], $compilerLogs['Symfony\Component\DependencyInjection\Compiler\RemovePrivateAliasesPass']);
$this->assertSame(array(
array('message' => 'Some custom logging message'),
array('message' => 'With ending :'),
), $compilerLogs['Unknown Compiler Pass']);
$this->assertSame([
['message' => 'Some custom logging message'],
['message' => 'With ending :'],
], $compilerLogs['Unknown Compiler Pass']);
}
public function testWithMasterRequest()
@@ -53,10 +53,10 @@ class LoggerDataCollectorTest extends TestCase
$logger = $this
->getMockBuilder(DebugLoggerInterface::class)
->setMethods(array('countErrors', 'getLogs', 'clear'))
->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock();
$logger->expects($this->once())->method('countErrors')->with(null);
$logger->expects($this->exactly(2))->method('getLogs')->with(null)->will($this->returnValue(array()));
$logger->expects($this->exactly(2))->method('getLogs')->with(null)->will($this->returnValue([]));
$c = new LoggerDataCollector($logger, __DIR__.'/', $stack);
@@ -74,10 +74,10 @@ class LoggerDataCollectorTest extends TestCase
$logger = $this
->getMockBuilder(DebugLoggerInterface::class)
->setMethods(array('countErrors', 'getLogs', 'clear'))
->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock();
$logger->expects($this->once())->method('countErrors')->with($subRequest);
$logger->expects($this->exactly(2))->method('getLogs')->with($subRequest)->will($this->returnValue(array()));
$logger->expects($this->exactly(2))->method('getLogs')->with($subRequest)->will($this->returnValue([]));
$c = new LoggerDataCollector($logger, __DIR__.'/', $stack);
@@ -92,7 +92,7 @@ class LoggerDataCollectorTest extends TestCase
{
$logger = $this
->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
->setMethods(array('countErrors', 'getLogs', 'clear'))
->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock();
$logger->expects($this->once())->method('countErrors')->will($this->returnValue($nb));
$logger->expects($this->exactly(2))->method('getLogs')->will($this->returnValue($logs));
@@ -106,7 +106,7 @@ class LoggerDataCollectorTest extends TestCase
$logs = array_map(function ($v) {
if (isset($v['context']['exception'])) {
$e = &$v['context']['exception'];
$e = isset($e["\0*\0message"]) ? array($e["\0*\0message"], $e["\0*\0severity"]) : array($e["\0Symfony\Component\Debug\Exception\SilencedErrorContext\0severity"]);
$e = isset($e["\0*\0message"]) ? [$e["\0*\0message"], $e["\0*\0severity"]] : [$e["\0Symfony\Component\Debug\Exception\SilencedErrorContext\0severity"]];
}
return $v;
@@ -124,7 +124,7 @@ class LoggerDataCollectorTest extends TestCase
{
$logger = $this
->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface')
->setMethods(array('countErrors', 'getLogs', 'clear'))
->setMethods(['countErrors', 'getLogs', 'clear'])
->getMock();
$logger->expects($this->once())->method('clear');
@@ -134,55 +134,55 @@ class LoggerDataCollectorTest extends TestCase
public function getCollectTestData()
{
yield 'simple log' => array(
yield 'simple log' => [
1,
array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
array(array('message' => 'foo', 'context' => array(), 'priority' => 100, 'priorityName' => 'DEBUG')),
[['message' => 'foo', 'context' => [], 'priority' => 100, 'priorityName' => 'DEBUG']],
[['message' => 'foo', 'context' => [], 'priority' => 100, 'priorityName' => 'DEBUG']],
0,
0,
);
];
yield 'log with a context' => array(
yield 'log with a context' => [
1,
array(array('message' => 'foo', 'context' => array('foo' => 'bar'), 'priority' => 100, 'priorityName' => 'DEBUG')),
array(array('message' => 'foo', 'context' => array('foo' => 'bar'), 'priority' => 100, 'priorityName' => 'DEBUG')),
[['message' => 'foo', 'context' => ['foo' => 'bar'], 'priority' => 100, 'priorityName' => 'DEBUG']],
[['message' => 'foo', 'context' => ['foo' => 'bar'], 'priority' => 100, 'priorityName' => 'DEBUG']],
0,
0,
);
];
if (!class_exists(SilencedErrorContext::class)) {
return;
}
yield 'logs with some deprecations' => array(
yield 'logs with some deprecations' => [
1,
array(
array('message' => 'foo3', 'context' => array('exception' => new \ErrorException('warning', 0, E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG'),
array('message' => 'foo', 'context' => array('exception' => new \ErrorException('deprecated', 0, E_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG'),
array('message' => 'foo2', 'context' => array('exception' => new \ErrorException('deprecated', 0, E_USER_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG'),
),
array(
array('message' => 'foo3', 'context' => array('exception' => array('warning', E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG'),
array('message' => 'foo', 'context' => array('exception' => array('deprecated', E_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false),
array('message' => 'foo2', 'context' => array('exception' => array('deprecated', E_USER_DEPRECATED)), 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false),
),
[
['message' => 'foo3', 'context' => ['exception' => new \ErrorException('warning', 0, E_USER_WARNING)], 'priority' => 100, 'priorityName' => 'DEBUG'],
['message' => 'foo', 'context' => ['exception' => new \ErrorException('deprecated', 0, E_DEPRECATED)], 'priority' => 100, 'priorityName' => 'DEBUG'],
['message' => 'foo2', 'context' => ['exception' => new \ErrorException('deprecated', 0, E_USER_DEPRECATED)], 'priority' => 100, 'priorityName' => 'DEBUG'],
],
[
['message' => 'foo3', 'context' => ['exception' => ['warning', E_USER_WARNING]], 'priority' => 100, 'priorityName' => 'DEBUG'],
['message' => 'foo', 'context' => ['exception' => ['deprecated', E_DEPRECATED]], 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false],
['message' => 'foo2', 'context' => ['exception' => ['deprecated', E_USER_DEPRECATED]], 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => false],
],
2,
0,
array(100 => array('count' => 3, 'name' => 'DEBUG')),
);
[100 => ['count' => 3, 'name' => 'DEBUG']],
];
yield 'logs with some silent errors' => array(
yield 'logs with some silent errors' => [
1,
array(
array('message' => 'foo3', 'context' => array('exception' => new \ErrorException('warning', 0, E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG'),
array('message' => 'foo3', 'context' => array('exception' => new SilencedErrorContext(E_USER_WARNING, __FILE__, __LINE__)), 'priority' => 100, 'priorityName' => 'DEBUG'),
),
array(
array('message' => 'foo3', 'context' => array('exception' => array('warning', E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG'),
array('message' => 'foo3', 'context' => array('exception' => array(E_USER_WARNING)), 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => true),
),
[
['message' => 'foo3', 'context' => ['exception' => new \ErrorException('warning', 0, E_USER_WARNING)], 'priority' => 100, 'priorityName' => 'DEBUG'],
['message' => 'foo3', 'context' => ['exception' => new SilencedErrorContext(E_USER_WARNING, __FILE__, __LINE__)], 'priority' => 100, 'priorityName' => 'DEBUG'],
],
[
['message' => 'foo3', 'context' => ['exception' => ['warning', E_USER_WARNING]], 'priority' => 100, 'priorityName' => 'DEBUG'],
['message' => 'foo3', 'context' => ['exception' => [E_USER_WARNING]], 'priority' => 100, 'priorityName' => 'DEBUG', 'errorCount' => 1, 'scream' => true],
],
0,
1,
);
];
}
}

View File

@@ -39,21 +39,21 @@ class MemoryDataCollectorTest extends TestCase
public function getBytesConversionTestData()
{
return array(
array('2k', 2048),
array('2 k', 2048),
array('8m', 8 * 1024 * 1024),
array('+2 k', 2048),
array('+2???k', 2048),
array('0x10', 16),
array('0xf', 15),
array('010', 8),
array('+0x10 k', 16 * 1024),
array('1g', 1024 * 1024 * 1024),
array('1G', 1024 * 1024 * 1024),
array('-1', -1),
array('0', 0),
array('2mk', 2048), // the unit must be the last char, so in this case 'k', not 'm'
);
return [
['2k', 2048],
['2 k', 2048],
['8m', 8 * 1024 * 1024],
['+2 k', 2048],
['+2???k', 2048],
['0x10', 16],
['0xf', 15],
['010', 8],
['+0x10 k', 16 * 1024],
['1g', 1024 * 1024 * 1024],
['1G', 1024 * 1024 * 1024],
['-1', -1],
['0', 0],
['2mk', 2048], // the unit must be the last char, so in this case 'k', not 'm'
];
}
}

View File

@@ -48,8 +48,8 @@ class RequestDataCollectorTest extends TestCase
$this->assertInstanceOf(ParameterBag::class, $c->getResponseCookies());
$this->assertSame('html', $c->getFormat());
$this->assertEquals('foobar', $c->getRoute());
$this->assertEquals(array('name' => 'foo'), $c->getRouteParams());
$this->assertSame(array(), $c->getSessionAttributes());
$this->assertEquals(['name' => 'foo'], $c->getRouteParams());
$this->assertSame([], $c->getSessionAttributes());
$this->assertSame('en', $c->getLocale());
$this->assertContains(__FILE__, $attributes->get('resource'));
$this->assertSame('stdClass', $attributes->get('object')->getType());
@@ -62,13 +62,13 @@ class RequestDataCollectorTest extends TestCase
public function testCollectWithoutRouteParams()
{
$request = $this->createRequest(array());
$request = $this->createRequest([]);
$c = new RequestDataCollector();
$c->collect($request, $this->createResponse());
$c->lateCollect();
$this->assertEquals(array(), $c->getRouteParams());
$this->assertEquals([], $c->getRouteParams());
}
/**
@@ -94,95 +94,95 @@ class RequestDataCollectorTest extends TestCase
$r3 = new \ReflectionClass($this);
// test name, callable, expected
return array(
array(
return [
[
'"Regular" callable',
array($this, 'testControllerInspection'),
array(
[$this, 'testControllerInspection'],
[
'class' => __NAMESPACE__.'\RequestDataCollectorTest',
'method' => 'testControllerInspection',
'file' => __FILE__,
'line' => $r1->getStartLine(),
),
),
],
],
array(
[
'Closure',
function () { return 'foo'; },
array(
[
'class' => __NAMESPACE__.'\{closure}',
'method' => null,
'file' => __FILE__,
'line' => __LINE__ - 5,
),
),
],
],
array(
[
'Static callback as string',
__NAMESPACE__.'\RequestDataCollectorTest::staticControllerMethod',
array(
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => 'staticControllerMethod',
'file' => __FILE__,
'line' => $r2->getStartLine(),
),
),
],
],
array(
[
'Static callable with instance',
array($this, 'staticControllerMethod'),
array(
[$this, 'staticControllerMethod'],
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => 'staticControllerMethod',
'file' => __FILE__,
'line' => $r2->getStartLine(),
),
),
],
],
array(
[
'Static callable with class name',
array('Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'staticControllerMethod'),
array(
['Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'staticControllerMethod'],
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => 'staticControllerMethod',
'file' => __FILE__,
'line' => $r2->getStartLine(),
),
),
],
],
array(
[
'Callable with instance depending on __call()',
array($this, 'magicMethod'),
array(
[$this, 'magicMethod'],
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => 'magicMethod',
'file' => 'n/a',
'line' => 'n/a',
),
),
],
],
array(
[
'Callable with class name depending on __callStatic()',
array('Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'magicMethod'),
array(
['Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'magicMethod'],
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => 'magicMethod',
'file' => 'n/a',
'line' => 'n/a',
),
),
],
],
array(
[
'Invokable controller',
$this,
array(
[
'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest',
'method' => null,
'file' => __FILE__,
'line' => $r3->getStartLine(),
),
),
);
],
],
];
}
public function testItIgnoresInvalidCallables()
@@ -199,9 +199,9 @@ class RequestDataCollectorTest extends TestCase
public function testItAddsRedirectedAttributesWhenRequestContainsSpecificCookie()
{
$request = $this->createRequest();
$request->cookies->add(array(
$request->cookies->add([
'sf_redirect' => '{}',
));
]);
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
@@ -235,9 +235,9 @@ class RequestDataCollectorTest extends TestCase
$request = $this->createRequest();
$request->attributes->set('_redirected', true);
$request->cookies->add(array(
$request->cookies->add([
'sf_redirect' => '{"method": "POST"}',
));
]);
$c->collect($request, $response = $this->createResponse());
$c->lateCollect();
@@ -248,7 +248,7 @@ class RequestDataCollectorTest extends TestCase
$this->assertNull($cookie->getValue());
}
protected function createRequest($routeParams = array('name' => 'foo'))
protected function createRequest($routeParams = ['name' => 'foo'])
{
$request = Request::create('http://test.com/foo?bar=baz');
$request->attributes->set('foo', 'bar');

View File

@@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector;
use Symfony\Component\Stopwatch\Stopwatch;
/**
* @group time-sensitive
@@ -51,5 +52,6 @@ class TimeDataCollectorTest extends TestCase
$c->collect($request, new Response());
$this->assertEquals(123456000, $c->getStartTime());
$this->assertSame(\class_exists(Stopwatch::class, false), $c->isStopwatchInstalled());
}
}

View File

@@ -31,7 +31,7 @@ class TraceableEventDispatcherTest extends TestCase
$kernel->terminate($request, $response);
$events = $stopwatch->getSectionEvents($response->headers->get('X-Debug-Token'));
$this->assertEquals(array(
$this->assertEquals([
'__section__',
'kernel.request',
'kernel.controller',
@@ -39,13 +39,13 @@ class TraceableEventDispatcherTest extends TestCase
'controller',
'kernel.response',
'kernel.terminate',
), array_keys($events));
], array_keys($events));
}
public function testStopwatchCheckControllerOnRequestEvent()
{
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')
->setMethods(array('isStarted'))
->setMethods(['isStarted'])
->getMock();
$stopwatch->expects($this->once())
->method('isStarted')
@@ -61,7 +61,7 @@ class TraceableEventDispatcherTest extends TestCase
public function testStopwatchStopControllerOnRequestEvent()
{
$stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch')
->setMethods(array('isStarted', 'stop', 'stopSection'))
->setMethods(['isStarted', 'stop', 'stopSection'])
->getMock();
$stopwatch->expects($this->once())
->method('isStarted')
@@ -114,7 +114,7 @@ class TraceableEventDispatcherTest extends TestCase
$controllerResolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock();
$controllerResolver->expects($this->once())->method('getController')->will($this->returnValue($controller));
$argumentResolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface')->getMock();
$argumentResolver->expects($this->once())->method('getArguments')->will($this->returnValue(array()));
$argumentResolver->expects($this->once())->method('getArguments')->will($this->returnValue([]));
return new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver);
}

View File

@@ -24,76 +24,76 @@ class AddAnnotatedClassesToCachePassTest extends TestCase
$r->setAccessible(true);
$expand = $r->getClosure($pass);
$this->assertSame('Foo', $expand(array('Foo'), array())[0]);
$this->assertSame('Foo', $expand(array('\\Foo'), array())[0]);
$this->assertSame('Foo', $expand(array('Foo'), array('\\Foo'))[0]);
$this->assertSame('Foo', $expand(array('Foo'), array('Foo'))[0]);
$this->assertSame('Foo', $expand(array('\\Foo'), array('\\Foo\\Bar'))[0]);
$this->assertSame('Foo', $expand(array('Foo'), array('\\Foo\\Bar'))[0]);
$this->assertSame('Foo', $expand(array('\\Foo'), array('\\Foo\\Bar\\Acme'))[0]);
$this->assertSame('Foo', $expand(['Foo'], [])[0]);
$this->assertSame('Foo', $expand(['\\Foo'], [])[0]);
$this->assertSame('Foo', $expand(['Foo'], ['\\Foo'])[0]);
$this->assertSame('Foo', $expand(['Foo'], ['Foo'])[0]);
$this->assertSame('Foo', $expand(['\\Foo'], ['\\Foo\\Bar'])[0]);
$this->assertSame('Foo', $expand(['Foo'], ['\\Foo\\Bar'])[0]);
$this->assertSame('Foo', $expand(['\\Foo'], ['\\Foo\\Bar\\Acme'])[0]);
$this->assertSame('Foo\\Bar', $expand(array('Foo\\'), array('\\Foo\\Bar'))[0]);
$this->assertSame('Foo\\Bar\\Acme', $expand(array('Foo\\'), array('\\Foo\\Bar\\Acme'))[0]);
$this->assertEmpty($expand(array('Foo\\'), array('\\Foo')));
$this->assertSame('Foo\\Bar', $expand(['Foo\\'], ['\\Foo\\Bar'])[0]);
$this->assertSame('Foo\\Bar\\Acme', $expand(['Foo\\'], ['\\Foo\\Bar\\Acme'])[0]);
$this->assertEmpty($expand(['Foo\\'], ['\\Foo']));
$this->assertSame('Acme\\Foo\\Bar', $expand(array('**\\Foo\\'), array('\\Acme\\Foo\\Bar'))[0]);
$this->assertEmpty($expand(array('**\\Foo\\'), array('\\Foo\\Bar')));
$this->assertEmpty($expand(array('**\\Foo\\'), array('\\Acme\\Foo')));
$this->assertEmpty($expand(array('**\\Foo\\'), array('\\Foo')));
$this->assertSame('Acme\\Foo\\Bar', $expand(['**\\Foo\\'], ['\\Acme\\Foo\\Bar'])[0]);
$this->assertEmpty($expand(['**\\Foo\\'], ['\\Foo\\Bar']));
$this->assertEmpty($expand(['**\\Foo\\'], ['\\Acme\\Foo']));
$this->assertEmpty($expand(['**\\Foo\\'], ['\\Foo']));
$this->assertSame('Acme\\Foo', $expand(array('**\\Foo'), array('\\Acme\\Foo'))[0]);
$this->assertEmpty($expand(array('**\\Foo'), array('\\Acme\\Foo\\AcmeBundle')));
$this->assertEmpty($expand(array('**\\Foo'), array('\\Acme\\FooBar\\AcmeBundle')));
$this->assertSame('Acme\\Foo', $expand(['**\\Foo'], ['\\Acme\\Foo'])[0]);
$this->assertEmpty($expand(['**\\Foo'], ['\\Acme\\Foo\\AcmeBundle']));
$this->assertEmpty($expand(['**\\Foo'], ['\\Acme\\FooBar\\AcmeBundle']));
$this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\*\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
$this->assertEmpty($expand(array('Foo\\*\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar')));
$this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\*\\Bar'], ['\\Foo\\Acme\\Bar'])[0]);
$this->assertEmpty($expand(['Foo\\*\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar']));
$this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
$this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(array('Foo\\**\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar'))[0]);
$this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**\\Bar'], ['\\Foo\\Acme\\Bar'])[0]);
$this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(['Foo\\**\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar'])[0]);
$this->assertSame('Acme\\Bar', $expand(array('*\\Bar'), array('\\Acme\\Bar'))[0]);
$this->assertEmpty($expand(array('*\\Bar'), array('\\Bar')));
$this->assertEmpty($expand(array('*\\Bar'), array('\\Foo\\Acme\\Bar')));
$this->assertSame('Acme\\Bar', $expand(['*\\Bar'], ['\\Acme\\Bar'])[0]);
$this->assertEmpty($expand(['*\\Bar'], ['\\Bar']));
$this->assertEmpty($expand(['*\\Bar'], ['\\Foo\\Acme\\Bar']));
$this->assertSame('Foo\\Acme\\Bar', $expand(array('**\\Bar'), array('\\Foo\\Acme\\Bar'))[0]);
$this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(array('**\\Bar'), array('\\Foo\\Acme\\Bundle\\Bar'))[0]);
$this->assertEmpty($expand(array('**\\Bar'), array('\\Bar')));
$this->assertSame('Foo\\Acme\\Bar', $expand(['**\\Bar'], ['\\Foo\\Acme\\Bar'])[0]);
$this->assertSame('Foo\\Acme\\Bundle\\Bar', $expand(['**\\Bar'], ['\\Foo\\Acme\\Bundle\\Bar'])[0]);
$this->assertEmpty($expand(['**\\Bar'], ['\\Bar']));
$this->assertSame('Foo\\Bar', $expand(array('Foo\\*'), array('\\Foo\\Bar'))[0]);
$this->assertEmpty($expand(array('Foo\\*'), array('\\Foo\\Acme\\Bar')));
$this->assertSame('Foo\\Bar', $expand(['Foo\\*'], ['\\Foo\\Bar'])[0]);
$this->assertEmpty($expand(['Foo\\*'], ['\\Foo\\Acme\\Bar']));
$this->assertSame('Foo\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Bar'))[0]);
$this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Acme\\Bar'))[0]);
$this->assertSame('Foo\\Bar', $expand(['Foo\\**'], ['\\Foo\\Bar'])[0]);
$this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**'], ['\\Foo\\Acme\\Bar'])[0]);
$this->assertSame(array('Foo\\Bar'), $expand(array('Foo\\*'), array('Foo\\Bar', 'Foo\\BarTest')));
$this->assertSame(array('Foo\\Bar', 'Foo\\BarTest'), $expand(array('Foo\\*', 'Foo\\*Test'), array('Foo\\Bar', 'Foo\\BarTest')));
$this->assertSame(['Foo\\Bar'], $expand(['Foo\\*'], ['Foo\\Bar', 'Foo\\BarTest']));
$this->assertSame(['Foo\\Bar', 'Foo\\BarTest'], $expand(['Foo\\*', 'Foo\\*Test'], ['Foo\\Bar', 'Foo\\BarTest']));
$this->assertSame(
'Acme\\FooBundle\\Controller\\DefaultController',
$expand(array('**Bundle\\Controller\\'), array('\\Acme\\FooBundle\\Controller\\DefaultController'))[0]
$expand(['**Bundle\\Controller\\'], ['\\Acme\\FooBundle\\Controller\\DefaultController'])[0]
);
$this->assertSame(
'FooBundle\\Controller\\DefaultController',
$expand(array('**Bundle\\Controller\\'), array('\\FooBundle\\Controller\\DefaultController'))[0]
$expand(['**Bundle\\Controller\\'], ['\\FooBundle\\Controller\\DefaultController'])[0]
);
$this->assertSame(
'Acme\\FooBundle\\Controller\\Bar\\DefaultController',
$expand(array('**Bundle\\Controller\\'), array('\\Acme\\FooBundle\\Controller\\Bar\\DefaultController'))[0]
$expand(['**Bundle\\Controller\\'], ['\\Acme\\FooBundle\\Controller\\Bar\\DefaultController'])[0]
);
$this->assertSame(
'Bundle\\Controller\\Bar\\DefaultController',
$expand(array('**Bundle\\Controller\\'), array('\\Bundle\\Controller\\Bar\\DefaultController'))[0]
$expand(['**Bundle\\Controller\\'], ['\\Bundle\\Controller\\Bar\\DefaultController'])[0]
);
$this->assertSame(
'Acme\\Bundle\\Controller\\Bar\\DefaultController',
$expand(array('**Bundle\\Controller\\'), array('\\Acme\\Bundle\\Controller\\Bar\\DefaultController'))[0]
$expand(['**Bundle\\Controller\\'], ['\\Acme\\Bundle\\Controller\\Bar\\DefaultController'])[0]
);
$this->assertSame('Foo\\Bar', $expand(array('Foo\\Bar'), array())[0]);
$this->assertSame('Foo\\Acme\\Bar', $expand(array('Foo\\**'), array('\\Foo\\Acme\\Bar'))[0]);
$this->assertSame('Foo\\Bar', $expand(['Foo\\Bar'], [])[0]);
$this->assertSame('Foo\\Acme\\Bar', $expand(['Foo\\**'], ['\\Foo\\Acme\\Bar'])[0]);
}
}

View File

@@ -23,19 +23,19 @@ class ControllerArgumentValueResolverPassTest extends TestCase
{
public function testServicesAreOrderedAccordingToPriority()
{
$services = array(
'n3' => array(array()),
'n1' => array(array('priority' => 200)),
'n2' => array(array('priority' => 100)),
);
$services = [
'n3' => [[]],
'n1' => [['priority' => 200]],
'n2' => [['priority' => 100]],
];
$expected = array(
$expected = [
new Reference('n1'),
new Reference('n2'),
new Reference('n3'),
);
];
$definition = new Definition(ArgumentResolver::class, array(null, array()));
$definition = new Definition(ArgumentResolver::class, [null, []]);
$container = new ContainerBuilder();
$container->setDefinition('argument_resolver', $definition);
@@ -55,19 +55,19 @@ class ControllerArgumentValueResolverPassTest extends TestCase
public function testInDebugWithStopWatchDefinition()
{
$services = array(
'n3' => array(array()),
'n1' => array(array('priority' => 200)),
'n2' => array(array('priority' => 100)),
);
$services = [
'n3' => [[]],
'n1' => [['priority' => 200]],
'n2' => [['priority' => 100]],
];
$expected = array(
$expected = [
new Reference('n1'),
new Reference('n2'),
new Reference('n3'),
);
];
$definition = new Definition(ArgumentResolver::class, array(null, array()));
$definition = new Definition(ArgumentResolver::class, [null, []]);
$container = new ContainerBuilder();
$container->register('debug.stopwatch', Stopwatch::class);
$container->setDefinition('argument_resolver', $definition);
@@ -92,9 +92,9 @@ class ControllerArgumentValueResolverPassTest extends TestCase
public function testInDebugWithouStopWatchDefinition()
{
$expected = array(new Reference('n1'));
$expected = [new Reference('n1')];
$definition = new Definition(ArgumentResolver::class, array(null, array()));
$definition = new Definition(ArgumentResolver::class, [null, []]);
$container = new ContainerBuilder();
$container->register('n1')->addTag('controller.argument_value_resolver');
$container->setDefinition('argument_resolver', $definition);
@@ -110,14 +110,14 @@ class ControllerArgumentValueResolverPassTest extends TestCase
public function testReturningEmptyArrayWhenNoService()
{
$definition = new Definition(ArgumentResolver::class, array(null, array()));
$definition = new Definition(ArgumentResolver::class, [null, []]);
$container = new ContainerBuilder();
$container->setDefinition('argument_resolver', $definition);
$container->setParameter('kernel.debug', false);
(new ControllerArgumentValueResolverPass())->process($container);
$this->assertEquals(array(), $definition->getArgument(1)->getValues());
$this->assertEquals([], $definition->getArgument(1)->getValues());
}
public function testNoArgumentResolver()

View File

@@ -33,12 +33,12 @@ class FragmentRendererPassTest extends TestCase
$builder = new ContainerBuilder();
$fragmentHandlerDefinition = $builder->register('fragment.handler');
$builder->register('my_content_renderer', 'Symfony\Component\DependencyInjection\Definition')
->addTag('kernel.fragment_renderer', array('alias' => 'foo'));
->addTag('kernel.fragment_renderer', ['alias' => 'foo']);
$pass = new FragmentRendererPass();
$pass->process($builder);
$this->assertEquals(array(array('addRendererService', array('foo', 'my_content_renderer'))), $fragmentHandlerDefinition->getMethodCalls());
$this->assertEquals([['addRendererService', ['foo', 'my_content_renderer']]], $fragmentHandlerDefinition->getMethodCalls());
}
public function testValidContentRenderer()
@@ -47,20 +47,20 @@ class FragmentRendererPassTest extends TestCase
$fragmentHandlerDefinition = $builder->register('fragment.handler')
->addArgument(null);
$builder->register('my_content_renderer', 'Symfony\Component\HttpKernel\Tests\DependencyInjection\RendererService')
->addTag('kernel.fragment_renderer', array('alias' => 'foo'));
->addTag('kernel.fragment_renderer', ['alias' => 'foo']);
$pass = new FragmentRendererPass();
$pass->process($builder);
$serviceLocatorDefinition = $builder->getDefinition((string) $fragmentHandlerDefinition->getArgument(0));
$this->assertSame(ServiceLocator::class, $serviceLocatorDefinition->getClass());
$this->assertEquals(array('foo' => new ServiceClosureArgument(new Reference('my_content_renderer'))), $serviceLocatorDefinition->getArgument(0));
$this->assertEquals(['foo' => new ServiceClosureArgument(new Reference('my_content_renderer'))], $serviceLocatorDefinition->getArgument(0));
}
}
class RendererService implements FragmentRendererInterface
{
public function render($uri, Request $request = null, array $options = array())
public function render($uri, Request $request = null, array $options = [])
{
}

View File

@@ -23,9 +23,9 @@ class MergeExtensionConfigurationPassTest extends TestCase
$container = new ContainerBuilder();
$container->registerExtension(new LoadedExtension());
$container->registerExtension(new NotLoadedExtension());
$container->loadFromExtension('loaded', array());
$container->loadFromExtension('loaded', []);
$configPass = new MergeExtensionConfigurationPass(array('loaded', 'not_loaded'));
$configPass = new MergeExtensionConfigurationPass(['loaded', 'not_loaded']);
$configPass->process($container);
$this->assertTrue($container->hasDefinition('loaded.foo'));

View File

@@ -32,7 +32,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testInvalidClass()
{
$container = new ContainerBuilder();
$container->register('argument_resolver.service')->addArgument(array());
$container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', NotFound::class)
->addTag('controller.service_arguments')
@@ -49,10 +49,10 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testNoAction()
{
$container = new ContainerBuilder();
$container->register('argument_resolver.service')->addArgument(array());
$container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', RegisterTestController::class)
->addTag('controller.service_arguments', array('argument' => 'bar'))
->addTag('controller.service_arguments', ['argument' => 'bar'])
;
$pass = new RegisterControllerArgumentLocatorsPass();
@@ -66,10 +66,10 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testNoArgument()
{
$container = new ContainerBuilder();
$container->register('argument_resolver.service')->addArgument(array());
$container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', RegisterTestController::class)
->addTag('controller.service_arguments', array('action' => 'fooAction'))
->addTag('controller.service_arguments', ['action' => 'fooAction'])
;
$pass = new RegisterControllerArgumentLocatorsPass();
@@ -83,10 +83,10 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testNoService()
{
$container = new ContainerBuilder();
$container->register('argument_resolver.service')->addArgument(array());
$container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', RegisterTestController::class)
->addTag('controller.service_arguments', array('action' => 'fooAction', 'argument' => 'bar'))
->addTag('controller.service_arguments', ['action' => 'fooAction', 'argument' => 'bar'])
;
$pass = new RegisterControllerArgumentLocatorsPass();
@@ -100,10 +100,10 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testInvalidMethod()
{
$container = new ContainerBuilder();
$container->register('argument_resolver.service')->addArgument(array());
$container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', RegisterTestController::class)
->addTag('controller.service_arguments', array('action' => 'barAction', 'argument' => 'bar', 'id' => 'bar_service'))
->addTag('controller.service_arguments', ['action' => 'barAction', 'argument' => 'bar', 'id' => 'bar_service'])
;
$pass = new RegisterControllerArgumentLocatorsPass();
@@ -117,10 +117,10 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testInvalidArgument()
{
$container = new ContainerBuilder();
$container->register('argument_resolver.service')->addArgument(array());
$container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', RegisterTestController::class)
->addTag('controller.service_arguments', array('action' => 'fooAction', 'argument' => 'baz', 'id' => 'bar'))
->addTag('controller.service_arguments', ['action' => 'fooAction', 'argument' => 'baz', 'id' => 'bar'])
;
$pass = new RegisterControllerArgumentLocatorsPass();
@@ -130,7 +130,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testAllActions()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', RegisterTestController::class)
->addTag('controller.service_arguments')
@@ -141,7 +141,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$this->assertEquals(array('foo::fooAction'), array_keys($locator));
$this->assertEquals(['foo::fooAction'], array_keys($locator));
$this->assertInstanceof(ServiceClosureArgument::class, $locator['foo::fooAction']);
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
@@ -149,18 +149,18 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$this->assertSame(ServiceLocator::class, $locator->getClass());
$this->assertFalse($locator->isPublic());
$expected = array('bar' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE, 'bar')));
$expected = ['bar' => new ServiceClosureArgument(new TypedReference(ControllerDummy::class, ControllerDummy::class, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE, 'bar'))];
$this->assertEquals($expected, $locator->getArgument(0));
}
public function testExplicitArgument()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', RegisterTestController::class)
->addTag('controller.service_arguments', array('action' => 'fooAction', 'argument' => 'bar', 'id' => 'bar'))
->addTag('controller.service_arguments', array('action' => 'fooAction', 'argument' => 'bar', 'id' => 'baz')) // should be ignored, the first wins
->addTag('controller.service_arguments', ['action' => 'fooAction', 'argument' => 'bar', 'id' => 'bar'])
->addTag('controller.service_arguments', ['action' => 'fooAction', 'argument' => 'bar', 'id' => 'baz']) // should be ignored, the first wins
;
$pass = new RegisterControllerArgumentLocatorsPass();
@@ -169,17 +169,17 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE)));
$expected = ['bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE))];
$this->assertEquals($expected, $locator->getArgument(0));
}
public function testOptionalArgument()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', RegisterTestController::class)
->addTag('controller.service_arguments', array('action' => 'fooAction', 'argument' => 'bar', 'id' => '?bar'))
->addTag('controller.service_arguments', ['action' => 'fooAction', 'argument' => 'bar', 'id' => '?bar'])
;
$pass = new RegisterControllerArgumentLocatorsPass();
@@ -188,14 +188,14 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
$expected = array('bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)));
$expected = ['bar' => new ServiceClosureArgument(new TypedReference('bar', ControllerDummy::class, ContainerInterface::IGNORE_ON_INVALID_REFERENCE))];
$this->assertEquals($expected, $locator->getArgument(0));
}
public function testSkipSetContainer()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', ContainerAwareRegisterTestController::class)
->addTag('controller.service_arguments');
@@ -204,7 +204,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$pass->process($container);
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$this->assertSame(array('foo::fooAction'), array_keys($locator));
$this->assertSame(['foo::fooAction'], array_keys($locator));
}
/**
@@ -214,7 +214,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testExceptionOnNonExistentTypeHint()
{
$container = new ContainerBuilder();
$container->register('argument_resolver.service')->addArgument(array());
$container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', NonExistentClassController::class)
->addTag('controller.service_arguments');
@@ -230,7 +230,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testExceptionOnNonExistentTypeHintDifferentNamespace()
{
$container = new ContainerBuilder();
$container->register('argument_resolver.service')->addArgument(array());
$container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', NonExistentClassDifferentNamespaceController::class)
->addTag('controller.service_arguments');
@@ -242,7 +242,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testNoExceptionOnNonExistentTypeHintOptionalArg()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', NonExistentClassOptionalController::class)
->addTag('controller.service_arguments');
@@ -251,13 +251,13 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$pass->process($container);
$locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$this->assertSame(array('foo::barAction', 'foo::fooAction'), array_keys($locator));
$this->assertSame(['foo::barAction', 'foo::fooAction'], array_keys($locator));
}
public function testArgumentWithNoTypeHintIsOk()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', ArgumentWithoutTypeController::class)
->addTag('controller.service_arguments');
@@ -272,7 +272,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testControllersAreMadePublic()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', ArgumentWithoutTypeController::class)
->setPublic(false)
@@ -290,10 +290,10 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testBindings($bindingName)
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', RegisterTestController::class)
->setBindings(array($bindingName => new Reference('foo')))
->setBindings([$bindingName => new Reference('foo')])
->addTag('controller.service_arguments');
$pass = new RegisterControllerArgumentLocatorsPass();
@@ -303,17 +303,17 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]);
$expected = array('bar' => new ServiceClosureArgument(new Reference('foo')));
$expected = ['bar' => new ServiceClosureArgument(new Reference('foo'))];
$this->assertEquals($expected, $locator->getArgument(0));
}
public function provideBindings()
{
return array(
array(ControllerDummy::class.'$bar'),
array(ControllerDummy::class),
array('$bar'),
);
return [
[ControllerDummy::class.'$bar'],
[ControllerDummy::class],
['$bar'],
];
}
/**
@@ -322,10 +322,10 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function testBindScalarValueToControllerArgument($bindingKey)
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('foo', ArgumentWithoutTypeController::class)
->setBindings(array($bindingKey => '%foo%'))
->setBindings([$bindingKey => '%foo%'])
->addTag('controller.service_arguments');
$container->setParameter('foo', 'foo_val');
@@ -350,19 +350,19 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
public function provideBindScalarValueToControllerArgument()
{
yield array('$someArg');
yield array('string $someArg');
yield ['$someArg'];
yield ['string $someArg'];
}
public function testBindingsOnChildDefinitions()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('parent', ArgumentWithoutTypeController::class);
$container->setDefinition('child', (new ChildDefinition('parent'))
->setBindings(array('$someArg' => new Reference('parent')))
->setBindings(['$someArg' => new Reference('parent')])
->addTag('controller.service_arguments')
);

View File

@@ -23,13 +23,13 @@ class RemoveEmptyControllerArgumentLocatorsPassTest extends TestCase
public function testProcess()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('stdClass', 'stdClass');
$container->register(parent::class, 'stdClass');
$container->register('c1', RemoveTestController1::class)->addTag('controller.service_arguments');
$container->register('c2', RemoveTestController2::class)->addTag('controller.service_arguments')
->addMethodCall('setTestCase', array(new Reference('c1')));
->addMethodCall('setTestCase', [new Reference('c1')]);
$pass = new RegisterControllerArgumentLocatorsPass();
$pass->process($container);
@@ -43,19 +43,19 @@ class RemoveEmptyControllerArgumentLocatorsPassTest extends TestCase
(new ResolveInvalidReferencesPass())->process($container);
$this->assertCount(1, $container->getDefinition((string) $controllers['c2::setTestCase']->getValues()[0])->getArgument(0));
$this->assertSame(array(), $container->getDefinition((string) $controllers['c2::fooAction']->getValues()[0])->getArgument(0));
$this->assertSame([], $container->getDefinition((string) $controllers['c2::fooAction']->getValues()[0])->getArgument(0));
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
$controllers = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0);
$this->assertSame(array('c1::fooAction', 'c1:fooAction'), array_keys($controllers));
$this->assertSame(array('bar'), array_keys($container->getDefinition((string) $controllers['c1::fooAction']->getValues()[0])->getArgument(0)));
$this->assertSame(['c1::fooAction', 'c1:fooAction'], array_keys($controllers));
$this->assertSame(['bar'], array_keys($container->getDefinition((string) $controllers['c1::fooAction']->getValues()[0])->getArgument(0)));
$expectedLog = array(
$expectedLog = [
'Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass: Removing service-argument resolver for controller "c2::fooAction": no corresponding services exist for the referenced types.',
'Symfony\Component\HttpKernel\DependencyInjection\RemoveEmptyControllerArgumentLocatorsPass: Removing method "setTestCase" of service "c2" from controller candidates: the method is called at instantiation, thus cannot be an action.',
);
];
$this->assertSame($expectedLog, $container->getCompiler()->getLog());
}
@@ -63,7 +63,7 @@ class RemoveEmptyControllerArgumentLocatorsPassTest extends TestCase
public function testInvoke()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.service')->addArgument(array());
$resolver = $container->register('argument_resolver.service')->addArgument([]);
$container->register('invokable', InvokableRegisterTestController::class)
->addTag('controller.service_arguments')
@@ -73,7 +73,7 @@ class RemoveEmptyControllerArgumentLocatorsPassTest extends TestCase
(new RemoveEmptyControllerArgumentLocatorsPass())->process($container);
$this->assertEquals(
array('invokable::__invoke', 'invokable:__invoke', 'invokable'),
['invokable::__invoke', 'invokable:__invoke', 'invokable'],
array_keys($container->getDefinition((string) $resolver->getArgument(0))->getArgument(0))
);
}

View File

@@ -19,14 +19,14 @@ class ResettableServicePassTest extends TestCase
$container = new ContainerBuilder();
$container->register('one', ResettableService::class)
->setPublic(true)
->addTag('kernel.reset', array('method' => 'reset'));
->addTag('kernel.reset', ['method' => 'reset']);
$container->register('two', ClearableService::class)
->setPublic(true)
->addTag('kernel.reset', array('method' => 'clear'));
->addTag('kernel.reset', ['method' => 'clear']);
$container->register('services_resetter', ServicesResetter::class)
->setPublic(true)
->setArguments(array(null, array()));
->setArguments([null, []]);
$container->addCompilerPass(new ResettableServicePass());
$container->compile();
@@ -34,16 +34,16 @@ class ResettableServicePassTest extends TestCase
$definition = $container->getDefinition('services_resetter');
$this->assertEquals(
array(
new IteratorArgument(array(
[
new IteratorArgument([
'one' => new Reference('one', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE),
'two' => new Reference('two', ContainerInterface::IGNORE_ON_UNINITIALIZED_REFERENCE),
)),
array(
]),
[
'one' => 'reset',
'two' => 'clear',
),
),
],
],
$definition->getArguments()
);
}
@@ -58,7 +58,7 @@ class ResettableServicePassTest extends TestCase
$container->register(ResettableService::class)
->addTag('kernel.reset');
$container->register('services_resetter', ServicesResetter::class)
->setArguments(array(null, array()));
->setArguments([null, []]);
$container->addCompilerPass(new ResettableServicePass());
$container->compile();
@@ -68,7 +68,7 @@ class ResettableServicePassTest extends TestCase
{
$container = new ContainerBuilder();
$container->register('services_resetter', ServicesResetter::class)
->setArguments(array(null, array()));
->setArguments([null, []]);
$container->addCompilerPass(new ResettableServicePass());
$container->compile();

View File

@@ -26,13 +26,13 @@ class ServicesResetterTest extends TestCase
public function testResetServices()
{
$resetter = new ServicesResetter(new \ArrayIterator(array(
$resetter = new ServicesResetter(new \ArrayIterator([
'id1' => new ResettableService(),
'id2' => new ClearableService(),
)), array(
]), [
'id1' => 'reset',
'id2' => 'clear',
));
]);
$resetter->reset();

View File

@@ -11,7 +11,7 @@ class FilterControllerArgumentsEventTest extends TestCase
{
public function testFilterControllerArgumentsEvent()
{
$filterController = new FilterControllerArgumentsEvent(new TestHttpKernel(), function () {}, array('test'), new Request(), 1);
$this->assertEquals($filterController->getArguments(), array('test'));
$filterController = new FilterControllerArgumentsEvent(new TestHttpKernel(), function () {}, ['test'], new Request(), 1);
$this->assertEquals($filterController->getArguments(), ['test']);
}
}

View File

@@ -30,7 +30,7 @@ class AddRequestFormatsListenerTest extends TestCase
protected function setUp()
{
$this->listener = new AddRequestFormatsListener(array('csv' => array('text/csv', 'text/plain')));
$this->listener = new AddRequestFormatsListener(['csv' => ['text/csv', 'text/plain']]);
}
protected function tearDown()
@@ -46,7 +46,7 @@ class AddRequestFormatsListenerTest extends TestCase
public function testRegisteredEvent()
{
$this->assertEquals(
array(KernelEvents::REQUEST => array('onKernelRequest', 1)),
[KernelEvents::REQUEST => ['onKernelRequest', 1]],
AddRequestFormatsListener::getSubscribedEvents()
);
}
@@ -58,7 +58,7 @@ class AddRequestFormatsListenerTest extends TestCase
$request->expects($this->once())
->method('setFormat')
->with('csv', array('text/csv', 'text/plain'));
->with('csv', ['text/csv', 'text/plain']);
$this->listener->onKernelRequest($event);
}

View File

@@ -40,11 +40,11 @@ class DebugHandlersListenerTest extends TestCase
$listener = new DebugHandlersListener($userHandler, $logger);
$xHandler = new ExceptionHandler();
$eHandler = new ErrorHandler();
$eHandler->setExceptionHandler(array($xHandler, 'handle'));
$eHandler->setExceptionHandler([$xHandler, 'handle']);
$exception = null;
set_error_handler(array($eHandler, 'handleError'));
set_exception_handler(array($eHandler, 'handleException'));
set_error_handler([$eHandler, 'handleError']);
set_exception_handler([$eHandler, 'handleException']);
try {
$listener->configure();
} catch (\Exception $exception) {
@@ -58,10 +58,10 @@ class DebugHandlersListenerTest extends TestCase
$this->assertSame($userHandler, $xHandler->setHandler('var_dump'));
$loggers = $eHandler->setLoggers(array());
$loggers = $eHandler->setLoggers([]);
$this->assertArrayHasKey(E_DEPRECATED, $loggers);
$this->assertSame(array($logger, LogLevel::INFO), $loggers[E_DEPRECATED]);
$this->assertSame([$logger, LogLevel::INFO], $loggers[E_DEPRECATED]);
}
public function testConfigureForHttpKernelWithNoTerminateWithException()
@@ -75,7 +75,7 @@ class DebugHandlersListenerTest extends TestCase
);
$exception = null;
$h = set_exception_handler(array($eHandler, 'handleException'));
$h = set_exception_handler([$eHandler, 'handleException']);
try {
$listener->configure($event);
} catch (\Exception $exception) {
@@ -101,16 +101,16 @@ class DebugHandlersListenerTest extends TestCase
$dispatcher->addSubscriber($listener);
$xListeners = array(
KernelEvents::REQUEST => array(array($listener, 'configure')),
ConsoleEvents::COMMAND => array(array($listener, 'configure')),
);
$xListeners = [
KernelEvents::REQUEST => [[$listener, 'configure']],
ConsoleEvents::COMMAND => [[$listener, 'configure']],
];
$this->assertSame($xListeners, $dispatcher->getListeners());
$exception = null;
$eHandler = new ErrorHandler();
set_error_handler(array($eHandler, 'handleError'));
set_exception_handler(array($eHandler, 'handleException'));
set_error_handler([$eHandler, 'handleError']);
set_exception_handler([$eHandler, 'handleException']);
try {
$dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
} catch (\Exception $exception) {
@@ -139,7 +139,7 @@ class DebugHandlersListenerTest extends TestCase
$eHandler->setExceptionHandler('var_dump');
$exception = null;
set_exception_handler(array($eHandler, 'handleException'));
set_exception_handler([$eHandler, 'handleException']);
try {
$listener->configure();
} catch (\Exception $exception) {

View File

@@ -29,7 +29,7 @@ class DumpListenerTest extends TestCase
public function testSubscribedEvents()
{
$this->assertSame(
array(ConsoleEvents::COMMAND => array('configure', 1024)),
[ConsoleEvents::COMMAND => ['configure', 1024]],
DumpListener::getSubscribedEvents()
);
}
@@ -68,7 +68,7 @@ class MockCloner implements ClonerInterface
{
public function cloneVar($var)
{
return new Data(array(array($var.'-')));
return new Data([[$var.'-']]);
}
}

View File

@@ -98,7 +98,7 @@ class ExceptionListenerTest extends TestCase
public function provider()
{
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
return array(array(null, null));
return [[null, null]];
}
$request = new Request();
@@ -106,9 +106,9 @@ class ExceptionListenerTest extends TestCase
$event = new GetResponseForExceptionEvent(new TestKernel(), $request, HttpKernelInterface::MASTER_REQUEST, $exception);
$event2 = new GetResponseForExceptionEvent(new TestKernelThatThrowsException(), $request, HttpKernelInterface::MASTER_REQUEST, $exception);
return array(
array($event, $event2),
);
return [
[$event, $event2],
];
}
public function testSubRequestFormat()
@@ -146,7 +146,7 @@ class ExceptionListenerTest extends TestCase
$event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
$dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
$response = new Response('', 200, array('content-security-policy' => "style-src 'self'"));
$response = new Response('', 200, ['content-security-policy' => "style-src 'self'"]);
$this->assertTrue($response->headers->has('content-security-policy'));
$event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);

View File

@@ -68,7 +68,7 @@ class FragmentListenerTest extends TestCase
*/
public function testAccessDeniedWithWrongSignature()
{
$request = Request::create('http://example.com/_fragment', 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1'));
$request = Request::create('http://example.com/_fragment', 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']);
$listener = new FragmentListener(new UriSigner('foo'));
$event = $this->createGetResponseEvent($request);
@@ -79,14 +79,14 @@ class FragmentListenerTest extends TestCase
public function testWithSignature()
{
$signer = new UriSigner('foo');
$request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo'), 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1'));
$request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo'), 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']);
$listener = new FragmentListener($signer);
$event = $this->createGetResponseEvent($request);
$listener->onKernelRequest($event);
$this->assertEquals(array('foo' => 'bar', '_controller' => 'foo'), $request->attributes->get('_route_params'));
$this->assertEquals(['foo' => 'bar', '_controller' => 'foo'], $request->attributes->get('_route_params'));
$this->assertFalse($request->query->has('_path'));
}
@@ -105,7 +105,7 @@ class FragmentListenerTest extends TestCase
public function testRemovesPathWithControllerNotDefined()
{
$signer = new UriSigner('foo');
$request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar'), 'GET', array(), array(), array(), array('REMOTE_ADDR' => '10.0.0.1'));
$request = Request::create($signer->sign('http://example.com/_fragment?_path=foo%3Dbar'), 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']);
$listener = new FragmentListener($signer);
$event = $this->createGetResponseEvent($request);

View File

@@ -54,7 +54,7 @@ class LocaleListenerTest extends TestCase
$context = $this->getMockBuilder('Symfony\Component\Routing\RequestContext')->getMock();
$context->expects($this->once())->method('setParameter')->with('_locale', 'es');
$router = $this->getMockBuilder('Symfony\Component\Routing\Router')->setMethods(array('getContext'))->disableOriginalConstructor()->getMock();
$router = $this->getMockBuilder('Symfony\Component\Routing\Router')->setMethods(['getContext'])->disableOriginalConstructor()->getMock();
$router->expects($this->once())->method('getContext')->will($this->returnValue($context));
$request = Request::create('/');
@@ -70,7 +70,7 @@ class LocaleListenerTest extends TestCase
$context = $this->getMockBuilder('Symfony\Component\Routing\RequestContext')->getMock();
$context->expects($this->once())->method('setParameter')->with('_locale', 'es');
$router = $this->getMockBuilder('Symfony\Component\Routing\Router')->setMethods(array('getContext'))->disableOriginalConstructor()->getMock();
$router = $this->getMockBuilder('Symfony\Component\Routing\Router')->setMethods(['getContext'])->disableOriginalConstructor()->getMock();
$router->expects($this->once())->method('getContext')->will($this->returnValue($context));
$parentRequest = Request::create('/');

View File

@@ -19,6 +19,7 @@ use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\EventListener\ProfilerListener;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\HttpKernel\Profiler\Profile;
class ProfilerListenerTest extends TestCase
{
@@ -27,9 +28,7 @@ class ProfilerListenerTest extends TestCase
*/
public function testKernelTerminate()
{
$profile = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profile')
->disableOriginalConstructor()
->getMock();
$profile = new Profile('token');
$profiler = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler')
->disableOriginalConstructor()

View File

@@ -30,7 +30,7 @@ class ResponseListenerTest extends TestCase
{
$this->dispatcher = new EventDispatcher();
$listener = new ResponseListener('UTF-8');
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
$this->kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
}
@@ -54,7 +54,7 @@ class ResponseListenerTest extends TestCase
public function testFilterSetsNonDefaultCharsetIfNotOverridden()
{
$listener = new ResponseListener('ISO-8859-15');
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'), 1);
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
$response = new Response('foo');
@@ -67,7 +67,7 @@ class ResponseListenerTest extends TestCase
public function testFilterDoesNothingIfCharsetIsOverridden()
{
$listener = new ResponseListener('ISO-8859-15');
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'), 1);
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
$response = new Response('foo');
$response->setCharset('ISO-8859-1');
@@ -81,7 +81,7 @@ class ResponseListenerTest extends TestCase
public function testFiltersSetsNonDefaultCharsetIfNotOverriddenOnNonTextContentType()
{
$listener = new ResponseListener('ISO-8859-15');
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'), 1);
$this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse'], 1);
$response = new Response('foo');
$request = Request::create('/');

View File

@@ -62,12 +62,12 @@ class RouterListenerTest extends TestCase
public function getPortData()
{
return array(
array(80, 443, 'http://localhost/', 80, 443),
array(80, 443, 'http://localhost:90/', 90, 443),
array(80, 443, 'https://localhost/', 80, 443),
array(80, 443, 'https://localhost:90/', 80, 90),
);
return [
[80, 443, 'http://localhost/', 80, 443],
[80, 443, 'http://localhost:90/', 90, 443],
[80, 443, 'https://localhost/', 80, 443],
[80, 443, 'https://localhost:90/', 80, 90],
];
}
private function createGetResponseEventForUri(string $uri): GetResponseEvent
@@ -97,7 +97,7 @@ class RouterListenerTest extends TestCase
$requestMatcher->expects($this->once())
->method('matchRequest')
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->will($this->returnValue(array()));
->will($this->returnValue([]));
$listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext());
$listener->onKernelRequest($event);
@@ -113,7 +113,7 @@ class RouterListenerTest extends TestCase
$requestMatcher->expects($this->any())
->method('matchRequest')
->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->will($this->returnValue(array()));
->will($this->returnValue([]));
$context = new RequestContext();
@@ -154,10 +154,10 @@ class RouterListenerTest extends TestCase
public function getLoggingParameterData()
{
return array(
array(array('_route' => 'foo'), 'Matched route "{route}".', array('route' => 'foo', 'route_parameters' => array('_route' => 'foo'), 'request_uri' => 'http://localhost/', 'method' => 'GET')),
array(array(), 'Matched route "{route}".', array('route' => 'n/a', 'route_parameters' => array(), 'request_uri' => 'http://localhost/', 'method' => 'GET')),
);
return [
[['_route' => 'foo'], 'Matched route "{route}".', ['route' => 'foo', 'route_parameters' => ['_route' => 'foo'], 'request_uri' => 'http://localhost/', 'method' => 'GET']],
[[], 'Matched route "{route}".', ['route' => 'n/a', 'route_parameters' => [], 'request_uri' => 'http://localhost/', 'method' => 'GET']],
];
}
public function testWithBadRequest()

View File

@@ -15,8 +15,10 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
@@ -41,8 +43,16 @@ class SessionListenerTest extends TestCase
{
$session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock();
$requestStack = $this->getMockBuilder(RequestStack::class)->getMock();
$requestStack->expects($this->once())->method('getMasterRequest')->willReturn(null);
$sessionStorage = $this->getMockBuilder(NativeSessionStorage::class)->getMock();
$sessionStorage->expects($this->never())->method('setOptions')->with(['cookie_secure' => true]);
$container = new Container();
$container->set('session', $session);
$container->set('request_stack', $requestStack);
$container->set('session_storage', $sessionStorage);
$request = new Request();
$listener = new SessionListener($container);
@@ -113,9 +123,9 @@ class SessionListenerTest extends TestCase
$response->setSharedMaxAge(60);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
$container = new ServiceLocator(array(
$container = new ServiceLocator([
'initialized_session' => function () {},
));
]);
$listener = new SessionListener($container);
$listener->onKernelResponse(new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
@@ -140,7 +150,7 @@ class SessionListenerTest extends TestCase
$request = new Request();
$response = new Response();
$response->setCache(array('public' => true, 'max_age' => '30'));
$response->setCache(['public' => true, 'max_age' => '30']);
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
$this->assertTrue($request->hasSession());

View File

@@ -30,7 +30,7 @@ class SurrogateListenerTest extends TestCase
$response = new Response('foo <esi:include src="" />');
$listener = new SurrogateListener(new Esi());
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
@@ -44,7 +44,7 @@ class SurrogateListenerTest extends TestCase
$response = new Response('foo <esi:include src="" />');
$listener = new SurrogateListener(new Esi());
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
@@ -58,7 +58,7 @@ class SurrogateListenerTest extends TestCase
$response = new Response('foo');
$listener = new SurrogateListener(new Esi());
$dispatcher->addListener(KernelEvents::RESPONSE, array($listener, 'onKernelResponse'));
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);

View File

@@ -86,7 +86,7 @@ class TestSessionListenerTest extends TestCase
$response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST);
$this->assertSame(array(), $response->headers->getCookies());
$this->assertSame([], $response->headers->getCookies());
}
public function testEmptySessionWithNewSessionIdDoesSendCookie()
@@ -96,7 +96,7 @@ class TestSessionListenerTest extends TestCase
$this->fixSessionId('456');
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$request = Request::create('/', 'GET', array(), array('MOCKSESSID' => '123'));
$request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']);
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
@@ -115,11 +115,11 @@ class TestSessionListenerTest extends TestCase
$this->fixSessionId('456');
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$request = Request::create('/', 'GET', array(), array('MOCKSESSID' => '123'));
$request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']);
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
$response = new Response('', 200, array('Set-Cookie' => $existing));
$response = new Response('', 200, ['Set-Cookie' => $existing]);
$response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
@@ -128,11 +128,11 @@ class TestSessionListenerTest extends TestCase
public function anotherCookieProvider()
{
return array(
'same' => array('MOCKSESSID=789; path=/', array('MOCKSESSID=789; path=/')),
'different domain' => array('MOCKSESSID=789; path=/; domain=example.com', array('MOCKSESSID=789; path=/; domain=example.com', 'MOCKSESSID=456; path=/')),
'different path' => array('MOCKSESSID=789; path=/foo', array('MOCKSESSID=789; path=/foo', 'MOCKSESSID=456; path=/')),
);
return [
'same' => ['MOCKSESSID=789; path=/', ['MOCKSESSID=789; path=/']],
'different domain' => ['MOCKSESSID=789; path=/; domain=example.com', ['MOCKSESSID=789; path=/; domain=example.com', 'MOCKSESSID=456; path=/']],
'different path' => ['MOCKSESSID=789; path=/foo', ['MOCKSESSID=789; path=/foo', 'MOCKSESSID=456; path=/']],
];
}
public function testUnstartedSessionIsNotSave()

View File

@@ -23,7 +23,7 @@ class ValidateRequestListenerTest extends TestCase
{
protected function tearDown()
{
Request::setTrustedProxies(array(), -1);
Request::setTrustedProxies([], -1);
}
/**
@@ -35,12 +35,12 @@ class ValidateRequestListenerTest extends TestCase
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$request = new Request();
$request->setTrustedProxies(array('1.1.1.1'), Request::HEADER_X_FORWARDED_FOR | Request::HEADER_FORWARDED);
$request->setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_FOR | Request::HEADER_FORWARDED);
$request->server->set('REMOTE_ADDR', '1.1.1.1');
$request->headers->set('FORWARDED', 'for=2.2.2.2');
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
$dispatcher->addListener(KernelEvents::REQUEST, array(new ValidateRequestListener(), 'onKernelRequest'));
$dispatcher->addListener(KernelEvents::REQUEST, [new ValidateRequestListener(), 'onKernelRequest']);
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$dispatcher->dispatch(KernelEvents::REQUEST, $event);

View File

@@ -9,22 +9,22 @@ class HttpExceptionTest extends TestCase
{
public function headerDataProvider()
{
return array(
array(array('X-Test' => 'Test')),
array(array('X-Test' => 1)),
array(
array(
array('X-Test' => 'Test'),
array('X-Test-2' => 'Test-2'),
),
),
);
return [
[['X-Test' => 'Test']],
[['X-Test' => 1]],
[
[
['X-Test' => 'Test'],
['X-Test-2' => 'Test-2'],
],
],
];
}
public function testHeadersDefault()
{
$exception = $this->createException();
$this->assertSame(array(), $exception->getHeaders());
$this->assertSame([], $exception->getHeaders());
}
/**

View File

@@ -8,17 +8,17 @@ class MethodNotAllowedHttpExceptionTest extends HttpExceptionTest
{
public function testHeadersDefault()
{
$exception = new MethodNotAllowedHttpException(array('GET', 'PUT'));
$this->assertSame(array('Allow' => 'GET, PUT'), $exception->getHeaders());
$exception = new MethodNotAllowedHttpException(['GET', 'PUT']);
$this->assertSame(['Allow' => 'GET, PUT'], $exception->getHeaders());
}
public function testWithHeaderConstruct()
{
$headers = array(
$headers = [
'Cache-Control' => 'public, s-maxage=1200',
);
];
$exception = new MethodNotAllowedHttpException(array('get'), null, null, null, $headers);
$exception = new MethodNotAllowedHttpException(['get'], null, null, null, $headers);
$headers['Allow'] = 'GET';
@@ -30,7 +30,7 @@ class MethodNotAllowedHttpExceptionTest extends HttpExceptionTest
*/
public function testHeadersSetter($headers)
{
$exception = new MethodNotAllowedHttpException(array('GET'));
$exception = new MethodNotAllowedHttpException(['GET']);
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}

View File

@@ -9,14 +9,14 @@ class ServiceUnavailableHttpExceptionTest extends HttpExceptionTest
public function testHeadersDefaultRetryAfter()
{
$exception = new ServiceUnavailableHttpException(10);
$this->assertSame(array('Retry-After' => 10), $exception->getHeaders());
$this->assertSame(['Retry-After' => 10], $exception->getHeaders());
}
public function testWithHeaderConstruct()
{
$headers = array(
$headers = [
'Cache-Control' => 'public, s-maxage=1337',
);
];
$exception = new ServiceUnavailableHttpException(1337, null, null, null, $headers);

View File

@@ -9,14 +9,14 @@ class TooManyRequestsHttpExceptionTest extends HttpExceptionTest
public function testHeadersDefaultRertyAfter()
{
$exception = new TooManyRequestsHttpException(10);
$this->assertSame(array('Retry-After' => 10), $exception->getHeaders());
$this->assertSame(['Retry-After' => 10], $exception->getHeaders());
}
public function testWithHeaderConstruct()
{
$headers = array(
$headers = [
'Cache-Control' => 'public, s-maxage=69',
);
];
$exception = new TooManyRequestsHttpException(69, null, null, null, $headers);

View File

@@ -9,14 +9,14 @@ class UnauthorizedHttpExceptionTest extends HttpExceptionTest
public function testHeadersDefault()
{
$exception = new UnauthorizedHttpException('Challenge');
$this->assertSame(array('WWW-Authenticate' => 'Challenge'), $exception->getHeaders());
$this->assertSame(['WWW-Authenticate' => 'Challenge'], $exception->getHeaders());
}
public function testWithHeaderConstruct()
{
$headers = array(
$headers = [
'Cache-Control' => 'public, s-maxage=1200',
);
];
$exception = new UnauthorizedHttpException('Challenge', null, null, null, $headers);

View File

@@ -31,7 +31,7 @@ class CloneVarDataCollector extends DataCollector
public function reset()
{
$this->data = array();
$this->data = [];
}
public function getData()

View File

@@ -23,7 +23,7 @@ class KernelForTest extends Kernel
public function registerBundles()
{
return array();
return [];
}
public function registerContainerConfiguration(LoaderInterface $loader)

View File

@@ -19,7 +19,7 @@ class KernelWithoutBundles extends Kernel
{
public function registerBundles()
{
return array();
return [];
}
public function registerContainerConfiguration(LoaderInterface $loader)

View File

@@ -17,12 +17,12 @@ class TestEventDispatcher extends TraceableEventDispatcher
{
public function getCalledListeners()
{
return array('foo');
return ['foo'];
}
public function getNotCalledListeners()
{
return array('bar');
return ['bar'];
}
public function reset()
@@ -31,6 +31,6 @@ class TestEventDispatcher extends TraceableEventDispatcher
public function getOrphanedEvents()
{
return array();
return [];
}
}

View File

@@ -30,7 +30,7 @@ class EsiFragmentRendererTest extends TestCase
{
$strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy(true), new UriSigner('foo'));
$request = Request::create('/');
$reference = new ControllerReference('main_controller', array('foo' => array(true)), array());
$reference = new ControllerReference('main_controller', ['foo' => [true]], []);
$strategy->render($reference, $request);
}
@@ -43,8 +43,8 @@ class EsiFragmentRendererTest extends TestCase
$request->headers->set('Surrogate-Capability', 'ESI/1.0');
$this->assertEquals('<esi:include src="/" />', $strategy->render('/', $request)->getContent());
$this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent());
$this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, array('alt' => 'foo'))->getContent());
$this->assertEquals("<esi:comment text=\"This is a comment\" />\n<esi:include src=\"/\" />", $strategy->render('/', $request, ['comment' => 'This is a comment'])->getContent());
$this->assertEquals('<esi:include src="/" alt="foo" />', $strategy->render('/', $request, ['alt' => 'foo'])->getContent());
}
public function testRenderControllerReference()
@@ -56,12 +56,12 @@ class EsiFragmentRendererTest extends TestCase
$request->setLocale('fr');
$request->headers->set('Surrogate-Capability', 'ESI/1.0');
$reference = new ControllerReference('main_controller', array(), array());
$altReference = new ControllerReference('alt_controller', array(), array());
$reference = new ControllerReference('main_controller', [], []);
$altReference = new ControllerReference('alt_controller', [], []);
$this->assertEquals(
'<esi:include src="/_fragment?_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D&_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" alt="/_fragment?_hash=iPJEdRoUpGrM1ztqByiorpfMPtiW%2FOWwdH1DBUXHhEc%3D&_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dalt_controller" />',
$strategy->render($reference, $request, array('alt' => $altReference))->getContent()
$strategy->render($reference, $request, ['alt' => $altReference])->getContent()
);
}
@@ -90,7 +90,7 @@ class EsiFragmentRendererTest extends TestCase
$request->setLocale('fr');
$request->headers->set('Surrogate-Capability', 'ESI/1.0');
$strategy->render('/', $request, array('alt' => new ControllerReference('alt_controller')));
$strategy->render('/', $request, ['alt' => new ControllerReference('alt_controller')]);
}
private function getInlineStrategy($called = false)

View File

@@ -68,12 +68,12 @@ class FragmentHandlerTest extends TestCase
public function testRender()
{
$handler = $this->getHandler($this->returnValue(new Response('foo')), array('/', Request::create('/'), array('foo' => 'foo', 'ignore_errors' => true)));
$handler = $this->getHandler($this->returnValue(new Response('foo')), ['/', Request::create('/'), ['foo' => 'foo', 'ignore_errors' => true]]);
$this->assertEquals('foo', $handler->render('/', 'foo', array('foo' => 'foo')));
$this->assertEquals('foo', $handler->render('/', 'foo', ['foo' => 'foo']));
}
protected function getHandler($returnValue, $arguments = array())
protected function getHandler($returnValue, $arguments = [])
{
$renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
$renderer

View File

@@ -25,14 +25,14 @@ class HIncludeFragmentRendererTest extends TestCase
public function testRenderExceptionWhenControllerAndNoSigner()
{
$strategy = new HIncludeFragmentRenderer();
$strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'));
$strategy->render(new ControllerReference('main_controller', [], []), Request::create('/'));
}
public function testRenderWithControllerAndSigner()
{
$strategy = new HIncludeFragmentRenderer(null, new UriSigner('foo'));
$this->assertEquals('<hx:include src="/_fragment?_hash=BP%2BOzCD5MRUI%2BHJpgPDOmoju00FnzLhP3TGcSHbbBLs%3D&amp;_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller"></hx:include>', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
$this->assertEquals('<hx:include src="/_fragment?_hash=BP%2BOzCD5MRUI%2BHJpgPDOmoju00FnzLhP3TGcSHbbBLs%3D&amp;_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller"></hx:include>', $strategy->render(new ControllerReference('main_controller', [], []), Request::create('/'))->getContent());
}
public function testRenderWithUri()
@@ -48,30 +48,30 @@ class HIncludeFragmentRendererTest extends TestCase
{
// only default
$strategy = new HIncludeFragmentRenderer();
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), ['default' => 'default'])->getContent());
// only global default
$strategy = new HIncludeFragmentRenderer(null, null, 'global_default');
$this->assertEquals('<hx:include src="/foo">global_default</hx:include>', $strategy->render('/foo', Request::create('/'), array())->getContent());
$this->assertEquals('<hx:include src="/foo">global_default</hx:include>', $strategy->render('/foo', Request::create('/'), [])->getContent());
// global default and default
$strategy = new HIncludeFragmentRenderer(null, null, 'global_default');
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), ['default' => 'default'])->getContent());
}
public function testRenderWithAttributesOptions()
{
// with id
$strategy = new HIncludeFragmentRenderer();
$this->assertEquals('<hx:include src="/foo" id="bar">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default', 'id' => 'bar'))->getContent());
$this->assertEquals('<hx:include src="/foo" id="bar">default</hx:include>', $strategy->render('/foo', Request::create('/'), ['default' => 'default', 'id' => 'bar'])->getContent());
// with attributes
$strategy = new HIncludeFragmentRenderer();
$this->assertEquals('<hx:include src="/foo" p1="v1" p2="v2">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default', 'attributes' => array('p1' => 'v1', 'p2' => 'v2')))->getContent());
$this->assertEquals('<hx:include src="/foo" p1="v1" p2="v2">default</hx:include>', $strategy->render('/foo', Request::create('/'), ['default' => 'default', 'attributes' => ['p1' => 'v1', 'p2' => 'v2']])->getContent());
// with id & attributes
$strategy = new HIncludeFragmentRenderer();
$this->assertEquals('<hx:include src="/foo" p1="v1" p2="v2" id="bar">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default', 'id' => 'bar', 'attributes' => array('p1' => 'v1', 'p2' => 'v2')))->getContent());
$this->assertEquals('<hx:include src="/foo" p1="v1" p2="v2" id="bar">default</hx:include>', $strategy->render('/foo', Request::create('/'), ['default' => 'default', 'id' => 'bar', 'attributes' => ['p1' => 'v1', 'p2' => 'v2']])->getContent());
}
public function testRenderWithDefaultText()
@@ -84,7 +84,7 @@ class HIncludeFragmentRendererTest extends TestCase
// only default
$strategy = new HIncludeFragmentRenderer($engine);
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'default'))->getContent());
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), ['default' => 'default'])->getContent());
}
public function testRenderWithEngineAndDefaultText()
@@ -97,6 +97,6 @@ class HIncludeFragmentRendererTest extends TestCase
// only default
$strategy = new HIncludeFragmentRenderer($engine);
$this->assertEquals('<hx:include src="/foo">loading...</hx:include>', $strategy->render('/foo', Request::create('/'), array('default' => 'loading...'))->getContent());
$this->assertEquals('<hx:include src="/foo">loading...</hx:include>', $strategy->render('/foo', Request::create('/'), ['default' => 'loading...'])->getContent());
}
}

View File

@@ -34,7 +34,7 @@ class InlineFragmentRendererTest extends TestCase
{
$strategy = new InlineFragmentRenderer($this->getKernel($this->returnValue(new Response('foo'))));
$this->assertEquals('foo', $strategy->render(new ControllerReference('main_controller', array(), array()), Request::create('/'))->getContent());
$this->assertEquals('foo', $strategy->render(new ControllerReference('main_controller', [], []), Request::create('/'))->getContent());
}
public function testRenderWithObjectsAsAttributes()
@@ -42,29 +42,29 @@ class InlineFragmentRendererTest extends TestCase
$object = new \stdClass();
$subRequest = Request::create('/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dmain_controller');
$subRequest->attributes->replace(array('object' => $object, '_format' => 'html', '_controller' => 'main_controller', '_locale' => 'en'));
$subRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$subRequest->headers->set('forwarded', array('for="127.0.0.1";host="localhost";proto=http'));
$subRequest->attributes->replace(['object' => $object, '_format' => 'html', '_controller' => 'main_controller', '_locale' => 'en']);
$subRequest->headers->set('x-forwarded-for', ['127.0.0.1']);
$subRequest->headers->set('forwarded', ['for="127.0.0.1";host="localhost";proto=http']);
$subRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
$subRequest->server->set('HTTP_FORWARDED', 'for="127.0.0.1";host="localhost";proto=http');
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($subRequest));
$this->assertSame('foo', $strategy->render(new ControllerReference('main_controller', array('object' => $object), array()), Request::create('/'))->getContent());
$this->assertSame('foo', $strategy->render(new ControllerReference('main_controller', ['object' => $object], []), Request::create('/'))->getContent());
}
public function testRenderWithTrustedHeaderDisabled()
{
Request::setTrustedProxies(array(), 0);
Request::setTrustedProxies([], 0);
$expectedSubRequest = Request::create('/');
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$expectedSubRequest->headers->set('x-forwarded-for', ['127.0.0.1']);
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));
$this->assertSame('foo', $strategy->render('/', Request::create('/'))->getContent());
Request::setTrustedProxies(array(), -1);
Request::setTrustedProxies([], -1);
}
/**
@@ -87,7 +87,7 @@ class InlineFragmentRendererTest extends TestCase
$strategy = new InlineFragmentRenderer($this->getKernel($this->throwException(new \RuntimeException('foo'))), $dispatcher);
$this->assertEmpty($strategy->render('/', Request::create('/'), array('ignore_errors' => true))->getContent());
$this->assertEmpty($strategy->render('/', Request::create('/'), ['ignore_errors' => true])->getContent());
}
public function testRenderExceptionIgnoreErrorsWithAlt()
@@ -97,7 +97,7 @@ class InlineFragmentRendererTest extends TestCase
$this->returnValue(new Response('bar'))
)));
$this->assertEquals('bar', $strategy->render('/', Request::create('/'), array('ignore_errors' => true, 'alt' => '/foo'))->getContent());
$this->assertEquals('bar', $strategy->render('/', Request::create('/'), ['ignore_errors' => true, 'alt' => '/foo'])->getContent());
}
private function getKernel($returnValue)
@@ -129,7 +129,7 @@ class InlineFragmentRendererTest extends TestCase
$argumentResolver
->expects($this->once())
->method('getArguments')
->will($this->returnValue(array()))
->will($this->returnValue([]))
;
$kernel = new HttpKernel(new EventDispatcher(), $controllerResolver, new RequestStack(), $argumentResolver);
@@ -140,7 +140,7 @@ class InlineFragmentRendererTest extends TestCase
echo 'Foo';
// simulate a sub-request with output buffering and an exception
$renderer->render('/', Request::create('/'), array('ignore_errors' => true));
$renderer->render('/', Request::create('/'), ['ignore_errors' => true]);
$this->assertEquals('Foo', ob_get_clean());
}
@@ -151,10 +151,10 @@ class InlineFragmentRendererTest extends TestCase
$expectedSubRequest->attributes->set('_format', 'foo');
$expectedSubRequest->setLocale('fr');
if (Request::HEADER_X_FORWARDED_FOR & Request::getTrustedHeaderSet()) {
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$expectedSubRequest->headers->set('x-forwarded-for', ['127.0.0.1']);
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
}
$expectedSubRequest->headers->set('forwarded', array('for="127.0.0.1";host="localhost";proto=http'));
$expectedSubRequest->headers->set('forwarded', ['for="127.0.0.1";host="localhost";proto=http']);
$expectedSubRequest->server->set('HTTP_FORWARDED', 'for="127.0.0.1";host="localhost";proto=http');
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));
@@ -171,10 +171,10 @@ class InlineFragmentRendererTest extends TestCase
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
if (Request::HEADER_X_FORWARDED_FOR & Request::getTrustedHeaderSet()) {
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$expectedSubRequest->headers->set('x-forwarded-for', ['127.0.0.1']);
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
}
$expectedSubRequest->headers->set('forwarded', array('for="127.0.0.1";host="localhost";proto=http'));
$expectedSubRequest->headers->set('forwarded', ['for="127.0.0.1";host="localhost";proto=http']);
$expectedSubRequest->server->set('HTTP_FORWARDED', 'for="127.0.0.1";host="localhost";proto=http');
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));
@@ -186,35 +186,35 @@ class InlineFragmentRendererTest extends TestCase
public function testESIHeaderIsKeptInSubrequestWithTrustedHeaderDisabled()
{
Request::setTrustedProxies(array(), Request::HEADER_FORWARDED);
Request::setTrustedProxies([], Request::HEADER_FORWARDED);
$this->testESIHeaderIsKeptInSubrequest();
Request::setTrustedProxies(array(), -1);
Request::setTrustedProxies([], -1);
}
public function testHeadersPossiblyResultingIn304AreNotAssignedToSubrequest()
{
$expectedSubRequest = Request::create('/');
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$expectedSubRequest->headers->set('forwarded', array('for="127.0.0.1";host="localhost";proto=http'));
$expectedSubRequest->headers->set('x-forwarded-for', ['127.0.0.1']);
$expectedSubRequest->headers->set('forwarded', ['for="127.0.0.1";host="localhost";proto=http']);
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
$expectedSubRequest->server->set('HTTP_FORWARDED', 'for="127.0.0.1";host="localhost";proto=http');
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));
$request = Request::create('/', 'GET', array(), array(), array(), array('HTTP_IF_MODIFIED_SINCE' => 'Fri, 01 Jan 2016 00:00:00 GMT', 'HTTP_IF_NONE_MATCH' => '*'));
$request = Request::create('/', 'GET', [], [], [], ['HTTP_IF_MODIFIED_SINCE' => 'Fri, 01 Jan 2016 00:00:00 GMT', 'HTTP_IF_NONE_MATCH' => '*']);
$strategy->render('/', $request);
}
public function testFirstTrustedProxyIsSetAsRemote()
{
Request::setTrustedProxies(array('1.1.1.1'), -1);
Request::setTrustedProxies(['1.1.1.1'], -1);
$expectedSubRequest = Request::create('/');
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
$expectedSubRequest->server->set('REMOTE_ADDR', '127.0.0.1');
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$expectedSubRequest->headers->set('forwarded', array('for="127.0.0.1";host="localhost";proto=http'));
$expectedSubRequest->headers->set('x-forwarded-for', ['127.0.0.1']);
$expectedSubRequest->headers->set('forwarded', ['for="127.0.0.1";host="localhost";proto=http']);
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
$expectedSubRequest->server->set('HTTP_FORWARDED', 'for="127.0.0.1";host="localhost";proto=http');
@@ -224,7 +224,7 @@ class InlineFragmentRendererTest extends TestCase
$request->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
$strategy->render('/', $request);
Request::setTrustedProxies(array(), -1);
Request::setTrustedProxies([], -1);
}
public function testIpAddressOfRangedTrustedProxyIsSetAsRemote()
@@ -232,12 +232,12 @@ class InlineFragmentRendererTest extends TestCase
$expectedSubRequest = Request::create('/');
$expectedSubRequest->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
$expectedSubRequest->server->set('REMOTE_ADDR', '127.0.0.1');
$expectedSubRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$expectedSubRequest->headers->set('forwarded', array('for="127.0.0.1";host="localhost";proto=http'));
$expectedSubRequest->headers->set('x-forwarded-for', ['127.0.0.1']);
$expectedSubRequest->headers->set('forwarded', ['for="127.0.0.1";host="localhost";proto=http']);
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
$expectedSubRequest->server->set('HTTP_FORWARDED', 'for="127.0.0.1";host="localhost";proto=http');
Request::setTrustedProxies(array('1.1.1.1/24'), -1);
Request::setTrustedProxies(['1.1.1.1/24'], -1);
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));
@@ -245,7 +245,7 @@ class InlineFragmentRendererTest extends TestCase
$request->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
$strategy->render('/', $request);
Request::setTrustedProxies(array(), -1);
Request::setTrustedProxies([], -1);
}
/**

View File

@@ -35,14 +35,14 @@ class RoutableFragmentRendererTest extends TestCase
public function getGenerateFragmentUriData()
{
return array(
array('/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array())),
array('/_fragment?_path=_format%3Dxml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('_format' => 'xml'), array())),
array('/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo', '_format' => 'json'), array())),
array('/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => 'foo'), array('bar' => 'bar'))),
array('/_fragment?foo=foo&_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array(), array('foo' => 'foo'))),
array('/_fragment?_path=foo%255B0%255D%3Dfoo%26foo%255B1%255D%3Dbar%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', array('foo' => array('foo', 'bar')), array())),
);
return [
['/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', [], [])],
['/_fragment?_path=_format%3Dxml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', ['_format' => 'xml'], [])],
['/_fragment?_path=foo%3Dfoo%26_format%3Djson%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', ['foo' => 'foo', '_format' => 'json'], [])],
['/_fragment?bar=bar&_path=foo%3Dfoo%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', ['foo' => 'foo'], ['bar' => 'bar'])],
['/_fragment?foo=foo&_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', [], ['foo' => 'foo'])],
['/_fragment?_path=foo%255B0%255D%3Dfoo%26foo%255B1%255D%3Dbar%26_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', ['foo' => ['foo', 'bar']], [])],
];
}
public function testGenerateFragmentUriWithARequest()
@@ -50,7 +50,7 @@ class RoutableFragmentRendererTest extends TestCase
$request = Request::create('/');
$request->attributes->set('_format', 'json');
$request->setLocale('fr');
$controller = new ControllerReference('controller', array(), array());
$controller = new ControllerReference('controller', [], []);
$this->assertEquals('/_fragment?_path=_format%3Djson%26_locale%3Dfr%26_controller%3Dcontroller', $this->callGenerateFragmentUriMethod($controller, $request));
}
@@ -66,10 +66,10 @@ class RoutableFragmentRendererTest extends TestCase
public function getGenerateFragmentUriDataWithNonScalar()
{
return array(
array(new ControllerReference('controller', array('foo' => new Foo(), 'bar' => 'bar'), array())),
array(new ControllerReference('controller', array('foo' => array('foo' => 'foo'), 'bar' => array('bar' => new Foo())), array())),
);
return [
[new ControllerReference('controller', ['foo' => new Foo(), 'bar' => 'bar'], [])],
[new ControllerReference('controller', ['foo' => ['foo' => 'foo'], 'bar' => ['bar' => new Foo()]], [])],
];
}
private function callGenerateFragmentUriMethod(ControllerReference $reference, Request $request, $absolute = false)

View File

@@ -35,7 +35,7 @@ class SsiFragmentRendererTest extends TestCase
$request->headers->set('Surrogate-Capability', 'SSI/1.0');
$this->assertEquals('<!--#include virtual="/" -->', $strategy->render('/', $request)->getContent());
$this->assertEquals('<!--#include virtual="/" -->', $strategy->render('/', $request, array('comment' => 'This is a comment'))->getContent(), 'Strategy options should not impact the ssi include tag');
$this->assertEquals('<!--#include virtual="/" -->', $strategy->render('/', $request, ['comment' => 'This is a comment'])->getContent(), 'Strategy options should not impact the ssi include tag');
}
public function testRenderControllerReference()
@@ -47,12 +47,12 @@ class SsiFragmentRendererTest extends TestCase
$request->setLocale('fr');
$request->headers->set('Surrogate-Capability', 'SSI/1.0');
$reference = new ControllerReference('main_controller', array(), array());
$altReference = new ControllerReference('alt_controller', array(), array());
$reference = new ControllerReference('main_controller', [], []);
$altReference = new ControllerReference('alt_controller', [], []);
$this->assertEquals(
'<!--#include virtual="/_fragment?_hash=Jz1P8NErmhKTeI6onI1EdAXTB85359MY3RIk5mSJ60w%3D&_path=_format%3Dhtml%26_locale%3Dfr%26_controller%3Dmain_controller" -->',
$strategy->render($reference, $request, array('alt' => $altReference))->getContent()
$strategy->render($reference, $request, ['alt' => $altReference])->getContent()
);
}
@@ -81,7 +81,7 @@ class SsiFragmentRendererTest extends TestCase
$request->setLocale('fr');
$request->headers->set('Surrogate-Capability', 'SSI/1.0');
$strategy->render('/', $request, array('alt' => new ControllerReference('alt_controller')));
$strategy->render('/', $request, ['alt' => new ControllerReference('alt_controller')]);
}
private function getInlineStrategy($called = false)

View File

@@ -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))

View File

@@ -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();

View File

@@ -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)) {

View 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'],
],
];
}
}

View File

@@ -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))

View File

@@ -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);
}

View File

@@ -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(),
);
];
}
}

View File

@@ -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)

View File

@@ -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)

View File

@@ -105,7 +105,7 @@ class HttpKernelTest extends TestCase
$event->setResponse(new Response($event->getException()->getMessage()));
});
$kernel = $this->getHttpKernel($dispatcher, function () { throw new MethodNotAllowedHttpException(array('POST')); });
$kernel = $this->getHttpKernel($dispatcher, function () { throw new MethodNotAllowedHttpException(['POST']); });
$response = $kernel->handle(new Request());
$this->assertEquals('405', $response->getStatusCode());
@@ -114,12 +114,12 @@ class HttpKernelTest extends TestCase
public function getStatusCodes()
{
return array(
array(200, 404),
array(404, 200),
array(301, 200),
array(500, 200),
);
return [
[200, 404],
[404, 200],
[301, 200],
[500, 200],
];
}
/**
@@ -141,11 +141,11 @@ class HttpKernelTest extends TestCase
public function getSpecificStatusCodes()
{
return array(
array(200),
array(302),
array(403),
);
return [
[200],
[302],
[403],
];
}
public function testHandleWhenAListenerReturnsAResponse()
@@ -199,7 +199,7 @@ class HttpKernelTest extends TestCase
public function testHandleWhenTheControllerIsAnArray()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getHttpKernel($dispatcher, array(new TestController(), 'controller'));
$kernel = $this->getHttpKernel($dispatcher, [new TestController(), 'controller']);
$this->assertResponseEquals(new Response('foo'), $kernel->handle(new Request()));
}
@@ -207,7 +207,7 @@ class HttpKernelTest extends TestCase
public function testHandleWhenTheControllerIsAStaticArray()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getHttpKernel($dispatcher, array('Symfony\Component\HttpKernel\Tests\TestController', 'staticcontroller'));
$kernel = $this->getHttpKernel($dispatcher, ['Symfony\Component\HttpKernel\Tests\TestController', 'staticcontroller']);
$this->assertResponseEquals(new Response('foo'), $kernel->handle(new Request()));
}
@@ -258,7 +258,7 @@ class HttpKernelTest extends TestCase
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::CONTROLLER_ARGUMENTS, function (FilterControllerArgumentsEvent $event) {
$event->setArguments(array('foo'));
$event->setArguments(['foo']);
});
$kernel = $this->getHttpKernel($dispatcher, function ($content) { return new Response($content); });
@@ -282,12 +282,12 @@ class HttpKernelTest extends TestCase
};
$event->setController($newController);
$event->setArguments(array('bar'));
$event->setArguments(['bar']);
});
$kernel = $this->getHttpKernel($dispatcher, function ($content) { return new Response($content); }, null, array('foo'));
$kernel = $this->getHttpKernel($dispatcher, function ($content) { return new Response($content); }, null, ['foo']);
$this->assertResponseEquals(new Response('foo', 200, array('X-Id' => 'bar')), $kernel->handle(new Request()));
$this->assertResponseEquals(new Response('foo', 200, ['X-Id' => 'bar']), $kernel->handle(new Request()));
}
public function testTerminate()
@@ -312,7 +312,7 @@ class HttpKernelTest extends TestCase
{
$request = new Request();
$stack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->setMethods(array('push', 'pop'))->getMock();
$stack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->setMethods(['push', 'pop'])->getMock();
$stack->expects($this->at(0))->method('push')->with($this->equalTo($request));
$stack->expects($this->at(1))->method('pop');
@@ -328,7 +328,7 @@ class HttpKernelTest extends TestCase
public function testInconsistentClientIpsOnMasterRequests()
{
$request = new Request();
$request->setTrustedProxies(array('1.1.1.1'), Request::HEADER_X_FORWARDED_FOR | Request::HEADER_FORWARDED);
$request->setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_FOR | Request::HEADER_FORWARDED);
$request->server->set('REMOTE_ADDR', '1.1.1.1');
$request->headers->set('FORWARDED', 'for=2.2.2.2');
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
@@ -341,10 +341,10 @@ class HttpKernelTest extends TestCase
$kernel = $this->getHttpKernel($dispatcher);
$kernel->handle($request, $kernel::MASTER_REQUEST, false);
Request::setTrustedProxies(array(), -1);
Request::setTrustedProxies([], -1);
}
private function getHttpKernel(EventDispatcherInterface $eventDispatcher, $controller = null, RequestStack $requestStack = null, array $arguments = array())
private function getHttpKernel(EventDispatcherInterface $eventDispatcher, $controller = null, RequestStack $requestStack = null, array $arguments = [])
{
if (null === $controller) {
$controller = function () { return new Response('Hello'); };

View File

@@ -91,7 +91,7 @@ class KernelTest extends TestCase
public function testBootInitializesBundlesAndContainer()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer'));
$kernel = $this->getKernel(['initializeBundles', 'initializeContainer']);
$kernel->expects($this->once())
->method('initializeBundles');
$kernel->expects($this->once())
@@ -106,10 +106,10 @@ class KernelTest extends TestCase
$bundle->expects($this->once())
->method('setContainer');
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'getBundles'));
$kernel = $this->getKernel(['initializeBundles', 'initializeContainer', 'getBundles']);
$kernel->expects($this->once())
->method('getBundles')
->will($this->returnValue(array($bundle)));
->will($this->returnValue([$bundle]));
$kernel->boot();
}
@@ -117,7 +117,7 @@ class KernelTest extends TestCase
public function testBootSetsTheBootedFlagToTrue()
{
// use test kernel to access isBooted()
$kernel = $this->getKernelForTest(array('initializeBundles', 'initializeContainer'));
$kernel = $this->getKernelForTest(['initializeBundles', 'initializeContainer']);
$kernel->boot();
$this->assertTrue($kernel->isBooted());
@@ -125,7 +125,7 @@ class KernelTest extends TestCase
public function testClassCacheIsNotLoadedByDefault()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer', 'doLoadClassCache'));
$kernel = $this->getKernel(['initializeBundles', 'initializeContainer', 'doLoadClassCache']);
$kernel->expects($this->never())
->method('doLoadClassCache');
@@ -134,7 +134,7 @@ class KernelTest extends TestCase
public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce()
{
$kernel = $this->getKernel(array('initializeBundles', 'initializeContainer'));
$kernel = $this->getKernel(['initializeBundles', 'initializeContainer']);
$kernel->expects($this->once())
->method('initializeBundles');
@@ -148,7 +148,7 @@ class KernelTest extends TestCase
$bundle->expects($this->once())
->method('shutdown');
$kernel = $this->getKernel(array(), array($bundle));
$kernel = $this->getKernel([], [$bundle]);
$kernel->boot();
$kernel->shutdown();
@@ -161,10 +161,10 @@ class KernelTest extends TestCase
->method('setContainer')
->with(null);
$kernel = $this->getKernel(array('getBundles'));
$kernel = $this->getKernel(['getBundles']);
$kernel->expects($this->any())
->method('getBundles')
->will($this->returnValue(array($bundle)));
->will($this->returnValue([$bundle]));
$kernel->boot();
$kernel->shutdown();
@@ -184,7 +184,7 @@ class KernelTest extends TestCase
->method('handle')
->with($request, $type, $catch);
$kernel = $this->getKernel(array('getHttpKernel'));
$kernel = $this->getKernel(['getHttpKernel']);
$kernel->expects($this->once())
->method('getHttpKernel')
->will($this->returnValue($httpKernelMock));
@@ -202,7 +202,7 @@ class KernelTest extends TestCase
->disableOriginalConstructor()
->getMock();
$kernel = $this->getKernel(array('getHttpKernel', 'boot'));
$kernel = $this->getKernel(['getHttpKernel', 'boot']);
$kernel->expects($this->once())
->method('getHttpKernel')
->will($this->returnValue($httpKernelMock));
@@ -331,7 +331,7 @@ EOF;
$debug = true;
$kernel = new KernelForTest($env, $debug);
$expected = serialize(array($env, $debug));
$expected = serialize([$env, $debug]);
$this->assertEquals($expected, $kernel->serialize());
}
@@ -364,7 +364,7 @@ EOF;
*/
public function testLocateResourceThrowsExceptionWhenResourceDoesNotExist()
{
$kernel = $this->getKernel(array('getBundle'));
$kernel = $this->getKernel(['getBundle']);
$kernel
->expects($this->once())
->method('getBundle')
@@ -376,7 +376,7 @@ EOF;
public function testLocateResourceReturnsTheFirstThatMatches()
{
$kernel = $this->getKernel(array('getBundle'));
$kernel = $this->getKernel(['getBundle']);
$kernel
->expects($this->once())
->method('getBundle')
@@ -388,7 +388,7 @@ EOF;
public function testLocateResourceIgnoresDirOnNonResource()
{
$kernel = $this->getKernel(array('getBundle'));
$kernel = $this->getKernel(['getBundle']);
$kernel
->expects($this->once())
->method('getBundle')
@@ -403,7 +403,7 @@ EOF;
public function testLocateResourceReturnsTheDirOneForResources()
{
$kernel = $this->getKernel(array('getBundle'));
$kernel = $this->getKernel(['getBundle']);
$kernel
->expects($this->once())
->method('getBundle')
@@ -418,7 +418,7 @@ EOF;
public function testLocateResourceOnDirectories()
{
$kernel = $this->getKernel(array('getBundle'));
$kernel = $this->getKernel(['getBundle']);
$kernel
->expects($this->exactly(2))
->method('getBundle')
@@ -434,7 +434,7 @@ EOF;
$kernel->locateResource('@FooBundle/Resources', __DIR__.'/Fixtures/Resources')
);
$kernel = $this->getKernel(array('getBundle'));
$kernel = $this->getKernel(['getBundle']);
$kernel
->expects($this->exactly(2))
->method('getBundle')
@@ -460,13 +460,13 @@ EOF;
$fooBundle = $this->getBundle(null, null, 'FooBundle', 'DuplicateName');
$barBundle = $this->getBundle(null, null, 'BarBundle', 'DuplicateName');
$kernel = $this->getKernel(array(), array($fooBundle, $barBundle));
$kernel = $this->getKernel([], [$fooBundle, $barBundle]);
$kernel->boot();
}
public function testTerminateReturnsSilentlyIfKernelIsNotBooted()
{
$kernel = $this->getKernel(array('getHttpKernel'));
$kernel = $this->getKernel(['getHttpKernel']);
$kernel->expects($this->never())
->method('getHttpKernel');
@@ -478,7 +478,7 @@ EOF;
// does not implement TerminableInterface
$httpKernel = new TestKernel();
$kernel = $this->getKernel(array('getHttpKernel'));
$kernel = $this->getKernel(['getHttpKernel']);
$kernel->expects($this->once())
->method('getHttpKernel')
->willReturn($httpKernel);
@@ -491,14 +491,14 @@ EOF;
// implements TerminableInterface
$httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel')
->disableOriginalConstructor()
->setMethods(array('terminate'))
->setMethods(['terminate'])
->getMock();
$httpKernelMock
->expects($this->once())
->method('terminate');
$kernel = $this->getKernel(array('getHttpKernel'));
$kernel = $this->getKernel(['getHttpKernel']);
$kernel->expects($this->exactly(2))
->method('getHttpKernel')
->will($this->returnValue($httpKernelMock));
@@ -571,7 +571,7 @@ EOF;
$container->addCompilerPass(new ResettableServicePass());
$container->register('one', ResettableService::class)
->setPublic(true)
->addTag('kernel.reset', array('method' => 'reset'));
->addTag('kernel.reset', ['method' => 'reset']);
$container->register('services_resetter', ServicesResetter::class)->setPublic(true);
}, $httpKernelMock, 'resetting');
@@ -595,7 +595,7 @@ EOF;
*/
public function testKernelStartTimeIsResetWhileBootingAlreadyBootedKernel()
{
$kernel = $this->getKernelForTest(array('initializeBundles'), true);
$kernel = $this->getKernelForTest(['initializeBundles'], true);
$kernel->boot();
$preReBoot = $kernel->getStartTime();
@@ -614,7 +614,7 @@ EOF;
{
$bundle = $this
->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')
->setMethods(array('getPath', 'getParent', 'getName'))
->setMethods(['getPath', 'getParent', 'getName'])
->disableOriginalConstructor()
;
@@ -653,14 +653,14 @@ EOF;
*
* @return Kernel
*/
protected function getKernel(array $methods = array(), array $bundles = array())
protected function getKernel(array $methods = [], array $bundles = [])
{
$methods[] = 'registerBundles';
$kernel = $this
->getMockBuilder('Symfony\Component\HttpKernel\Kernel')
->setMethods($methods)
->setConstructorArgs(array('test', false))
->setConstructorArgs(['test', false])
->getMockForAbstractClass()
;
$kernel->expects($this->any())
@@ -674,10 +674,10 @@ EOF;
return $kernel;
}
protected function getKernelForTest(array $methods = array(), $debug = false)
protected function getKernelForTest(array $methods = [], $debug = false)
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest')
->setConstructorArgs(array('test', $debug))
->setConstructorArgs(['test', $debug])
->setMethods($methods)
->getMock();
$p = new \ReflectionProperty($kernel, 'rootDir');
@@ -718,7 +718,7 @@ class CustomProjectDirKernel extends Kernel
public function registerBundles()
{
return array();
return [];
}
public function registerContainerConfiguration(LoaderInterface $loader)

View File

@@ -72,39 +72,39 @@ class LoggerTest extends TestCase
*/
public function testLogsAtAllLevels($level, $message)
{
$this->logger->{$level}($message, array('user' => 'Bob'));
$this->logger->log($level, $message, array('user' => 'Bob'));
$this->logger->{$level}($message, ['user' => 'Bob']);
$this->logger->log($level, $message, ['user' => 'Bob']);
$expected = array(
$expected = [
"[$level] message of level $level with context: Bob",
"[$level] message of level $level with context: Bob",
);
];
$this->assertLogsMatch($expected, $this->getLogs());
}
public function provideLevelsAndMessages()
{
return array(
LogLevel::EMERGENCY => array(LogLevel::EMERGENCY, 'message of level emergency with context: {user}'),
LogLevel::ALERT => array(LogLevel::ALERT, 'message of level alert with context: {user}'),
LogLevel::CRITICAL => array(LogLevel::CRITICAL, 'message of level critical with context: {user}'),
LogLevel::ERROR => array(LogLevel::ERROR, 'message of level error with context: {user}'),
LogLevel::WARNING => array(LogLevel::WARNING, 'message of level warning with context: {user}'),
LogLevel::NOTICE => array(LogLevel::NOTICE, 'message of level notice with context: {user}'),
LogLevel::INFO => array(LogLevel::INFO, 'message of level info with context: {user}'),
LogLevel::DEBUG => array(LogLevel::DEBUG, 'message of level debug with context: {user}'),
);
return [
LogLevel::EMERGENCY => [LogLevel::EMERGENCY, 'message of level emergency with context: {user}'],
LogLevel::ALERT => [LogLevel::ALERT, 'message of level alert with context: {user}'],
LogLevel::CRITICAL => [LogLevel::CRITICAL, 'message of level critical with context: {user}'],
LogLevel::ERROR => [LogLevel::ERROR, 'message of level error with context: {user}'],
LogLevel::WARNING => [LogLevel::WARNING, 'message of level warning with context: {user}'],
LogLevel::NOTICE => [LogLevel::NOTICE, 'message of level notice with context: {user}'],
LogLevel::INFO => [LogLevel::INFO, 'message of level info with context: {user}'],
LogLevel::DEBUG => [LogLevel::DEBUG, 'message of level debug with context: {user}'],
];
}
public function testLogLevelDisabled()
{
$this->logger = new Logger(LogLevel::INFO, $this->tmpFile);
$this->logger->debug('test', array('user' => 'Bob'));
$this->logger->log(LogLevel::DEBUG, 'test', array('user' => 'Bob'));
$this->logger->debug('test', ['user' => 'Bob']);
$this->logger->log(LogLevel::DEBUG, 'test', ['user' => 'Bob']);
// Will always be true, but asserts than an exception isn't thrown
$this->assertSame(array(), $this->getLogs());
$this->assertSame([], $this->getLogs());
}
/**
@@ -134,18 +134,18 @@ class LoggerTest extends TestCase
public function testContextReplacement()
{
$logger = $this->logger;
$logger->info('{Message {nothing} {user} {foo.bar} a}', array('user' => 'Bob', 'foo.bar' => 'Bar'));
$logger->info('{Message {nothing} {user} {foo.bar} a}', ['user' => 'Bob', 'foo.bar' => 'Bar']);
$expected = array('[info] {Message {nothing} Bob Bar a}');
$expected = ['[info] {Message {nothing} Bob Bar a}'];
$this->assertLogsMatch($expected, $this->getLogs());
}
public function testObjectCastToString()
{
if (method_exists($this, 'createPartialMock')) {
$dummy = $this->createPartialMock(DummyTest::class, array('__toString'));
$dummy = $this->createPartialMock(DummyTest::class, ['__toString']);
} else {
$dummy = $this->getMock(DummyTest::class, array('__toString'));
$dummy = $this->getMock(DummyTest::class, ['__toString']);
}
$dummy->expects($this->atLeastOnce())
->method('__toString')
@@ -153,54 +153,54 @@ class LoggerTest extends TestCase
$this->logger->warning($dummy);
$expected = array('[warning] DUMMY');
$expected = ['[warning] DUMMY'];
$this->assertLogsMatch($expected, $this->getLogs());
}
public function testContextCanContainAnything()
{
$context = array(
$context = [
'bool' => true,
'null' => null,
'string' => 'Foo',
'int' => 0,
'float' => 0.5,
'nested' => array('with object' => new DummyTest()),
'nested' => ['with object' => new DummyTest()],
'object' => new \DateTime(),
'resource' => fopen('php://memory', 'r'),
);
];
$this->logger->warning('Crazy context data', $context);
$expected = array('[warning] Crazy context data');
$expected = ['[warning] Crazy context data'];
$this->assertLogsMatch($expected, $this->getLogs());
}
public function testContextExceptionKeyCanBeExceptionOrOtherValues()
{
$logger = $this->logger;
$logger->warning('Random message', array('exception' => 'oops'));
$logger->critical('Uncaught Exception!', array('exception' => new \LogicException('Fail')));
$logger->warning('Random message', ['exception' => 'oops']);
$logger->critical('Uncaught Exception!', ['exception' => new \LogicException('Fail')]);
$expected = array(
$expected = [
'[warning] Random message',
'[critical] Uncaught Exception!',
);
];
$this->assertLogsMatch($expected, $this->getLogs());
}
public function testFormatter()
{
$this->logger = new Logger(LogLevel::DEBUG, $this->tmpFile, function ($level, $message, $context) {
return json_encode(array('level' => $level, 'message' => $message, 'context' => $context)).\PHP_EOL;
return json_encode(['level' => $level, 'message' => $message, 'context' => $context]).\PHP_EOL;
});
$this->logger->error('An error', array('foo' => 'bar'));
$this->logger->warning('A warning', array('baz' => 'bar'));
$this->assertSame(array(
$this->logger->error('An error', ['foo' => 'bar']);
$this->logger->warning('A warning', ['baz' => 'bar']);
$this->assertSame([
'{"level":"error","message":"An error","context":{"foo":"bar"}}',
'{"level":"warning","message":"A warning","context":{"baz":"bar"}}',
), $this->getLogs());
], $this->getLogs());
}
}

View File

@@ -29,59 +29,59 @@ class Logger implements LoggerInterface
public function clear()
{
$this->logs = array(
'emergency' => array(),
'alert' => array(),
'critical' => array(),
'error' => array(),
'warning' => array(),
'notice' => array(),
'info' => array(),
'debug' => array(),
);
$this->logs = [
'emergency' => [],
'alert' => [],
'critical' => [],
'error' => [],
'warning' => [],
'notice' => [],
'info' => [],
'debug' => [],
];
}
public function log($level, $message, array $context = array())
public function log($level, $message, array $context = [])
{
$this->logs[$level][] = $message;
}
public function emergency($message, array $context = array())
public function emergency($message, array $context = [])
{
$this->log('emergency', $message, $context);
}
public function alert($message, array $context = array())
public function alert($message, array $context = [])
{
$this->log('alert', $message, $context);
}
public function critical($message, array $context = array())
public function critical($message, array $context = [])
{
$this->log('critical', $message, $context);
}
public function error($message, array $context = array())
public function error($message, array $context = [])
{
$this->log('error', $message, $context);
}
public function warning($message, array $context = array())
public function warning($message, array $context = [])
{
$this->log('warning', $message, $context);
}
public function notice($message, array $context = array())
public function notice($message, array $context = [])
{
$this->log('notice', $message, $context);
}
public function info($message, array $context = array())
public function info($message, array $context = [])
{
$this->log('info', $message, $context);
}
public function debug($message, array $context = array())
public function debug($message, array $context = [])
{
$this->log('debug', $message, $context);
}

View File

@@ -226,7 +226,7 @@ class FileProfilerStorageTest extends TestCase
public function testRetrieveByMethodAndLimit()
{
foreach (array('POST', 'GET') as $method) {
foreach (['POST', 'GET'] as $method) {
for ($i = 0; $i < 5; ++$i) {
$profile = new Profile('token_'.$i.$method);
$profile->setMethod($method);
@@ -293,8 +293,8 @@ class FileProfilerStorageTest extends TestCase
$tokens = $this->storage->find('', '', 10, '');
$this->assertCount(2, $tokens);
$this->assertContains($tokens[0]['status_code'], array(200, 404));
$this->assertContains($tokens[1]['status_code'], array(200, 404));
$this->assertContains($tokens[0]['status_code'], [200, 404]);
$this->assertContains($tokens[1]['status_code'], [200, 404]);
}
public function testMultiRowIndexFile()

View File

@@ -44,7 +44,7 @@ class ProfilerTest extends TestCase
public function testReset()
{
$collector = $this->getMockBuilder(DataCollectorInterface::class)
->setMethods(array('collect', 'getName', 'reset'))
->setMethods(['collect', 'getName', 'reset'])
->getMock();
$collector->expects($this->any())->method('getName')->willReturn('mock');
$collector->expects($this->once())->method('reset');

View File

@@ -27,12 +27,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)