composer update

This commit is contained in:
2019-06-23 10:14:30 +00:00
parent a56db5ea2b
commit ec4506ebf4
790 changed files with 35767 additions and 7663 deletions
@@ -30,7 +30,7 @@ class FileLocatorTest extends TestCase
$kernel
->expects($this->never())
->method('locateResource');
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('LogicException');
$this->expectException('LogicException');
$locator->locate('/some/path');
}
@@ -0,0 +1,117 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ServiceLocator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver\NotTaggedControllerValueResolver;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
class NotTaggedControllerValueResolverTest extends TestCase
{
public function testDoSupportWhenControllerDoNotExists()
{
$resolver = new NotTaggedControllerValueResolver(new ServiceLocator([]));
$argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null);
$request = $this->requestWithAttributes(['_controller' => 'my_controller']);
$this->assertTrue($resolver->supports($request, $argument));
}
public function testDoNotSupportWhenControllerExists()
{
$resolver = new NotTaggedControllerValueResolver(new ServiceLocator([
'App\\Controller\\Mine::method' => function () {
return new ServiceLocator([
'dummy' => function () {
return new \stdClass();
},
]);
},
]));
$argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null);
$request = $this->requestWithAttributes(['_controller' => 'App\\Controller\\Mine::method']);
$this->assertFalse($resolver->supports($request, $argument));
}
public function testDoNotSupportEmptyController()
{
$resolver = new NotTaggedControllerValueResolver(new ServiceLocator([]));
$argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null);
$request = $this->requestWithAttributes(['_controller' => '']);
$this->assertFalse($resolver->supports($request, $argument));
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Could not resolve argument $dummy of "App\Controller\Mine::method()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?
*/
public function testController()
{
$resolver = new NotTaggedControllerValueResolver(new ServiceLocator([]));
$argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null);
$request = $this->requestWithAttributes(['_controller' => 'App\\Controller\\Mine::method']);
$this->assertTrue($resolver->supports($request, $argument));
$resolver->resolve($request, $argument);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Could not resolve argument $dummy of "App\Controller\Mine::method()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?
*/
public function testControllerWithATrailingBackSlash()
{
$resolver = new NotTaggedControllerValueResolver(new ServiceLocator([]));
$argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null);
$request = $this->requestWithAttributes(['_controller' => '\\App\\Controller\\Mine::method']);
$this->assertTrue($resolver->supports($request, $argument));
$resolver->resolve($request, $argument);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Could not resolve argument $dummy of "App\Controller\Mine::method()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?
*/
public function testControllerWithMethodNameStartUppercase()
{
$resolver = new NotTaggedControllerValueResolver(new ServiceLocator([]));
$argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null);
$request = $this->requestWithAttributes(['_controller' => 'App\\Controller\\Mine::Method']);
$this->assertTrue($resolver->supports($request, $argument));
$resolver->resolve($request, $argument);
}
/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
* @expectedExceptionMessage Could not resolve argument $dummy of "App\Controller\Mine::method()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?
*/
public function testControllerNameIsAnArray()
{
$resolver = new NotTaggedControllerValueResolver(new ServiceLocator([]));
$argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null);
$request = $this->requestWithAttributes(['_controller' => ['App\\Controller\\Mine', 'method']]);
$this->assertTrue($resolver->supports($request, $argument));
$resolver->resolve($request, $argument);
}
private function requestWithAttributes(array $attributes)
{
$request = Request::create('/');
foreach ($attributes as $name => $value) {
$request->attributes->set($name, $value);
}
return $request;
}
}
@@ -52,9 +52,9 @@ class DumpDataCollectorTest extends TestCase
];
$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());
$this->assertStringMatchesFormat('%a;a:%d:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', serialize($collector));
$this->assertSame(0, $collector->getDumpsCount());
$this->assertSame('a:2:{i:0;b:0;i:1;s:5:"UTF-8";}', $collector->serialize());
$this->assertSame("O:60:\"Symfony\Component\HttpKernel\DataCollector\DumpDataCollector\":1:{s:7:\"\0*\0data\";a:2:{i:0;b:0;i:1;s:5:\"UTF-8\";}}", serialize($collector));
}
public function testDumpWithServerConnection()
@@ -72,7 +72,7 @@ class DumpDataCollectorTest extends TestCase
ob_start();
$collector->collect(new Request(), new Response());
$this->assertEmpty(ob_get_clean());
$this->assertStringMatchesFormat('a:3:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', $collector->serialize());
$this->assertStringMatchesFormat('%a;a:%d:{i:0;a:5:{s:4:"data";%c:39:"Symfony\Component\VarDumper\Cloner\Data":%a', serialize($collector));
}
public function testCollectDefault()
@@ -90,7 +90,7 @@ class DumpDataCollectorTest extends TestCase
$this->assertSame("DumpDataCollectorTest.php on line {$line}:\n123\n", $output);
$this->assertSame(1, $collector->getDumpsCount());
$collector->serialize();
serialize($collector);
}
public function testCollectHtml()
@@ -118,7 +118,7 @@ EOTXT;
$this->assertSame($xOutput, trim($output));
$this->assertSame(1, $collector->getDumpsCount());
$collector->serialize();
serialize($collector);
}
public function testFlush()
@@ -22,8 +22,8 @@ use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -206,7 +206,7 @@ class RequestDataCollectorTest extends TestCase
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$c = new RequestDataCollector();
$c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $this->createResponse()));
$c->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $this->createResponse()));
$this->assertTrue($request->attributes->get('_redirected'));
}
@@ -290,7 +290,7 @@ class RequestDataCollectorTest extends TestCase
{
$resolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock();
$httpKernel = new HttpKernel(new EventDispatcher(), $resolver, null, $this->getMockBuilder(ArgumentResolverInterface::class)->getMock());
$event = new FilterControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST);
$event = new ControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST);
$collector->onKernelController($event);
}
@@ -333,4 +333,58 @@ class RequestDataCollectorTest extends TestCase
throw new \InvalidArgumentException(sprintf('Cookie named "%s" is not in response', $name));
}
/**
* @dataProvider provideJsonContentTypes
*/
public function testIsJson($contentType, $expected)
{
$response = $this->createResponse();
$request = $this->createRequest();
$request->headers->set('Content-Type', $contentType);
$c = new RequestDataCollector();
$c->collect($request, $response);
$this->assertSame($expected, $c->isJsonRequest());
}
public function provideJsonContentTypes()
{
return [
['text/csv', false],
['application/json', true],
['application/JSON', true],
['application/hal+json', true],
['application/xml+json', true],
['application/xml', false],
['', false],
];
}
/**
* @dataProvider providePrettyJson
*/
public function testGetPrettyJsonValidity($content, $expected)
{
$response = $this->createResponse();
$request = Request::create('/', 'POST', [], [], [], [], $content);
$c = new RequestDataCollector();
$c->collect($request, $response);
$this->assertSame($expected, $c->getPrettyJson());
}
public function providePrettyJson()
{
return [
['null', 'null'],
['{ "foo": "bar" }', '{
"foo": "bar"
}'],
['{ "abc" }', null],
['', null],
];
}
}
@@ -34,18 +34,6 @@ class FileLinkFormatterTest extends TestCase
$this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
}
public function testWhenFileLinkFormatAndRequest()
{
$file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
$requestStack = new RequestStack();
$request = new Request();
$requestStack->push($request);
$sut = new FileLinkFormatter('debug://open?url=file://%f&line=%l', $requestStack, __DIR__, '/_profiler/open?file=%f&line=%l#line%l');
$this->assertSame("debug://open?url=file://$file&line=3", $sut->format($file, 3));
}
public function testWhenNoFileLinkFormatAndRequest()
{
$file = __DIR__.\DIRECTORY_SEPARATOR.'file.php';
@@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\Tests\Debug;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
@@ -89,10 +90,10 @@ class TraceableEventDispatcherTest extends TestCase
$called2 = true;
});
});
$dispatcher->dispatch('my-event');
$dispatcher->dispatch(new Event(), 'my-event');
$this->assertTrue($called1);
$this->assertFalse($called2);
$dispatcher->dispatch('my-event');
$dispatcher->dispatch(new Event(), 'my-event');
$this->assertTrue($called2);
}
@@ -104,7 +105,7 @@ class TraceableEventDispatcherTest extends TestCase
};
$eventDispatcher->addListener('foo', $listener1);
$eventDispatcher->addListener('foo', function () {});
$eventDispatcher->dispatch('foo');
$eventDispatcher->dispatch(new Event(), 'foo');
$this->assertCount(1, $eventDispatcher->getListeners('foo'), 'expected listener1 to be removed');
}
@@ -376,6 +376,19 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase
$this->assertInstanceOf(ServiceClosureArgument::class, $locator['someArg']);
$this->assertEquals(new Reference('parent'), $locator['someArg']->getValues()[0]);
}
public function testNotTaggedControllerServiceReceivesLocatorArgument()
{
$container = new ContainerBuilder();
$resolver = $container->register('argument_resolver.not_tagged_controller')->addArgument([]);
$pass = new RegisterControllerArgumentLocatorsPass();
$pass->process($container);
$locatorArgument = $container->getDefinition('argument_resolver.not_tagged_controller')->getArgument(0);
$this->assertInstanceOf(Reference::class, $locatorArgument);
}
}
class RegisterTestController
@@ -0,0 +1,59 @@
<?php
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\RegisterLocaleAwareServicesPass;
use Symfony\Component\HttpKernel\EventListener\LocaleAwareListener;
use Symfony\Contracts\Translation\LocaleAwareInterface;
class RegisterLocaleAwareServicesPassTest extends TestCase
{
public function testCompilerPass()
{
$container = new ContainerBuilder();
$container->register('locale_aware_listener', LocaleAwareListener::class)
->setPublic(true)
->setArguments([null, null]);
$container->register('some_locale_aware_service', LocaleAwareInterface::class)
->setPublic(true)
->addTag('kernel.locale_aware');
$container->register('another_locale_aware_service', LocaleAwareInterface::class)
->setPublic(true)
->addTag('kernel.locale_aware');
$container->addCompilerPass(new RegisterLocaleAwareServicesPass());
$container->compile();
$this->assertEquals(
[
new IteratorArgument([
0 => new Reference('some_locale_aware_service'),
1 => new Reference('another_locale_aware_service'),
]),
null,
],
$container->getDefinition('locale_aware_listener')->getArguments()
);
}
public function testListenerUnregisteredWhenNoLocaleAwareServices()
{
$container = new ContainerBuilder();
$container->register('locale_aware_listener', LocaleAwareListener::class)
->setPublic(true)
->setArguments([null, null]);
$container->addCompilerPass(new RegisterLocaleAwareServicesPass());
$container->compile();
$this->assertFalse($container->hasDefinition('locale_aware_listener'));
}
}
@@ -0,0 +1,17 @@
<?php
namespace Symfony\Component\HttpKernel\Tests\Event;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Tests\TestHttpKernel;
class ControllerArgumentsEventTest extends TestCase
{
public function testControllerArgumentsEvent()
{
$filterController = new ControllerArgumentsEvent(new TestHttpKernel(), function () {}, ['test'], new Request(), 1);
$this->assertEquals($filterController->getArguments(), ['test']);
}
}
@@ -13,14 +13,14 @@ namespace Symfony\Component\HttpKernel\Tests\Event;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Tests\TestHttpKernel;
class GetResponseForExceptionEventTest extends TestCase
class ExceptionEventTest extends TestCase
{
public function testAllowSuccessfulResponseIsFalseByDefault()
{
$event = new GetResponseForExceptionEvent(new TestHttpKernel(), new Request(), 1, new \Exception());
$event = new ExceptionEvent(new TestHttpKernel(), new Request(), 1, new \Exception());
$this->assertFalse($event->isAllowingCustomResponseCode());
}
@@ -1,17 +0,0 @@
<?php
namespace Symfony\Component\HttpKernel\Tests\Event;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Tests\TestHttpKernel;
class FilterControllerArgumentsEventTest extends TestCase
{
public function testFilterControllerArgumentsEvent()
{
$filterController = new FilterControllerArgumentsEvent(new TestHttpKernel(), function () {}, ['test'], new Request(), 1);
$this->assertEquals($filterController->getArguments(), ['test']);
}
}
@@ -13,6 +13,7 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener;
use Symfony\Component\HttpKernel\KernelEvents;
@@ -46,7 +47,7 @@ class AddRequestFormatsListenerTest extends TestCase
public function testRegisteredEvent()
{
$this->assertEquals(
[KernelEvents::REQUEST => ['onKernelRequest', 1]],
[KernelEvents::REQUEST => ['onKernelRequest', 100]],
AddRequestFormatsListener::getSubscribedEvents()
);
}
@@ -54,7 +55,7 @@ class AddRequestFormatsListenerTest extends TestCase
public function testSetAdditionalFormats()
{
$request = $this->getRequestMock();
$event = $this->getGetResponseEventMock($request);
$event = $this->getRequestEventMock($request);
$request->expects($this->once())
->method('setFormat')
@@ -68,10 +69,10 @@ class AddRequestFormatsListenerTest extends TestCase
return $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
}
protected function getGetResponseEventMock(Request $request)
protected function getRequestEventMock(Request $request)
{
$event = $this
->getMockBuilder('Symfony\Component\HttpKernel\Event\GetResponseEvent')
->getMockBuilder(RequestEvent::class)
->disableOriginalConstructor()
->getMock();
@@ -112,7 +112,7 @@ class DebugHandlersListenerTest extends TestCase
set_error_handler([$eHandler, 'handleError']);
set_exception_handler([$eHandler, 'handleException']);
try {
$dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
$dispatcher->dispatch($event, ConsoleEvents::COMMAND);
} catch (\Exception $exception) {
}
restore_exception_handler();
@@ -0,0 +1,47 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpKernel\Tests\EventListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\EventListener\DisallowRobotsIndexingListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelInterface;
class DisallowRobotsIndexingListenerTest extends TestCase
{
/**
* @dataProvider provideResponses
*/
public function testInvoke(?string $expected, Response $response): void
{
$listener = new DisallowRobotsIndexingListener();
$event = new ResponseEvent($this->createMock(HttpKernelInterface::class), $this->createMock(Request::class), KernelInterface::MASTER_REQUEST, $response);
$listener->onResponse($event);
$this->assertSame($expected, $response->headers->get('X-Robots-Tag'), 'Header doesn\'t match expectations');
}
public function provideResponses(): iterable
{
yield 'No header' => ['noindex', new Response()];
yield 'Header already set' => [
'something else',
new Response('', 204, ['X-Robots-Tag' => 'something else']),
];
}
}
@@ -15,8 +15,8 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
@@ -103,8 +103,8 @@ class ExceptionListenerTest extends TestCase
$request = new Request();
$exception = new \Exception('foo');
$event = new GetResponseForExceptionEvent(new TestKernel(), $request, HttpKernelInterface::MASTER_REQUEST, $exception);
$event2 = new GetResponseForExceptionEvent(new TestKernelThatThrowsException(), $request, HttpKernelInterface::MASTER_REQUEST, $exception);
$event = new ExceptionEvent(new TestKernel(), $request, HttpKernelInterface::MASTER_REQUEST, $exception);
$event2 = new ExceptionEvent(new TestKernelThatThrowsException(), $request, HttpKernelInterface::MASTER_REQUEST, $exception);
return [
[$event, $event2],
@@ -123,7 +123,7 @@ class ExceptionListenerTest extends TestCase
$request = Request::create('/');
$request->setRequestFormat('xml');
$event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
$event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
$listener->onKernelException($event);
$response = $event->getResponse();
@@ -143,14 +143,14 @@ class ExceptionListenerTest extends TestCase
$dispatcher->addSubscriber($listener);
$request = Request::create('/');
$event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
$dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
$event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
$dispatcher->dispatch($event, KernelEvents::EXCEPTION);
$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);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$event = new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher->dispatch($event, KernelEvents::RESPONSE);
$this->assertFalse($response->headers->has('content-security-policy'), 'CSP header has been removed');
$this->assertFalse($dispatcher->hasListeners(KernelEvents::RESPONSE), 'CSP removal listener has been removed');
@@ -166,7 +166,7 @@ class ExceptionListenerTest extends TestCase
return $controller();
}));
$request = Request::create('/');
$event = new GetResponseForExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
$event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo'));
$listener->onKernelException($event);
$this->assertNull($event->getResponse());
@@ -13,7 +13,7 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\EventListener\FragmentListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\UriSigner;
@@ -25,7 +25,7 @@ class FragmentListenerTest extends TestCase
$request = Request::create('http://example.com/foo?_path=foo%3Dbar%26_controller%3Dfoo');
$listener = new FragmentListener(new UriSigner('foo'));
$event = $this->createGetResponseEvent($request);
$event = $this->createRequestEvent($request);
$expected = $request->attributes->all();
@@ -41,7 +41,7 @@ class FragmentListenerTest extends TestCase
$request->attributes->set('_controller', 'bar');
$listener = new FragmentListener(new UriSigner('foo'));
$event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST);
$event = $this->createRequestEvent($request, HttpKernelInterface::SUB_REQUEST);
$expected = $request->attributes->all();
@@ -58,7 +58,7 @@ class FragmentListenerTest extends TestCase
$request = Request::create('http://example.com/_fragment', 'POST');
$listener = new FragmentListener(new UriSigner('foo'));
$event = $this->createGetResponseEvent($request);
$event = $this->createRequestEvent($request);
$listener->onKernelRequest($event);
}
@@ -71,7 +71,7 @@ class FragmentListenerTest extends TestCase
$request = Request::create('http://example.com/_fragment', 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']);
$listener = new FragmentListener(new UriSigner('foo'));
$event = $this->createGetResponseEvent($request);
$event = $this->createRequestEvent($request);
$listener->onKernelRequest($event);
}
@@ -82,7 +82,7 @@ class FragmentListenerTest extends TestCase
$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);
$event = $this->createRequestEvent($request);
$listener->onKernelRequest($event);
@@ -95,7 +95,7 @@ class FragmentListenerTest extends TestCase
$request = Request::create('http://example.com/_fragment?_path=foo%3Dbar%26_controller%3Dfoo');
$listener = new FragmentListener(new UriSigner('foo'));
$event = $this->createGetResponseEvent($request, HttpKernelInterface::SUB_REQUEST);
$event = $this->createRequestEvent($request, HttpKernelInterface::SUB_REQUEST);
$listener->onKernelRequest($event);
@@ -108,15 +108,15 @@ class FragmentListenerTest extends TestCase
$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);
$event = $this->createRequestEvent($request);
$listener->onKernelRequest($event);
$this->assertFalse($request->query->has('_path'));
}
private function createGetResponseEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST)
private function createRequestEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST)
{
return new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, $requestType);
return new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, $requestType);
}
}
@@ -0,0 +1,119 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\HttpKernel\Tests\EventListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\EventListener\LocaleAwareListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Contracts\Translation\LocaleAwareInterface;
class LocaleAwareListenerTest extends TestCase
{
private $listener;
private $localeAwareService;
private $requestStack;
protected function setUp()
{
$this->localeAwareService = $this->getMockBuilder(LocaleAwareInterface::class)->getMock();
$this->requestStack = new RequestStack();
$this->listener = new LocaleAwareListener(new \ArrayIterator([$this->localeAwareService]), $this->requestStack);
}
public function testLocaleIsSetInOnKernelRequest()
{
$this->localeAwareService
->expects($this->once())
->method('setLocale')
->with($this->equalTo('fr'));
$event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
}
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest()
{
$this->localeAwareService
->expects($this->at(0))
->method('setLocale')
->will($this->throwException(new \InvalidArgumentException()));
$this->localeAwareService
->expects($this->at(1))
->method('setLocale')
->with($this->equalTo('en'));
$event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
}
public function testLocaleIsSetInOnKernelFinishRequestWhenParentRequestExists()
{
$this->localeAwareService
->expects($this->once())
->method('setLocale')
->with($this->equalTo('fr'));
$this->requestStack->push($this->createRequest('fr'));
$this->requestStack->push($subRequest = $this->createRequest('de'));
$event = new FinishRequestEvent($this->createHttpKernel(), $subRequest, HttpKernelInterface::SUB_REQUEST);
$this->listener->onKernelFinishRequest($event);
}
public function testLocaleIsSetToDefaultOnKernelFinishRequestWhenParentRequestDoesNotExist()
{
$this->localeAwareService
->expects($this->once())
->method('setLocale')
->with($this->equalTo('en'));
$this->requestStack->push($subRequest = $this->createRequest('de'));
$event = new FinishRequestEvent($this->createHttpKernel(), $subRequest, HttpKernelInterface::SUB_REQUEST);
$this->listener->onKernelFinishRequest($event);
}
public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest()
{
$this->localeAwareService
->expects($this->at(0))
->method('setLocale')
->will($this->throwException(new \InvalidArgumentException()));
$this->localeAwareService
->expects($this->at(1))
->method('setLocale')
->with($this->equalTo('en'));
$this->requestStack->push($this->createRequest('fr'));
$this->requestStack->push($subRequest = $this->createRequest('de'));
$event = new FinishRequestEvent($this->createHttpKernel(), $subRequest, HttpKernelInterface::SUB_REQUEST);
$this->listener->onKernelFinishRequest($event);
}
private function createHttpKernel()
{
return $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
}
private function createRequest($locale)
{
$request = new Request();
$request->setLocale($locale);
return $request;
}
}
@@ -12,10 +12,12 @@
namespace Symfony\Component\HttpKernel\Tests\EventListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\EventListener\LocaleListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
class LocaleListenerTest extends TestCase
{
@@ -26,12 +28,28 @@ class LocaleListenerTest extends TestCase
$this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->disableOriginalConstructor()->getMock();
}
public function testDefaultLocaleWithoutSession()
public function testIsAnEventSubscriber()
{
$this->assertInstanceOf(EventSubscriberInterface::class, new LocaleListener($this->requestStack));
}
public function testRegisteredEvent()
{
$this->assertEquals(
[
KernelEvents::REQUEST => [['setDefaultLocale', 100], ['onKernelRequest', 16]],
KernelEvents::FINISH_REQUEST => [['onKernelFinishRequest', 0]],
],
LocaleListener::getSubscribedEvents()
);
}
public function testDefaultLocale()
{
$listener = new LocaleListener($this->requestStack, 'fr');
$event = $this->getEvent($request = Request::create('/'));
$listener->onKernelRequest($event);
$listener->setDefaultLocale($event);
$this->assertEquals('fr', $request->getLocale());
}
@@ -95,8 +113,8 @@ class LocaleListenerTest extends TestCase
$this->assertEquals('de', $request->getLocale());
}
private function getEvent(Request $request)
private function getEvent(Request $request): RequestEvent
{
return new GetResponseEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
return new RequestEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST);
}
}
@@ -13,9 +13,9 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\EventListener\ProfilerListener;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\Kernel;
@@ -59,12 +59,12 @@ class ProfilerListenerTest extends TestCase
$listener = new ProfilerListener($profiler, $requestStack, null, $onlyException);
// master request
$listener->onKernelResponse(new FilterResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response));
$listener->onKernelResponse(new ResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response));
// sub request
$listener->onKernelException(new GetResponseForExceptionEvent($kernel, $subRequest, Kernel::SUB_REQUEST, new HttpException(404)));
$listener->onKernelResponse(new FilterResponseEvent($kernel, $subRequest, Kernel::SUB_REQUEST, $response));
$listener->onKernelException(new ExceptionEvent($kernel, $subRequest, Kernel::SUB_REQUEST, new HttpException(404)));
$listener->onKernelResponse(new ResponseEvent($kernel, $subRequest, Kernel::SUB_REQUEST, $response));
$listener->onKernelTerminate(new PostResponseEvent($kernel, $masterRequest, $response));
$listener->onKernelTerminate(new TerminateEvent($kernel, $masterRequest, $response));
}
}
@@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\EventListener\ResponseListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
@@ -45,8 +45,8 @@ class ResponseListenerTest extends TestCase
{
$response = new Response('foo');
$event = new FilterResponseEvent($this->kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$event = new ResponseEvent($this->kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
$this->dispatcher->dispatch($event, KernelEvents::RESPONSE);
$this->assertEquals('', $event->getResponse()->headers->get('content-type'));
}
@@ -58,8 +58,8 @@ class ResponseListenerTest extends TestCase
$response = new Response('foo');
$event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$event = new ResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch($event, KernelEvents::RESPONSE);
$this->assertEquals('ISO-8859-15', $response->getCharset());
}
@@ -72,8 +72,8 @@ class ResponseListenerTest extends TestCase
$response = new Response('foo');
$response->setCharset('ISO-8859-1');
$event = new FilterResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$event = new ResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch($event, KernelEvents::RESPONSE);
$this->assertEquals('ISO-8859-1', $response->getCharset());
}
@@ -87,8 +87,8 @@ class ResponseListenerTest extends TestCase
$request = Request::create('/');
$request->setRequestFormat('application/json');
$event = new FilterResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$event = new ResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response);
$this->dispatcher->dispatch($event, KernelEvents::RESPONSE);
$this->assertEquals('ISO-8859-15', $response->getCharset());
}
@@ -18,7 +18,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ArgumentResolver;
use Symfony\Component\HttpKernel\Controller\ControllerResolver;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
use Symfony\Component\HttpKernel\EventListener\RouterListener;
use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener;
@@ -52,7 +52,7 @@ class RouterListenerTest extends TestCase
->will($this->returnValue($context));
$listener = new RouterListener($urlMatcher, $this->requestStack);
$event = $this->createGetResponseEventForUri($uri);
$event = $this->createRequestEventForUri($uri);
$listener->onKernelRequest($event);
$this->assertEquals($expectedHttpPort, $context->getHttpPort());
@@ -70,13 +70,13 @@ class RouterListenerTest extends TestCase
];
}
private function createGetResponseEventForUri(string $uri): GetResponseEvent
private function createRequestEventForUri(string $uri): RequestEvent
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$request = Request::create($uri);
$request->attributes->set('_controller', null); // Prevents going in to routing process
return new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
return new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
}
/**
@@ -89,9 +89,9 @@ class RouterListenerTest extends TestCase
public function testRequestMatcher()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$request = Request::create('http://localhost/');
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
$requestMatcher->expects($this->once())
@@ -105,9 +105,9 @@ class RouterListenerTest extends TestCase
public function testSubRequestWithDifferentMethod()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$request = Request::create('http://localhost/', 'post');
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
$requestMatcher->expects($this->any())
@@ -121,9 +121,9 @@ class RouterListenerTest extends TestCase
$listener->onKernelRequest($event);
// sub-request with another HTTP method
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$request = Request::create('http://localhost/', 'get');
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST);
$event = new RequestEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST);
$listener->onKernelRequest($event);
@@ -145,11 +145,11 @@ class RouterListenerTest extends TestCase
->method('info')
->with($this->equalTo($log), $this->equalTo($parameters));
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$request = Request::create('http://localhost/');
$listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext(), $logger);
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
$listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
}
public function getLoggingParameterData()
@@ -209,9 +209,9 @@ class RouterListenerTest extends TestCase
*/
public function testRequestWithBadHost()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$request = Request::create('http://bad host %22/');
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock();
@@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\EventListener\SaveSessionListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -27,7 +27,7 @@ class SaveSessionListenerTest extends TestCase
public function testOnlyTriggeredOnMasterRequest()
{
$listener = new SaveSessionListener();
$event = $this->getMockBuilder(FilterResponseEvent::class)->disableOriginalConstructor()->getMock();
$event = $this->getMockBuilder(ResponseEvent::class)->disableOriginalConstructor()->getMock();
$event->expects($this->once())->method('isMasterRequest')->willReturn(false);
$event->expects($this->never())->method('getRequest');
@@ -47,6 +47,6 @@ class SaveSessionListenerTest extends TestCase
$request = new Request();
$request->setSession($session);
$response = new Response();
$listener->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
$listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
}
}
@@ -19,9 +19,9 @@ 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;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\EventListener\AbstractSessionListener;
use Symfony\Component\HttpKernel\EventListener\SessionListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -31,7 +31,7 @@ class SessionListenerTest extends TestCase
public function testOnlyTriggeredOnMasterRequest()
{
$listener = $this->getMockForAbstractClass(AbstractSessionListener::class);
$event = $this->getMockBuilder(GetResponseEvent::class)->disableOriginalConstructor()->getMock();
$event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock();
$event->expects($this->once())->method('isMasterRequest')->willReturn(false);
$event->expects($this->never())->method('getRequest');
@@ -57,7 +57,7 @@ class SessionListenerTest extends TestCase
$request = new Request();
$listener = new SessionListener($container);
$event = $this->getMockBuilder(GetResponseEvent::class)->disableOriginalConstructor()->getMock();
$event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock();
$event->expects($this->once())->method('isMasterRequest')->willReturn(true);
$event->expects($this->once())->method('getRequest')->willReturn($request);
@@ -79,10 +79,10 @@ class SessionListenerTest extends TestCase
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock();
$request = new Request();
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
$listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
$response = new Response();
$listener->onKernelResponse(new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
$listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
@@ -102,12 +102,12 @@ class SessionListenerTest extends TestCase
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock();
$request = new Request();
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
$listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
$response = new Response();
$response->setSharedMaxAge(60);
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
$listener->onKernelResponse(new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
$listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
@@ -128,7 +128,7 @@ class SessionListenerTest extends TestCase
]);
$listener = new SessionListener($container);
$listener->onKernelResponse(new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
$listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
@@ -151,20 +151,20 @@ class SessionListenerTest extends TestCase
$request = new Request();
$response = new Response();
$response->setCache(['public' => true, 'max_age' => '30']);
$listener->onKernelRequest(new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
$listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
$this->assertTrue($request->hasSession());
$subRequest = clone $request;
$this->assertSame($request->getSession(), $subRequest->getSession());
$listener->onKernelRequest(new GetResponseEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST));
$listener->onKernelResponse(new FilterResponseEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST, $response));
$listener->onKernelRequest(new RequestEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST));
$listener->onKernelResponse(new ResponseEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST, $response));
$listener->onFinishRequest(new FinishRequestEvent($kernel, $subRequest, HttpKernelInterface::MASTER_REQUEST));
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
$this->assertSame('30', $response->headers->getCacheControlDirective('max-age'));
$listener->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
$listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));
$this->assertTrue($response->headers->hasCacheControlDirective('private'));
$this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate'));
@@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\EventListener\SurrogateListener;
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -31,8 +31,8 @@ class SurrogateListenerTest extends TestCase
$listener = new SurrogateListener(new Esi());
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::SUB_REQUEST, $response);
$dispatcher->dispatch($event, KernelEvents::RESPONSE);
$this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control'));
}
@@ -45,8 +45,8 @@ class SurrogateListenerTest extends TestCase
$listener = new SurrogateListener(new Esi());
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher->dispatch($event, KernelEvents::RESPONSE);
$this->assertEquals('content="ESI/1.0"', $event->getResponse()->headers->get('Surrogate-Control'));
}
@@ -59,8 +59,8 @@ class SurrogateListenerTest extends TestCase
$listener = new SurrogateListener(new Esi());
$dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']);
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher->dispatch(KernelEvents::RESPONSE, $event);
$event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response);
$dispatcher->dispatch($event, KernelEvents::RESPONSE);
$this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control'));
}
@@ -15,8 +15,8 @@ use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\EventListener\SessionListener;
use Symfony\Component\HttpKernel\EventListener\TestSessionListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -95,9 +95,9 @@ class TestSessionListenerTest extends TestCase
$this->sessionIsEmpty();
$this->fixSessionId('456');
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']);
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
$response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST);
@@ -114,9 +114,9 @@ class TestSessionListenerTest extends TestCase
$this->sessionIsEmpty();
$this->fixSessionId('456');
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']);
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
$response = new Response('', 200, ['Set-Cookie' => $existing]);
@@ -145,8 +145,8 @@ class TestSessionListenerTest extends TestCase
public function testDoesNotThrowIfRequestDoesNotHaveASession()
{
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$event = new FilterResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response());
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response());
$this->listener->onKernelResponse($event);
@@ -157,8 +157,8 @@ class TestSessionListenerTest extends TestCase
{
$request->setSession($this->session);
$response = $response ?: new Response();
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock();
$event = new FilterResponseEvent($kernel, $request, $type, $response);
$kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock();
$event = new ResponseEvent($kernel, $request, $type, $response);
$this->listener->onKernelResponse($event);
@@ -14,11 +14,14 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\EventListener\TranslatorListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Contracts\Translation\LocaleAwareInterface;
/**
* @group legacy
*/
class TranslatorListenerTest extends TestCase
{
private $listener;
@@ -39,7 +42,7 @@ class TranslatorListenerTest extends TestCase
->method('setLocale')
->with($this->equalTo('fr'));
$event = new GetResponseEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
}
@@ -54,7 +57,7 @@ class TranslatorListenerTest extends TestCase
->method('setLocale')
->with($this->equalTo('en'));
$event = new GetResponseEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST);
$this->listener->onKernelRequest($event);
}
@@ -14,7 +14,7 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener;
use PHPUnit\Framework\TestCase;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;
@@ -41,8 +41,8 @@ class ValidateRequestListenerTest extends TestCase
$request->headers->set('X_FORWARDED_FOR', '3.3.3.3');
$dispatcher->addListener(KernelEvents::REQUEST, [new ValidateRequestListener(), 'onKernelRequest']);
$event = new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST);
$dispatcher->dispatch(KernelEvents::REQUEST, $event);
$dispatcher->dispatch($event, KernelEvents::REQUEST);
}
}
@@ -6,8 +6,8 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class AccessDeniedHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new AccessDeniedHttpException();
return new AccessDeniedHttpException($message, $previous, $code, $headers);
}
}
@@ -6,8 +6,8 @@ use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
class BadRequestHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new BadRequestHttpException();
return new BadRequestHttpException($message, $previous, $code, $headers);
}
}
@@ -6,8 +6,8 @@ use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
class ConflictHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new ConflictHttpException();
return new ConflictHttpException($message, $previous, $code, $headers);
}
}
@@ -6,8 +6,8 @@ use Symfony\Component\HttpKernel\Exception\GoneHttpException;
class GoneHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new GoneHttpException();
return new GoneHttpException($message, $previous, $code, $headers);
}
}
@@ -46,8 +46,16 @@ class HttpExceptionTest extends TestCase
$this->assertSame($headers, $exception->getHeaders());
}
protected function createException()
public function testThrowableIsAllowedForPrevious()
{
return new HttpException(200);
$previous = new class('Error of PHP 7+') extends \Error {
};
$exception = $this->createException(null, $previous);
$this->assertSame($previous, $exception->getPrevious());
}
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new HttpException(200, $message, $previous, $headers, $code);
}
}
@@ -6,8 +6,8 @@ use Symfony\Component\HttpKernel\Exception\LengthRequiredHttpException;
class LengthRequiredHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new LengthRequiredHttpException();
return new LengthRequiredHttpException($message, $previous, $code, $headers);
}
}
@@ -34,4 +34,9 @@ class MethodNotAllowedHttpExceptionTest extends HttpExceptionTest
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new MethodNotAllowedHttpException(['get'], $message, $previous, $code, $headers);
}
}
@@ -6,8 +6,8 @@ use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;
class NotAcceptableHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new NotAcceptableHttpException();
return new NotAcceptableHttpException($message, $previous, $code, $headers);
}
}
@@ -6,8 +6,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class NotFoundHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new NotFoundHttpException();
return new NotFoundHttpException($message, $previous, $code, $headers);
}
}
@@ -6,8 +6,8 @@ use Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException;
class PreconditionFailedHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new PreconditionFailedHttpException();
return new PreconditionFailedHttpException($message, $previous, $code, $headers);
}
}
@@ -6,8 +6,8 @@ use Symfony\Component\HttpKernel\Exception\PreconditionRequiredHttpException;
class PreconditionRequiredHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new PreconditionRequiredHttpException();
return new PreconditionRequiredHttpException($message, $previous, $code, $headers);
}
}
@@ -35,8 +35,8 @@ class ServiceUnavailableHttpExceptionTest extends HttpExceptionTest
$this->assertSame($headers, $exception->getHeaders());
}
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new ServiceUnavailableHttpException();
return new ServiceUnavailableHttpException(null, $message, $previous, $code, $headers);
}
}
@@ -35,8 +35,8 @@ class TooManyRequestsHttpExceptionTest extends HttpExceptionTest
$this->assertSame($headers, $exception->getHeaders());
}
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new TooManyRequestsHttpException();
return new TooManyRequestsHttpException(null, $message, $previous, $code, $headers);
}
}
@@ -34,4 +34,9 @@ class UnauthorizedHttpExceptionTest extends HttpExceptionTest
$exception->setHeaders($headers);
$this->assertSame($headers, $exception->getHeaders());
}
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new UnauthorizedHttpException('Challenge', $message, $previous, $code, $headers);
}
}
@@ -6,8 +6,8 @@ use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
class UnprocessableEntityHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new UnprocessableEntityHttpException();
return new UnprocessableEntityHttpException($message, $previous, $code, $headers);
}
}
@@ -6,8 +6,8 @@ use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException;
class UnsupportedMediaTypeHttpExceptionTest extends HttpExceptionTest
{
protected function createException()
protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = [])
{
return new UnsupportedMediaTypeHttpException();
return new UnsupportedMediaTypeHttpException($message, $previous, $code, $headers);
}
}
+2 -2
View File
@@ -11,9 +11,9 @@
namespace Symfony\Component\HttpKernel\Tests\Fixtures;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpKernel\HttpKernelBrowser;
class TestClient extends Client
class TestClient extends HttpKernelBrowser
{
protected function getScript($request)
{
@@ -16,6 +16,8 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer;
use Symfony\Component\HttpKernel\UriSigner;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
class HIncludeFragmentRendererTest extends TestCase
{
@@ -74,7 +76,17 @@ class HIncludeFragmentRendererTest extends TestCase
$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()
public function testRenderWithTwigAndDefaultText()
{
$twig = new Environment($loader = new ArrayLoader());
$strategy = new HIncludeFragmentRenderer($twig);
$this->assertEquals('<hx:include src="/foo">loading...</hx:include>', $strategy->render('/foo', Request::create('/'), ['default' => 'loading...'])->getContent());
}
/**
* @group legacy
*/
public function testRenderWithDefaultTextLegacy()
{
$engine = $this->getMockBuilder('Symfony\\Component\\Templating\\EngineInterface')->getMock();
$engine->expects($this->once())
@@ -86,17 +98,4 @@ class HIncludeFragmentRendererTest extends TestCase
$strategy = new HIncludeFragmentRenderer($engine);
$this->assertEquals('<hx:include src="/foo">default</hx:include>', $strategy->render('/foo', Request::create('/'), ['default' => 'default'])->getContent());
}
public function testRenderWithEngineAndDefaultText()
{
$engine = $this->getMockBuilder('Symfony\\Component\\Templating\\EngineInterface')->getMock();
$engine->expects($this->once())
->method('exists')
->with('loading...')
->willThrowException(new \RuntimeException());
// only default
$strategy = new HIncludeFragmentRenderer($engine);
$this->assertEquals('<hx:include src="/foo">loading...</hx:include>', $strategy->render('/foo', Request::create('/'), ['default' => 'loading...'])->getContent());
}
}
@@ -17,9 +17,11 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ControllerReference;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
class InlineFragmentRendererTest extends TestCase
{
@@ -72,7 +74,7 @@ class InlineFragmentRendererTest extends TestCase
*/
public function testRenderExceptionNoIgnoreErrors()
{
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock();
$dispatcher->expects($this->never())->method('dispatch');
$strategy = new InlineFragmentRenderer($this->getKernel($this->throwException(new \RuntimeException('foo'))), $dispatcher);
@@ -82,12 +84,16 @@ class InlineFragmentRendererTest extends TestCase
public function testRenderExceptionIgnoreErrors()
{
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
$dispatcher->expects($this->once())->method('dispatch')->with(KernelEvents::EXCEPTION);
$exception = new \RuntimeException('foo');
$kernel = $this->getKernel($this->throwException($exception));
$request = Request::create('/');
$expectedEvent = new ExceptionEvent($kernel, $request, $kernel::SUB_REQUEST, $exception);
$dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock();
$dispatcher->expects($this->once())->method('dispatch')->with($expectedEvent, KernelEvents::EXCEPTION);
$strategy = new InlineFragmentRenderer($this->getKernel($this->throwException(new \RuntimeException('foo'))), $dispatcher);
$strategy = new InlineFragmentRenderer($kernel, $dispatcher);
$this->assertEmpty($strategy->render('/', Request::create('/'), ['ignore_errors' => true])->getContent());
$this->assertEmpty($strategy->render('/', $request, ['ignore_errors' => true])->getContent());
}
public function testRenderExceptionIgnoreErrorsWithAlt()
@@ -1508,6 +1508,44 @@ class HttpCacheTest extends HttpCacheTestCase
// Surrogate request
$cache->handle($request, HttpKernelInterface::SUB_REQUEST);
}
public function testTraceHeaderNameCanBeChanged()
{
$this->cacheConfig['trace_header'] = 'X-My-Header';
$this->setNextResponse();
$this->request('GET', '/');
$this->assertTrue($this->response->headers->has('X-My-Header'));
}
public function testTraceLevelDefaultsToFullIfDebug()
{
$this->setNextResponse();
$this->request('GET', '/');
$this->assertTrue($this->response->headers->has('X-Symfony-Cache'));
$this->assertEquals('GET /: miss', $this->response->headers->get('X-Symfony-Cache'));
}
public function testTraceLevelDefaultsToNoneIfNotDebug()
{
$this->cacheConfig['debug'] = false;
$this->setNextResponse();
$this->request('GET', '/');
$this->assertFalse($this->response->headers->has('X-Symfony-Cache'));
}
public function testTraceLevelShort()
{
$this->cacheConfig['trace_level'] = 'short';
$this->setNextResponse();
$this->request('GET', '/');
$this->assertTrue($this->response->headers->has('X-Symfony-Cache'));
$this->assertEquals('miss', $this->response->headers->get('X-Symfony-Cache'));
}
}
class TestKernel implements HttpKernelInterface
@@ -122,7 +122,9 @@ class HttpCacheTestCase extends TestCase
$this->store = new Store(sys_get_temp_dir().'/http_cache');
$this->cacheConfig['debug'] = true;
if (!isset($this->cacheConfig['debug'])) {
$this->cacheConfig['debug'] = true;
}
$this->esi = $esi ? new Esi() : null;
$this->cache = new HttpCache($this->kernel, $this->store, $this->esi, $this->cacheConfig);
@@ -16,17 +16,17 @@ use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpKernel\HttpKernelBrowser;
use Symfony\Component\HttpKernel\Tests\Fixtures\TestClient;
/**
* @group time-sensitive
*/
class ClientTest extends TestCase
class HttpKernelBrowserTest extends TestCase
{
public function testDoRequest()
{
$client = new Client(new TestHttpKernel());
$client = new HttpKernelBrowser(new TestHttpKernel());
$client->request('GET', '/');
$this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
@@ -54,7 +54,7 @@ class ClientTest extends TestCase
public function testFilterResponseConvertsCookies()
{
$client = new Client(new TestHttpKernel());
$client = new HttpKernelBrowser(new TestHttpKernel());
$r = new \ReflectionObject($client);
$m = $r->getMethod('filterResponse');
@@ -75,7 +75,7 @@ class ClientTest extends TestCase
public function testFilterResponseSupportsStreamedResponses()
{
$client = new Client(new TestHttpKernel());
$client = new HttpKernelBrowser(new TestHttpKernel());
$r = new \ReflectionObject($client);
$m = $r->getMethod('filterResponse');
@@ -97,7 +97,7 @@ class ClientTest extends TestCase
@unlink($target);
$kernel = new TestHttpKernel();
$client = new Client($kernel);
$client = new HttpKernelBrowser($kernel);
$files = [
['tmp_name' => $source, 'name' => 'original', 'type' => 'mime/original', 'size' => null, 'error' => UPLOAD_ERR_OK],
@@ -128,7 +128,7 @@ class ClientTest extends TestCase
public function testUploadedFileWhenNoFileSelected()
{
$kernel = new TestHttpKernel();
$client = new Client($kernel);
$client = new HttpKernelBrowser($kernel);
$file = ['tmp_name' => '', 'name' => '', 'type' => '', 'size' => 0, 'error' => UPLOAD_ERR_NO_FILE];
@@ -145,7 +145,7 @@ class ClientTest extends TestCase
$source = tempnam(sys_get_temp_dir(), 'source');
$kernel = new TestHttpKernel();
$client = new Client($kernel);
$client = new HttpKernelBrowser($kernel);
$file = $this
->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
+9 -12
View File
@@ -20,8 +20,6 @@ use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerArgumentsEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\Exception\ControllerDoesNotReturnResponseException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
@@ -128,7 +126,7 @@ class HttpKernelTest extends TestCase
public function testHandleWhenAnExceptionIsHandledWithASpecificStatusCode($expectedStatusCode)
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::EXCEPTION, function (GetResponseForExceptionEvent $event) use ($expectedStatusCode) {
$dispatcher->addListener(KernelEvents::EXCEPTION, function ($event) use ($expectedStatusCode) {
$event->allowCustomResponseCode();
$event->setResponse(new Response('', $expectedStatusCode));
});
@@ -215,20 +213,19 @@ class HttpKernelTest extends TestCase
public function testHandleWhenTheControllerDoesNotReturnAResponse()
{
$dispatcher = new EventDispatcher();
$kernel = $this->getHttpKernel($dispatcher, function () { return 'foo'; });
$kernel = $this->getHttpKernel($dispatcher, function () {});
try {
$kernel->handle(new Request());
$this->fail('The kernel should throw an exception.');
} catch (ControllerDoesNotReturnResponseException $e) {
$first = $e->getTrace()[0];
// `file` index the array starting at 0, and __FILE__ starts at 1
$line = file($first['file'])[$first['line'] - 2];
$this->assertContains('// call controller', $line);
}
$first = $e->getTrace()[0];
// `file` index the array starting at 0, and __FILE__ starts at 1
$line = file($first['file'])[$first['line'] - 2];
$this->assertContains('// call controller', $line);
}
public function testHandleWhenTheControllerDoesNotReturnAResponseButAViewIsRegistered()
@@ -257,7 +254,7 @@ class HttpKernelTest extends TestCase
public function testHandleAllowChangingControllerArguments()
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::CONTROLLER_ARGUMENTS, function (FilterControllerArgumentsEvent $event) {
$dispatcher->addListener(KernelEvents::CONTROLLER_ARGUMENTS, function ($event) {
$event->setArguments(['foo']);
});
@@ -269,7 +266,7 @@ class HttpKernelTest extends TestCase
public function testHandleAllowChangingControllerAndArguments()
{
$dispatcher = new EventDispatcher();
$dispatcher->addListener(KernelEvents::CONTROLLER_ARGUMENTS, function (FilterControllerArgumentsEvent $event) {
$dispatcher->addListener(KernelEvents::CONTROLLER_ARGUMENTS, function ($event) {
$oldController = $event->getController();
$oldArguments = $event->getArguments();
+16 -3
View File
@@ -64,6 +64,20 @@ class KernelTest extends TestCase
$this->assertNull($clone->getContainer());
}
/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The environment "test.env" contains invalid characters, it can only contain characters allowed in PHP class names.
*/
public function testClassNameValidityGetter()
{
// We check the classname that will be generated by using a $env that
// contains invalid characters.
$env = 'test.env';
$kernel = new KernelForTest($env, false);
$kernel->boot();
}
public function testInitializeContainerClearsOldContainers()
{
$fs = new Filesystem();
@@ -330,9 +344,8 @@ EOF;
$env = 'test_env';
$debug = true;
$kernel = new KernelForTest($env, $debug);
$expected = serialize([$env, $debug]);
$this->assertEquals($expected, $kernel->serialize());
$expected = "O:57:\"Symfony\Component\HttpKernel\Tests\Fixtures\KernelForTest\":2:{s:14:\"\0*\0environment\";s:8:\"test_env\";s:8:\"\0*\0debug\";b:1;}";
$this->assertEquals($expected, serialize($kernel));
}
/**
+1 -1
View File
@@ -34,7 +34,7 @@ class LoggerTest extends TestCase
protected function setUp()
{
$this->tmpFile = sys_get_temp_dir().\DIRECTORY_SEPARATOR.'log';
$this->tmpFile = tempnam(sys_get_temp_dir(), 'log');
$this->logger = new Logger(LogLevel::DEBUG, $this->tmpFile);
}