From e0975503d31549bec32bac6b8f18cb4ed3849c7b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 16 May 2020 14:09:30 +0200 Subject: [PATCH 001/396] updated version to 5.2 --- Kernel.php | 10 +++++----- composer.json | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Kernel.php b/Kernel.php index b66dba0d3b..14b200bf32 100644 --- a/Kernel.php +++ b/Kernel.php @@ -73,15 +73,15 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.1.0-DEV'; - const VERSION_ID = 50100; + const VERSION = '5.2.0-DEV'; + const VERSION_ID = 50200; const MAJOR_VERSION = 5; - const MINOR_VERSION = 1; + const MINOR_VERSION = 2; const RELEASE_VERSION = 0; const EXTRA_VERSION = 'DEV'; - const END_OF_MAINTENANCE = '01/2021'; - const END_OF_LIFE = '01/2021'; + const END_OF_MAINTENANCE = '07/2021'; + const END_OF_LIFE = '07/2021'; public function __construct(string $environment, bool $debug) { diff --git a/composer.json b/composer.json index 2e8ab7af93..3850996958 100644 --- a/composer.json +++ b/composer.json @@ -77,7 +77,7 @@ "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "5.1-dev" + "dev-master": "5.2-dev" } } } From 9807fb16e95ffe3f230177cf9da4927f8b6d1c16 Mon Sep 17 00:00:00 2001 From: Vladimir Reznichenko Date: Sat, 2 May 2020 20:09:15 +0200 Subject: [PATCH 002/396] SCA: file_exists -> is_dir|is_file in foundation and kernel --- CacheWarmer/CacheWarmerAggregate.php | 2 +- DataCollector/LoggerDataCollector.php | 4 ++-- HttpCache/Store.php | 12 ++++++------ Kernel.php | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CacheWarmer/CacheWarmerAggregate.php b/CacheWarmer/CacheWarmerAggregate.php index f89b1cd7a0..cd3f0108a6 100644 --- a/CacheWarmer/CacheWarmerAggregate.php +++ b/CacheWarmer/CacheWarmerAggregate.php @@ -101,7 +101,7 @@ public function warmUp(string $cacheDir) if ($collectDeprecations) { restore_error_handler(); - if (file_exists($this->deprecationLogsFilepath)) { + if (is_file($this->deprecationLogsFilepath)) { $previousLogs = unserialize(file_get_contents($this->deprecationLogsFilepath)); $collectedLogs = array_merge($previousLogs, $collectedLogs); } diff --git a/DataCollector/LoggerDataCollector.php b/DataCollector/LoggerDataCollector.php index 34c6dc4297..732e7aa277 100644 --- a/DataCollector/LoggerDataCollector.php +++ b/DataCollector/LoggerDataCollector.php @@ -122,7 +122,7 @@ public function getName() private function getContainerDeprecationLogs(): array { - if (null === $this->containerPathPrefix || !file_exists($file = $this->containerPathPrefix.'Deprecations.log')) { + if (null === $this->containerPathPrefix || !is_file($file = $this->containerPathPrefix.'Deprecations.log')) { return []; } @@ -148,7 +148,7 @@ private function getContainerDeprecationLogs(): array private function getContainerCompilerLogs(string $compilerLogsFilepath = null): array { - if (!file_exists($compilerLogsFilepath)) { + if (!is_file($compilerLogsFilepath)) { return []; } diff --git a/HttpCache/Store.php b/HttpCache/Store.php index b7953e1303..3611116ed6 100644 --- a/HttpCache/Store.php +++ b/HttpCache/Store.php @@ -34,7 +34,7 @@ class Store implements StoreInterface public function __construct(string $root) { $this->root = $root; - if (!file_exists($this->root) && !@mkdir($this->root, 0777, true) && !is_dir($this->root)) { + if (!is_dir($this->root) && !@mkdir($this->root, 0777, true) && !is_dir($this->root)) { throw new \RuntimeException(sprintf('Unable to create the store directory (%s).', $this->root)); } $this->keyCache = new \SplObjectStorage(); @@ -66,7 +66,7 @@ public function lock(Request $request) if (!isset($this->locks[$key])) { $path = $this->getPath($key); - if (!file_exists(\dirname($path)) && false === @mkdir(\dirname($path), 0777, true) && !is_dir(\dirname($path))) { + if (!is_dir(\dirname($path)) && false === @mkdir(\dirname($path), 0777, true) && !is_dir(\dirname($path))) { return $path; } $h = fopen($path, 'cb'); @@ -110,7 +110,7 @@ public function isLocked(Request $request) return true; // shortcut if lock held by this process } - if (!file_exists($path = $this->getPath($key))) { + if (!is_file($path = $this->getPath($key))) { return false; } @@ -322,7 +322,7 @@ private function doPurge(string $url): bool unset($this->locks[$key]); } - if (file_exists($path = $this->getPath($key))) { + if (is_file($path = $this->getPath($key))) { unlink($path); return true; @@ -338,7 +338,7 @@ private function load(string $key): ?string { $path = $this->getPath($key); - return file_exists($path) && false !== ($contents = file_get_contents($path)) ? $contents : null; + return is_file($path) && false !== ($contents = file_get_contents($path)) ? $contents : null; } /** @@ -359,7 +359,7 @@ private function save(string $key, string $data): bool return false; } } else { - if (!file_exists(\dirname($path)) && false === @mkdir(\dirname($path), 0777, true) && !is_dir(\dirname($path))) { + if (!is_dir(\dirname($path)) && false === @mkdir(\dirname($path), 0777, true) && !is_dir(\dirname($path))) { return false; } diff --git a/Kernel.php b/Kernel.php index 45e00e4e8e..4660646d3a 100644 --- a/Kernel.php +++ b/Kernel.php @@ -722,7 +722,7 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container @chmod($dir.$file, 0666 & ~umask()); } $legacyFile = \dirname($dir.key($content)).'.legacy'; - if (file_exists($legacyFile)) { + if (is_file($legacyFile)) { @unlink($legacyFile); } From a2036cdf6395a32814b9baa8bbc67c5ea58cfeb0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 19 Jun 2020 12:58:59 +0200 Subject: [PATCH 003/396] [FrameworkBundle] allow enabling the HTTP cache using semantic configuration --- CHANGELOG.md | 5 ++++ Kernel.php | 41 ++++++++++++++++++++++---------- Tests/Fixtures/KernelForTest.php | 18 ++++++++++++++ Tests/KernelTest.php | 14 +++++------ 4 files changed, 57 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b74c4b8757..6bf20c948f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +5.2.0 +----- + + * made the public `http_cache` service handle requests when available + 5.1.0 ----- diff --git a/Kernel.php b/Kernel.php index 36f5dc53dd..cf4329fc16 100644 --- a/Kernel.php +++ b/Kernel.php @@ -115,20 +115,10 @@ public function boot() return; } - if ($this->debug) { - $this->startTime = microtime(true); - } - if ($this->debug && !isset($_ENV['SHELL_VERBOSITY']) && !isset($_SERVER['SHELL_VERBOSITY'])) { - putenv('SHELL_VERBOSITY=3'); - $_ENV['SHELL_VERBOSITY'] = 3; - $_SERVER['SHELL_VERBOSITY'] = 3; - } - // init bundles - $this->initializeBundles(); - - // init container - $this->initializeContainer(); + if (null === $this->container) { + $this->preBoot(); + } foreach ($this->getBundles() as $bundle) { $bundle->setContainer($this->container); @@ -188,6 +178,14 @@ public function shutdown() */ public function handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true) { + if (!$this->booted) { + $container = $this->container ?? $this->preBoot(); + + if ($container->has('http_cache')) { + return $container->get('http_cache')->handle($request, $type, $catch); + } + } + $this->boot(); ++$this->requestStackSize; $this->resetServices = true; @@ -752,6 +750,23 @@ protected function getContainerLoader(ContainerInterface $container) return new DelegatingLoader($resolver); } + private function preBoot(): ContainerInterface + { + if ($this->debug) { + $this->startTime = microtime(true); + } + if ($this->debug && !isset($_ENV['SHELL_VERBOSITY']) && !isset($_SERVER['SHELL_VERBOSITY'])) { + putenv('SHELL_VERBOSITY=3'); + $_ENV['SHELL_VERBOSITY'] = 3; + $_SERVER['SHELL_VERBOSITY'] = 3; + } + + $this->initializeBundles(); + $this->initializeContainer(); + + return $this->container; + } + /** * Removes comments from a PHP source string. * diff --git a/Tests/Fixtures/KernelForTest.php b/Tests/Fixtures/KernelForTest.php index f3b1951b83..33b167074e 100644 --- a/Tests/Fixtures/KernelForTest.php +++ b/Tests/Fixtures/KernelForTest.php @@ -12,11 +12,20 @@ namespace Symfony\Component\HttpKernel\Tests\Fixtures; use Symfony\Component\Config\Loader\LoaderInterface; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\Kernel; class KernelForTest extends Kernel { + private $fakeContainer; + + public function __construct(string $environment, bool $debug, bool $fakeContainer = true) + { + parent::__construct($environment, $debug); + $this->fakeContainer = $fakeContainer; + } + public function getBundleMap() { return $this->bundleMap; @@ -40,4 +49,13 @@ public function getProjectDir(): string { return __DIR__; } + + protected function initializeContainer() + { + if ($this->fakeContainer) { + $this->container = new ContainerBuilder(); + } else { + parent::initializeContainer(); + } + } } diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index f86c0ccd51..a5d0de8f89 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -69,7 +69,7 @@ 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 = new KernelForTest($env, false, false); $kernel->boot(); } @@ -101,11 +101,9 @@ public function testInitializeContainerClearsOldContainers() public function testBootInitializesBundlesAndContainer() { - $kernel = $this->getKernel(['initializeBundles', 'initializeContainer']); + $kernel = $this->getKernel(['initializeBundles']); $kernel->expects($this->once()) ->method('initializeBundles'); - $kernel->expects($this->once()) - ->method('initializeContainer'); $kernel->boot(); } @@ -116,7 +114,7 @@ public function testBootSetsTheContainerToTheBundles() $bundle->expects($this->once()) ->method('setContainer'); - $kernel = $this->getKernel(['initializeBundles', 'initializeContainer', 'getBundles']); + $kernel = $this->getKernel(['initializeBundles', 'getBundles']); $kernel->expects($this->once()) ->method('getBundles') ->willReturn([$bundle]); @@ -127,7 +125,7 @@ public function testBootSetsTheContainerToTheBundles() public function testBootSetsTheBootedFlagToTrue() { // use test kernel to access isBooted() - $kernel = $this->getKernel(['initializeBundles', 'initializeContainer']); + $kernel = $this->getKernel(['initializeBundles']); $kernel->boot(); $this->assertTrue($kernel->isBooted()); @@ -135,7 +133,7 @@ public function testBootSetsTheBootedFlagToTrue() public function testClassCacheIsNotLoadedByDefault() { - $kernel = $this->getKernel(['initializeBundles', 'initializeContainer', 'doLoadClassCache']); + $kernel = $this->getKernel(['initializeBundles', 'doLoadClassCache']); $kernel->expects($this->never()) ->method('doLoadClassCache'); @@ -144,7 +142,7 @@ public function testClassCacheIsNotLoadedByDefault() public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce() { - $kernel = $this->getKernel(['initializeBundles', 'initializeContainer']); + $kernel = $this->getKernel(['initializeBundles']); $kernel->expects($this->once()) ->method('initializeBundles'); From fac9cbfb843d37a739882ffe82c8d301ce04334e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 19 Jun 2020 15:56:57 +0200 Subject: [PATCH 004/396] [FrameworkBundle] allow configuring trusted proxies using semantic configuration --- CHANGELOG.md | 2 ++ Kernel.php | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bf20c948f..19f8d9f3bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ CHANGELOG ----- * made the public `http_cache` service handle requests when available + * allowed enabling trusted hosts and proxies using new `kernel.trusted_hosts`, + `kernel.trusted_proxies` and `kernel.trusted_headers` parameters 5.1.0 ----- diff --git a/Kernel.php b/Kernel.php index cf4329fc16..8f7ff96808 100644 --- a/Kernel.php +++ b/Kernel.php @@ -764,7 +764,17 @@ private function preBoot(): ContainerInterface $this->initializeBundles(); $this->initializeContainer(); - return $this->container; + $container = $this->container; + + if ($container->hasParameter('kernel.trusted_hosts') && $trustedHosts = $container->getParameter('kernel.trusted_hosts')) { + Request::setTrustedHosts($trustedHosts); + } + + if ($container->hasParameter('kernel.trusted_proxies') && $container->hasParameter('kernel.trusted_headers') && $trustedProxies = $container->getParameter('kernel.trusted_proxies')) { + Request::setTrustedProxies(\is_array($trustedProxies) ? $trustedProxies : array_map('trim', explode(',', $trustedProxies)), $container->getParameter('kernel.trusted_headers')); + } + + return $container; } /** From 4d628574efe36d7c3702082a9ead7647695a6278 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 16 Jun 2020 01:07:23 +0200 Subject: [PATCH 005/396] Move event alias mappings to their components. --- KernelEvents.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/KernelEvents.php b/KernelEvents.php index 0e1c9083e5..848990cb9a 100644 --- a/KernelEvents.php +++ b/KernelEvents.php @@ -11,6 +11,15 @@ namespace Symfony\Component\HttpKernel; +use Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent; +use Symfony\Component\HttpKernel\Event\ControllerEvent; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; +use Symfony\Component\HttpKernel\Event\FinishRequestEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; +use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\HttpKernel\Event\TerminateEvent; +use Symfony\Component\HttpKernel\Event\ViewEvent; + /** * Contains all events thrown in the HttpKernel component. * @@ -100,4 +109,20 @@ final class KernelEvents * @Event("Symfony\Component\HttpKernel\Event\TerminateEvent") */ const TERMINATE = 'kernel.terminate'; + + /** + * Event aliases. + * + * These aliases can be consumed by RegisterListenersPass. + */ + const ALIASES = [ + ControllerArgumentsEvent::class => self::CONTROLLER_ARGUMENTS, + ControllerEvent::class => self::CONTROLLER, + ResponseEvent::class => self::RESPONSE, + FinishRequestEvent::class => self::FINISH_REQUEST, + RequestEvent::class => self::REQUEST, + ViewEvent::class => self::VIEW, + ExceptionEvent::class => self::EXCEPTION, + TerminateEvent::class => self::TERMINATE, + ]; } From 890b37cb498eb031935b25bc7fc8c0767082b8bf Mon Sep 17 00:00:00 2001 From: Mathias Arlaud Date: Tue, 25 Feb 2020 16:40:39 +0100 Subject: [PATCH 006/396] Add session profiling --- CHANGELOG.md | 1 + DataCollector/RequestDataCollector.php | 52 +++++++++++++++- EventListener/AbstractSessionListener.php | 4 ++ .../RequestDataCollectorTest.php | 62 +++++++++++++++++++ Tests/EventListener/SessionListenerTest.php | 13 +++- 5 files changed, 129 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19f8d9f3bd..b5024cf0f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ CHANGELOG 5.2.0 ----- + * added session usage * made the public `http_cache` service handle requests when available * allowed enabling trusted hosts and proxies using new `kernel.trusted_hosts`, `kernel.trusted_proxies` and `kernel.trusted_headers` parameters diff --git a/DataCollector/RequestDataCollector.php b/DataCollector/RequestDataCollector.php index b92518d806..3b4063b4a9 100644 --- a/DataCollector/RequestDataCollector.php +++ b/DataCollector/RequestDataCollector.php @@ -15,7 +15,10 @@ use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Session\SessionBagInterface; +use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; @@ -28,10 +31,13 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInterface, LateDataCollectorInterface { protected $controllers; + private $sessionUsages = []; + private $requestStack; - public function __construct() + public function __construct(?RequestStack $requestStack = null) { $this->controllers = new \SplObjectStorage(); + $this->requestStack = $requestStack; } /** @@ -105,6 +111,8 @@ public function collect(Request $request, Response $response, \Throwable $except 'response_cookies' => $responseCookies, 'session_metadata' => $sessionMetadata, 'session_attributes' => $sessionAttributes, + 'session_usages' => array_values($this->sessionUsages), + 'stateless_check' => $this->requestStack && $this->requestStack->getMasterRequest()->attributes->get('_stateless', false), 'flashes' => $flashes, 'path_info' => $request->getPathInfo(), 'controller' => 'n/a', @@ -175,6 +183,7 @@ public function reset() { $this->data = []; $this->controllers = new \SplObjectStorage(); + $this->sessionUsages = []; } public function getMethod() @@ -242,6 +251,16 @@ public function getSessionAttributes() return $this->data['session_attributes']->getValue(); } + public function getStatelessCheck() + { + return $this->data['stateless_check']; + } + + public function getSessionUsages() + { + return $this->data['session_usages']; + } + public function getFlashes() { return $this->data['flashes']->getValue(); @@ -382,6 +401,37 @@ public function getName() return 'request'; } + public function collectSessionUsage(): void + { + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); + + $traceEndIndex = \count($trace) - 1; + for ($i = $traceEndIndex; $i > 0; --$i) { + if (null !== ($class = $trace[$i]['class'] ?? null) && (is_subclass_of($class, SessionInterface::class) || is_subclass_of($class, SessionBagInterface::class))) { + $traceEndIndex = $i; + break; + } + } + + if ((\count($trace) - 1) === $traceEndIndex) { + return; + } + + // Remove part of the backtrace that belongs to session only + array_splice($trace, 0, $traceEndIndex); + + // Merge identical backtraces generated by internal call reports + $name = sprintf('%s:%s', $trace[1]['class'] ?? $trace[0]['file'], $trace[0]['line']); + if (!\array_key_exists($name, $this->sessionUsages)) { + $this->sessionUsages[$name] = [ + 'name' => $name, + 'file' => $trace[0]['file'], + 'line' => $trace[0]['line'], + 'trace' => $trace, + ]; + } + } + /** * Parse a controller. * diff --git a/EventListener/AbstractSessionListener.php b/EventListener/AbstractSessionListener.php index 1fe3264f7d..0208e8dec5 100644 --- a/EventListener/AbstractSessionListener.php +++ b/EventListener/AbstractSessionListener.php @@ -152,6 +152,10 @@ public function onSessionUsage(): void return; } + if ($this->container && $this->container->has('session_collector')) { + $this->container->get('session_collector')(); + } + if (!$requestStack = $this->container && $this->container->has('request_stack') ? $this->container->get('request_stack') : null) { return; } diff --git a/Tests/DataCollector/RequestDataCollectorTest.php b/Tests/DataCollector/RequestDataCollectorTest.php index 5753dc88da..b62f765068 100644 --- a/Tests/DataCollector/RequestDataCollectorTest.php +++ b/Tests/DataCollector/RequestDataCollectorTest.php @@ -17,8 +17,11 @@ use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\RedirectResponse; 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\SessionBagInterface; +use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; @@ -248,6 +251,65 @@ public function testItCollectsTheRedirectionAndClearTheCookie() $this->assertNull($cookie->getValue()); } + public function testItCollectsTheSessionTraceProperly() + { + $collector = new RequestDataCollector(); + $request = $this->createRequest(); + + // RequestDataCollectorTest doesn't implement SessionInterface or SessionBagInterface, therefore should do nothing. + $collector->collectSessionUsage(); + + $collector->collect($request, $this->createResponse()); + $this->assertSame([], $collector->getSessionUsages()); + + $collector->reset(); + + $session = $this->createMock(SessionInterface::class); + $session->method('getMetadataBag')->willReturnCallback(static function () use ($collector) { + $collector->collectSessionUsage(); + }); + $session->getMetadataBag(); + + $collector->collect($request, $this->createResponse()); + $collector->lateCollect(); + + $usages = $collector->getSessionUsages(); + + $this->assertCount(1, $usages); + $this->assertSame(__FILE__, $usages[0]['file']); + $this->assertSame(__LINE__ - 9, $line = $usages[0]['line']); + + $trace = $usages[0]['trace']; + $this->assertSame('getMetadataBag', $trace[0]['function']); + $this->assertSame(self::class, $class = $trace[1]['class']); + + $this->assertSame(sprintf('%s:%s', $class, $line), $usages[0]['name']); + } + + public function testStatelessCheck() + { + $requestStack = new RequestStack(); + $request = $this->createRequest(); + $requestStack->push($request); + + $collector = new RequestDataCollector($requestStack); + $collector->collect($request, $response = $this->createResponse()); + $collector->lateCollect(); + + $this->assertFalse($collector->getStatelessCheck()); + + $requestStack = new RequestStack(); + $request = $this->createRequest(); + $request->attributes->set('_stateless', true); + $requestStack->push($request); + + $collector = new RequestDataCollector($requestStack); + $collector->collect($request, $response = $this->createResponse()); + $collector->lateCollect(); + + $this->assertTrue($collector->getStatelessCheck()); + } + protected function createRequest($routeParams = ['name' => 'foo']) { $request = Request::create('http://test.com/foo?bar=baz'); diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index 8df2ce5169..36183d3c13 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -20,6 +20,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; +use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; @@ -260,9 +261,13 @@ public function testSessionUsageCallbackWhenDebugAndStateless() $requestStack->push($request); $requestStack->push(new Request()); + $collector = $this->createMock(RequestDataCollector::class); + $collector->expects($this->once())->method('collectSessionUsage'); + $container = new Container(); $container->set('initialized_session', $session); $container->set('request_stack', $requestStack); + $container->set('session_collector', \Closure::fromCallable([$collector, 'collectSessionUsage'])); $this->expectException(UnexpectedSessionUsageException::class); (new SessionListener($container, true))->onSessionUsage(); @@ -277,12 +282,16 @@ public function testSessionUsageCallbackWhenNoDebug() $request = new Request(); $request->attributes->set('_stateless', true); - $requestStack = $this->getMockBuilder(RequestStack::class)->getMock(); - $requestStack->expects($this->never())->method('getMasterRequest')->willReturn($request); + $requestStack = new RequestStack(); + $requestStack->push($request); + + $collector = $this->createMock(RequestDataCollector::class); + $collector->expects($this->never())->method('collectSessionUsage'); $container = new Container(); $container->set('initialized_session', $session); $container->set('request_stack', $requestStack); + $container->set('session_collector', $collector); (new SessionListener($container))->onSessionUsage(); } From f465ee5fa487dd8622f7c57a8116a40bcfe3a52e Mon Sep 17 00:00:00 2001 From: efelo Date: Fri, 26 Jun 2020 21:31:13 +0200 Subject: [PATCH 007/396] [HttpKernel] added password hiding in request data collector raw content The password was already hidden in POST parameters, but still remained visible in raw content [HttpKernel] added password hiding in request data collector raw content The password was already hidden in POST parameters, but still remained visible in raw content [HttpKernel] added password hiding in request data collector raw content The password was already hidden in POST parameters, but still remained visible in raw content --- CHANGELOG.md | 2 ++ DataCollector/RequestDataCollector.php | 5 ++++- .../RequestDataCollectorTest.php | 21 +++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5024cf0f0..f597c6ab0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ CHANGELOG * made the public `http_cache` service handle requests when available * allowed enabling trusted hosts and proxies using new `kernel.trusted_hosts`, `kernel.trusted_proxies` and `kernel.trusted_headers` parameters + * content of request parameter `_password` is now also hidden + in the request profiler raw content section 5.1.0 ----- diff --git a/DataCollector/RequestDataCollector.php b/DataCollector/RequestDataCollector.php index 3b4063b4a9..b5e3c38d2b 100644 --- a/DataCollector/RequestDataCollector.php +++ b/DataCollector/RequestDataCollector.php @@ -95,7 +95,6 @@ public function collect(Request $request, Response $response, \Throwable $except $this->data = [ 'method' => $request->getMethod(), 'format' => $request->getRequestFormat(), - 'content' => $content, 'content_type' => $response->headers->get('Content-Type', 'text/html'), 'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '', 'status_code' => $statusCode, @@ -129,9 +128,13 @@ public function collect(Request $request, Response $response, \Throwable $except } if (isset($this->data['request_request']['_password'])) { + $encodedPassword = rawurlencode($this->data['request_request']['_password']); + $content = str_replace('_password='.$encodedPassword, '_password=******', $content); $this->data['request_request']['_password'] = '******'; } + $this->data['content'] = $content; + foreach ($this->data as $key => $value) { if (!\is_array($value)) { continue; diff --git a/Tests/DataCollector/RequestDataCollectorTest.php b/Tests/DataCollector/RequestDataCollectorTest.php index b62f765068..1184aea43e 100644 --- a/Tests/DataCollector/RequestDataCollectorTest.php +++ b/Tests/DataCollector/RequestDataCollectorTest.php @@ -310,6 +310,27 @@ public function testStatelessCheck() $this->assertTrue($collector->getStatelessCheck()); } + public function testItHidesPassword() + { + $c = new RequestDataCollector(); + + $request = Request::create( + 'http://test.com/login', + 'POST', + ['_password' => ' _password@123'], + [], + [], + [], + '_password=%20_password%40123' + ); + + $c->collect($request, $this->createResponse()); + $c->lateCollect(); + + $this->assertEquals('******', $c->getRequestRequest()->get('_password')); + $this->assertEquals('_password=******', $c->getContent()); + } + protected function createRequest($routeParams = ['name' => 'foo']) { $request = Request::create('http://test.com/foo?bar=baz'); From ea0b110307d7977de134db533453522c855f24e3 Mon Sep 17 00:00:00 2001 From: Gonzalo Vilaseca Date: Thu, 9 Jul 2020 20:05:33 +0200 Subject: [PATCH 008/396] [HttpKernel] Provide status code in fragment handler exception --- Fragment/FragmentHandler.php | 4 +++- Tests/Fragment/FragmentHandlerTest.php | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Fragment/FragmentHandler.php b/Fragment/FragmentHandler.php index f51978ac7e..a5544347dc 100644 --- a/Fragment/FragmentHandler.php +++ b/Fragment/FragmentHandler.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Symfony\Component\HttpKernel\Exception\HttpException; /** * Renders a URI that represents a resource fragment. @@ -97,7 +98,8 @@ public function render($uri, string $renderer = 'inline', array $options = []) protected function deliver(Response $response) { if (!$response->isSuccessful()) { - throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $this->requestStack->getCurrentRequest()->getUri(), $response->getStatusCode())); + $responseStatusCode = $response->getStatusCode(); + throw new \RuntimeException(sprintf('Error when rendering "%s" (Status code is %d).', $this->requestStack->getCurrentRequest()->getUri(), $responseStatusCode), 0, new HttpException($responseStatusCode)); } if (!$response instanceof StreamedResponse) { diff --git a/Tests/Fragment/FragmentHandlerTest.php b/Tests/Fragment/FragmentHandlerTest.php index 15e543a214..56f1016067 100644 --- a/Tests/Fragment/FragmentHandlerTest.php +++ b/Tests/Fragment/FragmentHandlerTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Fragment\FragmentHandler; /** @@ -53,11 +54,20 @@ public function testRenderWithUnknownRenderer() public function testDeliverWithUnsuccessfulResponse() { - $this->expectException('RuntimeException'); - $this->expectExceptionMessage('Error when rendering "http://localhost/" (Status code is 404).'); $handler = $this->getHandler($this->returnValue(new Response('foo', 404))); - - $handler->render('/', 'foo'); + try { + $handler->render('/', 'foo'); + $this->fail('->render() throws a \RuntimeException exception if response is not successful'); + } catch (\Exception $e) { + $this->assertInstanceOf('\RuntimeException', $e); + $this->assertEquals(0, $e->getCode()); + $this->assertEquals('Error when rendering "http://localhost/" (Status code is 404).', $e->getMessage()); + + $previousException = $e->getPrevious(); + $this->assertInstanceOf(HttpException::class, $previousException); + $this->assertEquals(404, $previousException->getStatusCode()); + $this->assertEquals(0, $previousException->getCode()); + } } public function testRender() From 4c3b02cd029c435ab60e8bd19a212e5632cb3124 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Tue, 21 Apr 2020 13:53:45 +0200 Subject: [PATCH 009/396] [HttpKernel] Add `$kernel->getBuildDir()` to separate it from the cache directory --- Kernel.php | 30 ++++++++++++++++++++---------- KernelInterface.php | 8 ++++++++ RebootableInterface.php | 6 +++--- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Kernel.php b/Kernel.php index 8f7ff96808..ac83e9ed53 100644 --- a/Kernel.php +++ b/Kernel.php @@ -314,7 +314,7 @@ public function getContainer() */ public function setAnnotatedClassCache(array $annotatedClasses) { - file_put_contents(($this->warmupDir ?: $this->getCacheDir()).'/annotations.map', sprintf('warmupDir ?: $this->getBuildDir()).'/annotations.map', sprintf('getProjectDir().'/var/cache/'.$this->environment; } + /** + * Gets the build directory. + */ + public function getBuildDir(): string + { + // Returns $this->getCacheDir() for backward compatibility + return $this->getCacheDir(); + } + /** * {@inheritdoc} */ @@ -419,14 +428,14 @@ protected function getContainerBaseClass() /** * Initializes the service container. * - * The cached version of the service container is used when fresh, otherwise the + * The built version of the service container is used when fresh, otherwise the * container is built. */ protected function initializeContainer() { $class = $this->getContainerClass(); - $cacheDir = $this->warmupDir ?: $this->getCacheDir(); - $cache = new ConfigCache($cacheDir.'/'.$class.'.php', $this->debug); + $buildDir = $this->warmupDir ?: $this->getBuildDir(); + $cache = new ConfigCache($buildDir.'/'.$class.'.php', $this->debug); $cachePath = $cache->getPath(); // Silence E_WARNING to ignore "include" failures - don't use "@" to prevent silencing fatal errors @@ -448,7 +457,7 @@ protected function initializeContainer() $oldContainer = \is_object($this->container) ? new \ReflectionClass($this->container) : $this->container = null; try { - is_dir($cacheDir) ?: mkdir($cacheDir, 0777, true); + is_dir($buildDir) ?: mkdir($buildDir, 0777, true); if ($lock = fopen($cachePath.'.lock', 'w')) { flock($lock, LOCK_EX | LOCK_NB, $wouldBlock); @@ -533,8 +542,8 @@ protected function initializeContainer() if ($collectDeprecations) { restore_error_handler(); - file_put_contents($cacheDir.'/'.$class.'Deprecations.log', serialize(array_values($collectedLogs))); - file_put_contents($cacheDir.'/'.$class.'Compiler.log', null !== $container ? implode("\n", $container->getCompiler()->getLog()) : ''); + file_put_contents($buildDir.'/'.$class.'Deprecations.log', serialize(array_values($collectedLogs))); + file_put_contents($buildDir.'/'.$class.'Compiler.log', null !== $container ? implode("\n", $container->getCompiler()->getLog()) : ''); } } @@ -570,7 +579,7 @@ protected function initializeContainer() $preload = array_merge($preload, (array) $this->container->get('cache_warmer')->warmUp($this->container->getParameter('kernel.cache_dir'))); } - if ($preload && method_exists(Preloader::class, 'append') && file_exists($preloadFile = $cacheDir.'/'.$class.'.preload.php')) { + if ($preload && method_exists(Preloader::class, 'append') && file_exists($preloadFile = $buildDir.'/'.$class.'.preload.php')) { Preloader::append($preloadFile, $preload); } } @@ -597,7 +606,8 @@ protected function getKernelParameters() 'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(), 'kernel.environment' => $this->environment, 'kernel.debug' => $this->debug, - 'kernel.cache_dir' => realpath($cacheDir = $this->warmupDir ?: $this->getCacheDir()) ?: $cacheDir, + 'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir, + 'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(), 'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(), 'kernel.bundles' => $bundles, 'kernel.bundles_metadata' => $bundlesMetadata, @@ -615,7 +625,7 @@ protected function getKernelParameters() */ protected function buildContainer() { - foreach (['cache' => $this->warmupDir ?: $this->getCacheDir(), 'logs' => $this->getLogDir()] as $name => $dir) { + foreach (['cache' => $this->getCacheDir(), 'build' => $this->warmupDir ?: $this->getBuildDir(), 'logs' => $this->getLogDir()] as $name => $dir) { if (!is_dir($dir)) { if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) { throw new \RuntimeException(sprintf('Unable to create the "%s" directory (%s).', $name, $dir)); diff --git a/KernelInterface.php b/KernelInterface.php index cea86f687a..c1be3aff43 100644 --- a/KernelInterface.php +++ b/KernelInterface.php @@ -20,6 +20,10 @@ * * It manages an environment made of application kernel and bundles. * + * @method string getBuildDir() Returns the build directory - not implementing it is deprecated since Symfony 5.2. + * This directory should be used to store build artifacts, and can be read-only at runtime. + * Caches written at runtime should be stored in the "cache directory" ({@see KernelInterface::getCacheDir()}). + * * @author Fabien Potencier */ interface KernelInterface extends HttpKernelInterface @@ -121,6 +125,10 @@ public function getStartTime(); /** * Gets the cache directory. * + * Since Symfony 5.2, the cache directory should be used for caches that are written at runtime. + * For caches and artifacts that can be warmed at compile-time and deployed as read-only, + * use the new "build directory" returned by the {@see getBuildDir()} method. + * * @return string The cache directory */ public function getCacheDir(); diff --git a/RebootableInterface.php b/RebootableInterface.php index 0dc46c3cef..e257237da9 100644 --- a/RebootableInterface.php +++ b/RebootableInterface.php @@ -21,10 +21,10 @@ interface RebootableInterface /** * Reboots a kernel. * - * The getCacheDir() method of a rebootable kernel should not be called - * while building the container. Use the %kernel.cache_dir% parameter instead. + * The getBuildDir() method of a rebootable kernel should not be called + * while building the container. Use the %kernel.build_dir% parameter instead. * - * @param string|null $warmupDir pass null to reboot in the regular cache directory + * @param string|null $warmupDir pass null to reboot in the regular build directory */ public function reboot(?string $warmupDir); } From 252cf71ca7b48e120822ec664b5d1710e925873b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 21 Aug 2020 08:52:49 +0200 Subject: [PATCH 010/396] Fixed CS --- Kernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel.php b/Kernel.php index ac83e9ed53..cae420dd12 100644 --- a/Kernel.php +++ b/Kernel.php @@ -334,7 +334,7 @@ public function getCacheDir() } /** - * Gets the build directory. + * {@inheritdoc} */ public function getBuildDir(): string { From f7f6e3610060f6ec8b66db6c14513db4045ad2d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vasseur?= Date: Thu, 13 Aug 2020 14:36:38 +0200 Subject: [PATCH 011/396] [RFC][HttpKernel][Security] Allowed adding attributes on controller arguments that will be passed to argument resolvers. --- Attribute/ArgumentInterface.php | 19 ++++++++++++++ CHANGELOG.md | 1 + ControllerMetadata/ArgumentMetadata.php | 14 +++++++++- .../ArgumentMetadataFactory.php | 26 ++++++++++++++++++- Exception/InvalidMetadataException.php | 16 ++++++++++++ .../ArgumentMetadataFactoryTest.php | 25 ++++++++++++++++++ Tests/Fixtures/Attribute/Foo.php | 26 +++++++++++++++++++ .../Controller/AttributeController.php | 23 ++++++++++++++++ 8 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 Attribute/ArgumentInterface.php create mode 100644 Exception/InvalidMetadataException.php create mode 100644 Tests/Fixtures/Attribute/Foo.php create mode 100644 Tests/Fixtures/Controller/AttributeController.php diff --git a/Attribute/ArgumentInterface.php b/Attribute/ArgumentInterface.php new file mode 100644 index 0000000000..8f0c6fb8b0 --- /dev/null +++ b/Attribute/ArgumentInterface.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Attribute; + +/** + * Marker interface for controller argument attributes. + */ +interface ArgumentInterface +{ +} diff --git a/CHANGELOG.md b/CHANGELOG.md index f597c6ab0c..47fb5b1685 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ CHANGELOG `kernel.trusted_proxies` and `kernel.trusted_headers` parameters * content of request parameter `_password` is now also hidden in the request profiler raw content section + * Allowed adding attributes on controller arguments that will be passed to argument resolvers. 5.1.0 ----- diff --git a/ControllerMetadata/ArgumentMetadata.php b/ControllerMetadata/ArgumentMetadata.php index 6fc7e70344..3454ff6e49 100644 --- a/ControllerMetadata/ArgumentMetadata.php +++ b/ControllerMetadata/ArgumentMetadata.php @@ -11,6 +11,8 @@ namespace Symfony\Component\HttpKernel\ControllerMetadata; +use Symfony\Component\HttpKernel\Attribute\ArgumentInterface; + /** * Responsible for storing metadata of an argument. * @@ -24,8 +26,9 @@ class ArgumentMetadata private $hasDefaultValue; private $defaultValue; private $isNullable; + private $attribute; - public function __construct(string $name, ?string $type, bool $isVariadic, bool $hasDefaultValue, $defaultValue, bool $isNullable = false) + public function __construct(string $name, ?string $type, bool $isVariadic, bool $hasDefaultValue, $defaultValue, bool $isNullable = false, ?ArgumentInterface $attribute = null) { $this->name = $name; $this->type = $type; @@ -33,6 +36,7 @@ public function __construct(string $name, ?string $type, bool $isVariadic, bool $this->hasDefaultValue = $hasDefaultValue; $this->defaultValue = $defaultValue; $this->isNullable = $isNullable || null === $type || ($hasDefaultValue && null === $defaultValue); + $this->attribute = $attribute; } /** @@ -104,4 +108,12 @@ public function getDefaultValue() return $this->defaultValue; } + + /** + * Returns the attribute (if any) that was set on the argument. + */ + public function getAttribute(): ?ArgumentInterface + { + return $this->attribute; + } } diff --git a/ControllerMetadata/ArgumentMetadataFactory.php b/ControllerMetadata/ArgumentMetadataFactory.php index 05a68229a3..6ae76c0ff8 100644 --- a/ControllerMetadata/ArgumentMetadataFactory.php +++ b/ControllerMetadata/ArgumentMetadataFactory.php @@ -11,6 +11,9 @@ namespace Symfony\Component\HttpKernel\ControllerMetadata; +use Symfony\Component\HttpKernel\Attribute\ArgumentInterface; +use Symfony\Component\HttpKernel\Exception\InvalidMetadataException; + /** * Builds {@see ArgumentMetadata} objects based on the given Controller. * @@ -34,7 +37,28 @@ public function createArgumentMetadata($controller): array } foreach ($reflection->getParameters() as $param) { - $arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull()); + $attribute = null; + if (method_exists($param, 'getAttributes')) { + $reflectionAttributes = $param->getAttributes(ArgumentInterface::class, \ReflectionAttribute::IS_INSTANCEOF); + + if (\count($reflectionAttributes) > 1) { + $representative = $controller; + + if (\is_array($representative)) { + $representative = sprintf('%s::%s()', \get_class($representative[0]), $representative[1]); + } elseif (\is_object($representative)) { + $representative = \get_class($representative); + } + + throw new InvalidMetadataException(sprintf('Controller "%s" has more than one attribute for "$%s" argument.', $representative, $param->getName())); + } + + if (isset($reflectionAttributes[0])) { + $attribute = $reflectionAttributes[0]->newInstance(); + } + } + + $arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull(), $attribute); } return $arguments; diff --git a/Exception/InvalidMetadataException.php b/Exception/InvalidMetadataException.php new file mode 100644 index 0000000000..129267ab05 --- /dev/null +++ b/Exception/InvalidMetadataException.php @@ -0,0 +1,16 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Exception; + +class InvalidMetadataException extends \LogicException +{ +} diff --git a/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php b/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php index dfab909802..3c57c3161c 100644 --- a/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php +++ b/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php @@ -15,6 +15,9 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory; +use Symfony\Component\HttpKernel\Exception\InvalidMetadataException; +use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\Foo; +use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\AttributeController; use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\BasicTypesController; use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\NullableController; use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\VariadicController; @@ -117,6 +120,28 @@ public function testNullableTypesSignature() ], $arguments); } + /** + * @requires PHP 8 + */ + public function testAttributeSignature() + { + $arguments = $this->factory->createArgumentMetadata([new AttributeController(), 'action']); + + $this->assertEquals([ + new ArgumentMetadata('baz', 'string', false, false, null, false, new Foo('bar')), + ], $arguments); + } + + /** + * @requires PHP 8 + */ + public function testAttributeSignatureError() + { + $this->expectException(InvalidMetadataException::class); + + $this->factory->createArgumentMetadata([new AttributeController(), 'invalidAction']); + } + private function signature1(self $foo, array $bar, callable $baz) { } diff --git a/Tests/Fixtures/Attribute/Foo.php b/Tests/Fixtures/Attribute/Foo.php new file mode 100644 index 0000000000..d932d0584a --- /dev/null +++ b/Tests/Fixtures/Attribute/Foo.php @@ -0,0 +1,26 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Tests\Fixtures\Attribute; + +use Attribute; +use Symfony\Component\HttpKernel\Attribute\ArgumentInterface; + +#[Attribute(Attribute::TARGET_PARAMETER)] +class Foo implements ArgumentInterface +{ + private $foo; + + public function __construct($foo) + { + $this->foo = $foo; + } +} diff --git a/Tests/Fixtures/Controller/AttributeController.php b/Tests/Fixtures/Controller/AttributeController.php new file mode 100644 index 0000000000..910f418ae1 --- /dev/null +++ b/Tests/Fixtures/Controller/AttributeController.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Tests\Fixtures\Controller; + +use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\Foo; + +class AttributeController +{ + public function action(#[Foo('bar')] string $baz) { + } + + public function invalidAction(#[Foo('bar'), Foo('bar')] string $baz) { + } +} From d584cf987fa492450a4eac1136df503922ae6711 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 12 Sep 2020 10:28:26 +0200 Subject: [PATCH 012/396] Fix CS --- ControllerMetadata/ArgumentMetadataFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ControllerMetadata/ArgumentMetadataFactory.php b/ControllerMetadata/ArgumentMetadataFactory.php index 6ae76c0ff8..f53bf065b9 100644 --- a/ControllerMetadata/ArgumentMetadataFactory.php +++ b/ControllerMetadata/ArgumentMetadataFactory.php @@ -38,7 +38,7 @@ public function createArgumentMetadata($controller): array foreach ($reflection->getParameters() as $param) { $attribute = null; - if (method_exists($param, 'getAttributes')) { + if (\PHP_VERSION_ID >= 80000) { $reflectionAttributes = $param->getAttributes(ArgumentInterface::class, \ReflectionAttribute::IS_INSTANCEOF); if (\count($reflectionAttributes) > 1) { From b51d6d3f0c9625777fcadb0d8a3b7cb74ee142a0 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Sun, 20 Sep 2020 02:23:25 +0200 Subject: [PATCH 013/396] Auto-register kernel as an extension --- CHANGELOG.md | 1 + Kernel.php | 4 ++++ Tests/KernelTest.php | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47fb5b1685..a655e2d6f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ CHANGELOG * content of request parameter `_password` is now also hidden in the request profiler raw content section * Allowed adding attributes on controller arguments that will be passed to argument resolvers. + * kernels implementing the `ExtensionInterface` will now be auto-registered to the container 5.1.0 ----- diff --git a/Kernel.php b/Kernel.php index 800ec07878..ad9a4b2d78 100644 --- a/Kernel.php +++ b/Kernel.php @@ -23,6 +23,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Dumper\PhpDumper; use Symfony\Component\DependencyInjection\Dumper\Preloader; +use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\DependencyInjection\Loader\ClosureLoader; use Symfony\Component\DependencyInjection\Loader\DirectoryLoader; use Symfony\Component\DependencyInjection\Loader\GlobFileLoader; @@ -688,6 +689,9 @@ protected function getContainerBuilder() $container = new ContainerBuilder(); $container->getParameterBag()->add($this->getKernelParameters()); + if ($this instanceof ExtensionInterface) { + $container->registerExtension($this); + } if ($this instanceof CompilerPassInterface) { $container->addCompilerPass($this, PassConfig::TYPE_BEFORE_OPTIMIZATION, -10000); } diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index 9e51805541..beb4b9fe3f 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Extension\ExtensionInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -475,6 +476,34 @@ public function testKernelReset() $this->assertFileExists(\dirname($containerFile).'.legacy'); } + public function testKernelExtension() + { + $kernel = new class() extends CustomProjectDirKernel implements ExtensionInterface { + public function load(array $configs, ContainerBuilder $container) + { + $container->setParameter('test.extension-registered', true); + } + + public function getNamespace() + { + return ''; + } + + public function getXsdValidationBasePath() + { + return false; + } + + public function getAlias() + { + return 'test-extension'; + } + }; + $kernel->boot(); + + $this->assertTrue($kernel->getContainer()->getParameter('test.extension-registered')); + } + public function testKernelPass() { $kernel = new PassKernel(); From 517cc55429c4f19b8920e797361bde4594bdbc64 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 26 Sep 2020 19:44:58 +0200 Subject: [PATCH 014/396] [Validator] Constraints as php 8 Attributes. --- Tests/Fixtures/Attribute/Foo.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tests/Fixtures/Attribute/Foo.php b/Tests/Fixtures/Attribute/Foo.php index d932d0584a..96a03adaad 100644 --- a/Tests/Fixtures/Attribute/Foo.php +++ b/Tests/Fixtures/Attribute/Foo.php @@ -11,10 +11,9 @@ namespace Symfony\Component\HttpKernel\Tests\Fixtures\Attribute; -use Attribute; use Symfony\Component\HttpKernel\Attribute\ArgumentInterface; -#[Attribute(Attribute::TARGET_PARAMETER)] +#[\Attribute(\Attribute::TARGET_PARAMETER)] class Foo implements ArgumentInterface { private $foo; From a5ff1d536f6ca0fe9c4091a510241a6fc77cde75 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 13 Oct 2020 11:46:19 +0200 Subject: [PATCH 015/396] [HttpKernel] add `kernel.runtime_environment` = `%env(default:kernel.environment:APP_RUNTIME_ENV)%` parameter --- CHANGELOG.md | 1 + Kernel.php | 1 + composer.json | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a655e2d6f9..364b8a67fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ CHANGELOG in the request profiler raw content section * Allowed adding attributes on controller arguments that will be passed to argument resolvers. * kernels implementing the `ExtensionInterface` will now be auto-registered to the container + * added parameter `kernel.runtime_environment`, defined as `%env(default:kernel.environment:APP_RUNTIME_ENV)%` 5.1.0 ----- diff --git a/Kernel.php b/Kernel.php index ad9a4b2d78..c5a6be5344 100644 --- a/Kernel.php +++ b/Kernel.php @@ -606,6 +606,7 @@ protected function getKernelParameters() return [ 'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(), 'kernel.environment' => $this->environment, + 'kernel.runtime_environment' => '%env(default:kernel.environment:APP_RUNTIME_ENV)%', 'kernel.debug' => $this->debug, 'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir, 'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(), diff --git a/composer.json b/composer.json index 08dc362f9f..1677de4bf5 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "symfony/config": "^5.0", "symfony/console": "^4.4|^5.0", "symfony/css-selector": "^4.4|^5.0", - "symfony/dependency-injection": "^4.4|^5.0", + "symfony/dependency-injection": "^5.1.8", "symfony/dom-crawler": "^4.4|^5.0", "symfony/expression-language": "^4.4|^5.0", "symfony/finder": "^4.4|^5.0", @@ -53,7 +53,7 @@ "symfony/config": "<5.0", "symfony/console": "<4.4", "symfony/form": "<5.0", - "symfony/dependency-injection": "<4.4", + "symfony/dependency-injection": "<5.1.8", "symfony/doctrine-bridge": "<5.0", "symfony/http-client": "<5.0", "symfony/mailer": "<5.0", From 732885dc905d3e07c25a69e44820174b5c98b149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 27 Oct 2020 08:55:05 +0100 Subject: [PATCH 016/396] [HttpKernel] HttpKernelBrowser: don't set a default Accept header --- CHANGELOG.md | 1 + HttpKernelBrowser.php | 5 ++++- Tests/HttpKernelBrowserTest.php | 11 +++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 364b8a67fc..db28213343 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ CHANGELOG * Allowed adding attributes on controller arguments that will be passed to argument resolvers. * kernels implementing the `ExtensionInterface` will now be auto-registered to the container * added parameter `kernel.runtime_environment`, defined as `%env(default:kernel.environment:APP_RUNTIME_ENV)%` + * do not set a default `Accept` HTTP header when using `HttpKernelBrowser` 5.1.0 ----- diff --git a/HttpKernelBrowser.php b/HttpKernelBrowser.php index c1f5b4c922..554585fb9c 100644 --- a/HttpKernelBrowser.php +++ b/HttpKernelBrowser.php @@ -130,7 +130,10 @@ protected function getHandleScript() */ protected function filterRequest(DomRequest $request) { - $httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $request->getServer(), $request->getContent()); + $httpRequest = Request::create($request->getUri(), $request->getMethod(), $request->getParameters(), $request->getCookies(), $request->getFiles(), $server = $request->getServer(), $request->getContent()); + if (!isset($server['HTTP_ACCEPT'])) { + $httpRequest->headers->remove('Accept'); + } foreach ($this->filterFiles($httpRequest->files->all()) as $key => $value) { $httpRequest->files->set($key, $value); diff --git a/Tests/HttpKernelBrowserTest.php b/Tests/HttpKernelBrowserTest.php index 4d4fe5ae72..b64924745b 100644 --- a/Tests/HttpKernelBrowserTest.php +++ b/Tests/HttpKernelBrowserTest.php @@ -179,4 +179,15 @@ public function testUploadedFileWhenSizeExceedsUploadMaxFileSize() unlink($source); } + + public function testAcceptHeaderNotSet() + { + $client = new HttpKernelBrowser(new TestHttpKernel()); + + $client->request('GET', '/'); + $this->assertFalse($client->getRequest()->headers->has('Accept')); + + $client->request('GET', '/', [], [], ['HTTP_ACCEPT' => 'application/ld+json']); + $this->assertSame('application/ld+json', $client->getRequest()->headers->get('Accept')); + } } From 109b2a46e470a487ec8b0ffea4b0bb993aaf42ed Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 28 Oct 2020 06:50:56 +0100 Subject: [PATCH 017/396] Update VERSION for 4.4.16 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index d5bf69ea73..c21108b040 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '4.4.16-DEV'; + const VERSION = '4.4.16'; const VERSION_ID = 40416; const MAJOR_VERSION = 4; const MINOR_VERSION = 4; const RELEASE_VERSION = 16; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '11/2022'; const END_OF_LIFE = '11/2023'; From 3cb45dc339f5102d5af9d1c252adcfd19450c19c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 28 Oct 2020 06:54:40 +0100 Subject: [PATCH 018/396] Bump Symfony version to 4.4.17 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index c21108b040..079d375aba 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '4.4.16'; - const VERSION_ID = 40416; + const VERSION = '4.4.17-DEV'; + const VERSION_ID = 40417; const MAJOR_VERSION = 4; const MINOR_VERSION = 4; - const RELEASE_VERSION = 16; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 17; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '11/2022'; const END_OF_LIFE = '11/2023'; From 62f871655517ad42ddd2b42e2765d81add4844f9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 28 Oct 2020 07:07:48 +0100 Subject: [PATCH 019/396] Bump Symfony version to 5.1.9 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 5968980737..8410143b86 100644 --- a/Kernel.php +++ b/Kernel.php @@ -73,12 +73,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.1.8'; - const VERSION_ID = 50108; + const VERSION = '5.1.9-DEV'; + const VERSION_ID = 50109; const MAJOR_VERSION = 5; const MINOR_VERSION = 1; - const RELEASE_VERSION = 8; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 9; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '01/2021'; const END_OF_LIFE = '01/2021'; From c9f92f1f6e657aabefbdb7b31091c399b8a70dd7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 28 Oct 2020 07:08:40 +0100 Subject: [PATCH 020/396] Update VERSION for 5.2.0-BETA3 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index c5a6be5344..5d42e45e6e 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.2.0-DEV'; + const VERSION = '5.2.0-BETA3'; const VERSION_ID = 50200; const MAJOR_VERSION = 5; const MINOR_VERSION = 2; const RELEASE_VERSION = 0; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = 'BETA3'; const END_OF_MAINTENANCE = '07/2021'; const END_OF_LIFE = '07/2021'; From 616581459b9409222b5b992dce87018bb52a7daf Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 28 Oct 2020 07:15:27 +0100 Subject: [PATCH 021/396] Bump Symfony version to 5.2.0 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 5d42e45e6e..c5a6be5344 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.2.0-BETA3'; + const VERSION = '5.2.0-DEV'; const VERSION_ID = 50200; const MAJOR_VERSION = 5; const MINOR_VERSION = 2; const RELEASE_VERSION = 0; - const EXTRA_VERSION = 'BETA3'; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '07/2021'; const END_OF_LIFE = '07/2021'; From c77a26800864b7b69fba9329a7d740508cf12f20 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 28 Oct 2020 08:52:32 +0100 Subject: [PATCH 022/396] Use short array deconstruction syntax. --- Controller/ControllerResolver.php | 4 ++-- DataCollector/DumpDataCollector.php | 2 +- .../RegisterControllerArgumentLocatorsPass.php | 6 +++--- .../RemoveEmptyControllerArgumentLocatorsPass.php | 4 ++-- Kernel.php | 4 ++-- Profiler/FileProfilerStorage.php | 2 +- .../ControllerArgumentValueResolverPassTest.php | 4 ++-- Tests/HttpCache/StoreTest.php | 4 ++-- Tests/HttpCache/TestHttpKernel.php | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Controller/ControllerResolver.php b/Controller/ControllerResolver.php index 44f34d8ee8..9c2fdd9807 100644 --- a/Controller/ControllerResolver.php +++ b/Controller/ControllerResolver.php @@ -116,7 +116,7 @@ protected function createController($controller) return $controller; } - list($class, $method) = explode('::', $controller, 2); + [$class, $method] = explode('::', $controller, 2); try { $controller = [$this->instantiateController($class), $method]; @@ -176,7 +176,7 @@ private function getControllerError($callable): string return 'Invalid array callable, expected [controller, method].'; } - list($controller, $method) = $callable; + [$controller, $method] = $callable; if (\is_string($controller) && !class_exists($controller)) { return sprintf('Class "%s" does not exist.', $controller); diff --git a/DataCollector/DumpDataCollector.php b/DataCollector/DumpDataCollector.php index 4e430f8f37..f864e355f9 100644 --- a/DataCollector/DumpDataCollector.php +++ b/DataCollector/DumpDataCollector.php @@ -75,7 +75,7 @@ public function dump(Data $data) $this->stopwatch->start('dump'); } - list('name' => $name, 'file' => $file, 'line' => $line, 'file_excerpt' => $fileExcerpt) = $this->sourceContextProvider->getContext(); + ['name' => $name, 'file' => $file, 'line' => $line, 'file_excerpt' => $fileExcerpt] = $this->sourceContextProvider->getContext(); if ($this->dumper instanceof Connection) { if (!$this->dumper->write($data)) { diff --git a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php index f214fd125a..40c850cf66 100644 --- a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php +++ b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php @@ -99,7 +99,7 @@ public function process(ContainerBuilder $container) if (!isset($methods[$action = strtolower($attributes['action'])])) { throw new InvalidArgumentException(sprintf('Invalid "action" attribute on tag "%s" for service "%s": no public "%s()" method found on class "%s".', $this->controllerTag, $id, $attributes['action'], $class)); } - list($r, $parameters) = $methods[$action]; + [$r, $parameters] = $methods[$action]; $found = false; foreach ($parameters as $p) { @@ -117,7 +117,7 @@ public function process(ContainerBuilder $container) } } - foreach ($methods as list($r, $parameters)) { + foreach ($methods as [$r, $parameters]) { /** @var \ReflectionMethod $r */ // create a per-method map of argument-names to service/type-references @@ -139,7 +139,7 @@ public function process(ContainerBuilder $container) } elseif (isset($bindings[$bindingName = $type.' $'.$p->name]) || isset($bindings[$bindingName = '$'.$p->name]) || isset($bindings[$bindingName = $type])) { $binding = $bindings[$bindingName]; - list($bindingValue, $bindingId, , $bindingType, $bindingFile) = $binding->getValues(); + [$bindingValue, $bindingId, , $bindingType, $bindingFile] = $binding->getValues(); $binding->setValues([$bindingValue, $bindingId, true, $bindingType, $bindingFile]); if (!$bindingValue instanceof Reference) { diff --git a/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php b/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php index 596b6188f6..c09f2bfdf3 100644 --- a/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php +++ b/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php @@ -42,9 +42,9 @@ public function process(ContainerBuilder $container) } else { // any methods listed for call-at-instantiation cannot be actions $reason = false; - list($id, $action) = explode('::', $controller); + [$id, $action] = explode('::', $controller); $controllerDef = $container->getDefinition($id); - foreach ($controllerDef->getMethodCalls() as list($method)) { + foreach ($controllerDef->getMethodCalls() as [$method]) { if (0 === strcasecmp($action, $method)) { $reason = sprintf('Removing method "%s" of service "%s" from controller candidates: the method is called at instantiation, thus cannot be an action.', $action, $id); break; diff --git a/Kernel.php b/Kernel.php index 079d375aba..746eec8869 100644 --- a/Kernel.php +++ b/Kernel.php @@ -262,7 +262,7 @@ public function locateResource($name/*, $dir = null, $first = true, $triggerDepr $bundleName = substr($name, 1); $path = ''; if (false !== strpos($bundleName, '/')) { - list($bundleName, $path) = explode('/', $bundleName, 2); + [$bundleName, $path] = explode('/', $bundleName, 2); } $isResource = 0 === strpos($path, 'Resources') && null !== $dir; @@ -893,7 +893,7 @@ public function serialize() public function unserialize($data) { @trigger_error(sprintf('The "%s" method is deprecated since Symfony 4.3.', __METHOD__), \E_USER_DEPRECATED); - list($environment, $debug) = unserialize($data, ['allowed_classes' => false]); + [$environment, $debug] = unserialize($data, ['allowed_classes' => false]); $this->__construct($environment, $debug); } diff --git a/Profiler/FileProfilerStorage.php b/Profiler/FileProfilerStorage.php index 5f23e5e05d..b74563ac13 100644 --- a/Profiler/FileProfilerStorage.php +++ b/Profiler/FileProfilerStorage.php @@ -61,7 +61,7 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null, $st $result = []; while (\count($result) < $limit && $line = $this->readLineFromFile($file)) { $values = str_getcsv($line); - list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent, $csvStatusCode) = $values; + [$csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent, $csvStatusCode] = $values; $csvTime = (int) $csvTime; if ($ip && false === strpos($csvIp, $ip) || $url && false === strpos($csvUrl, $url) || $method && false === strpos($csvMethod, $method) || $statusCode && false === strpos($csvStatusCode, $statusCode)) { diff --git a/Tests/DependencyInjection/ControllerArgumentValueResolverPassTest.php b/Tests/DependencyInjection/ControllerArgumentValueResolverPassTest.php index 2694d002cf..c95a7fb524 100644 --- a/Tests/DependencyInjection/ControllerArgumentValueResolverPassTest.php +++ b/Tests/DependencyInjection/ControllerArgumentValueResolverPassTest.php @@ -39,7 +39,7 @@ public function testServicesAreOrderedAccordingToPriority() $container = new ContainerBuilder(); $container->setDefinition('argument_resolver', $definition); - foreach ($services as $id => list($tag)) { + foreach ($services as $id => [$tag]) { $container->register($id)->addTag('controller.argument_value_resolver', $tag); } @@ -72,7 +72,7 @@ public function testInDebugWithStopWatchDefinition() $container->register('debug.stopwatch', Stopwatch::class); $container->setDefinition('argument_resolver', $definition); - foreach ($services as $id => list($tag)) { + foreach ($services as $id => [$tag]) { $container->register($id)->addTag('controller.argument_value_resolver', $tag); } diff --git a/Tests/HttpCache/StoreTest.php b/Tests/HttpCache/StoreTest.php index 1f5f472802..fc1ef64663 100644 --- a/Tests/HttpCache/StoreTest.php +++ b/Tests/HttpCache/StoreTest.php @@ -92,7 +92,7 @@ public function testSetsTheXContentDigestResponseHeaderBeforeStoring() { $cacheKey = $this->storeSimpleEntry(); $entries = $this->getStoreMetadata($cacheKey); - list(, $res) = $entries[0]; + [, $res] = $entries[0]; $this->assertEquals('en9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', $res['x-content-digest'][0]); } @@ -103,7 +103,7 @@ public function testDoesNotTrustXContentDigestFromUpstream() $cacheKey = $this->store->write($this->request, $response); $entries = $this->getStoreMetadata($cacheKey); - list(, $res) = $entries[0]; + [, $res] = $entries[0]; $this->assertEquals('en9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', $res['x-content-digest'][0]); $this->assertEquals('en9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', $response->headers->get('X-Content-Digest')); diff --git a/Tests/HttpCache/TestHttpKernel.php b/Tests/HttpCache/TestHttpKernel.php index 5b204d8269..c116c31b65 100644 --- a/Tests/HttpCache/TestHttpKernel.php +++ b/Tests/HttpCache/TestHttpKernel.php @@ -43,13 +43,13 @@ public function assert(\Closure $callback) { $trustedConfig = [Request::getTrustedProxies(), Request::getTrustedHeaderSet()]; - list($trustedProxies, $trustedHeaderSet, $backendRequest) = $this->backendRequest; + [$trustedProxies, $trustedHeaderSet, $backendRequest] = $this->backendRequest; Request::setTrustedProxies($trustedProxies, $trustedHeaderSet); try { $callback($backendRequest); } finally { - list($trustedProxies, $trustedHeaderSet) = $trustedConfig; + [$trustedProxies, $trustedHeaderSet] = $trustedConfig; Request::setTrustedProxies($trustedProxies, $trustedHeaderSet); } } From 897796b28a759715c1633aa70e82daf2aeb98d0c Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 28 Oct 2020 22:33:29 +0100 Subject: [PATCH 023/396] Fix CS --- .../RemoveEmptyControllerArgumentLocatorsPass.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php b/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php index 0d4bfb9f18..5f54e9c164 100644 --- a/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php +++ b/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php @@ -42,7 +42,7 @@ public function process(ContainerBuilder $container) } else { // any methods listed for call-at-instantiation cannot be actions $reason = false; - list($id, $action) = explode('::', $controller); + [$id, $action] = explode('::', $controller); if ($container->hasAlias($id)) { continue; From aab798445a46e1ac8d417a90c89b9377109c588d Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Fri, 30 Oct 2020 14:31:03 +0100 Subject: [PATCH 024/396] Remove Symfony 3 compatibility code. --- EventListener/AbstractSessionListener.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/EventListener/AbstractSessionListener.php b/EventListener/AbstractSessionListener.php index 0a6789d85a..3da47dd8d0 100644 --- a/EventListener/AbstractSessionListener.php +++ b/EventListener/AbstractSessionListener.php @@ -55,12 +55,8 @@ public function onKernelRequest(GetResponseEvent $event) $session = null; $request = $event->getRequest(); - if ($request->hasSession()) { - // no-op - } elseif (method_exists($request, 'setSessionFactory')) { + if (!$request->hasSession()) { $request->setSessionFactory(function () { return $this->getSession(); }); - } elseif ($session = $this->getSession()) { - $request->setSession($session); } $session = $session ?? ($this->container && $this->container->has('initialized_session') ? $this->container->get('initialized_session') : null); From 615304c758744b5869bbef2de42066eb4cdbdcdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 30 Oct 2020 21:47:32 +0100 Subject: [PATCH 025/396] Fix session called initized several time --- EventListener/AbstractSessionListener.php | 3 +- Tests/EventListener/SessionListenerTest.php | 34 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/EventListener/AbstractSessionListener.php b/EventListener/AbstractSessionListener.php index 3da47dd8d0..ce38d88608 100644 --- a/EventListener/AbstractSessionListener.php +++ b/EventListener/AbstractSessionListener.php @@ -56,7 +56,8 @@ public function onKernelRequest(GetResponseEvent $event) $session = null; $request = $event->getRequest(); if (!$request->hasSession()) { - $request->setSessionFactory(function () { return $this->getSession(); }); + $sess = null; + $request->setSessionFactory(function () use (&$sess) { return $sess ?? $sess = $this->getSession(); }); } $session = $session ?? ($this->container && $this->container->has('initialized_session') ? $this->container->get('initialized_session') : null); diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index 8fc9f6bc9c..b3799bdb41 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -20,11 +20,13 @@ use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; 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; +use Symfony\Component\HttpKernel\KernelInterface; class SessionListenerTest extends TestCase { @@ -178,4 +180,36 @@ public function testSurrogateMasterRequestIsPublic() $this->assertTrue($response->headers->has('Expires')); $this->assertLessThanOrEqual((new \DateTime('now', new \DateTimeZone('UTC'))), (new \DateTime($response->headers->get('Expires')))); } + + public function testGetSessionIsCalledOnce() + { + $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $sessionStorage = $this->getMockBuilder(NativeSessionStorage::class)->getMock(); + $kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); + + $sessionStorage->expects($this->once()) + ->method('setOptions') + ->with(['cookie_secure' => true]); + + $requestStack = new RequestStack(); + $requestStack->push($masterRequest = new Request([], [], [], [], [], ['HTTPS' => 'on'])); + + $container = new Container(); + $container->set('session_storage', $sessionStorage); + $container->set('session', $session); + $container->set('request_stack', $requestStack); + + $event = new GetResponseEvent($kernel, $masterRequest, HttpKernelInterface::MASTER_REQUEST); + + $listener = new SessionListener($container); + $listener->onKernelRequest($event); + + $subRequest = $masterRequest->duplicate(); + // at this point both master and subrequest have a closure to build the session + + $masterRequest->getSession(); + + // calling the factory on the subRequest should not trigger a second call to storage->sesOptions() + $subRequest->getSession(); + } } From 6bf4e638a73c873811e8f1b2f2d5abf505376e2e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 2 Nov 2020 17:05:56 +0100 Subject: [PATCH 026/396] [HttpKernel] fix merge --- Tests/EventListener/SessionListenerTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index b3799bdb41..8131ff2ea1 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -20,7 +20,6 @@ use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; 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; @@ -199,7 +198,7 @@ public function testGetSessionIsCalledOnce() $container->set('session', $session); $container->set('request_stack', $requestStack); - $event = new GetResponseEvent($kernel, $masterRequest, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $masterRequest, HttpKernelInterface::MASTER_REQUEST); $listener = new SessionListener($container); $listener->onKernelRequest($event); From b35b9b0c151a00a7d84fb063ce7eb17fb764f39c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Sun, 1 Nov 2020 22:31:33 +0100 Subject: [PATCH 027/396] Deprecate HEADER_X_FORWARDED_ALL constant --- Tests/HttpCache/HttpCacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/HttpCache/HttpCacheTest.php b/Tests/HttpCache/HttpCacheTest.php index 6ad64e4791..0f0a25ef1c 100644 --- a/Tests/HttpCache/HttpCacheTest.php +++ b/Tests/HttpCache/HttpCacheTest.php @@ -1361,7 +1361,7 @@ public function testClientIpIsAlwaysLocalhostForForwardedRequests() */ public function testHttpCacheIsSetAsATrustedProxy(array $existing) { - Request::setTrustedProxies($existing, Request::HEADER_X_FORWARDED_ALL); + Request::setTrustedProxies($existing, Request::HEADER_X_FORWARDED_FOR); $this->setNextResponse(); $this->request('GET', '/', ['REMOTE_ADDR' => '10.0.0.1']); From ad93121b82327d1bed5cabefe272421dd7ff538d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 10 Nov 2020 08:38:36 +0100 Subject: [PATCH 028/396] updated version to 5.3 --- Kernel.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Kernel.php b/Kernel.php index 3522aaa770..03c3bb0412 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,15 +74,15 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.2.0-DEV'; - const VERSION_ID = 50200; + const VERSION = '5.3.0-DEV'; + const VERSION_ID = 50300; const MAJOR_VERSION = 5; - const MINOR_VERSION = 2; + const MINOR_VERSION = 3; const RELEASE_VERSION = 0; const EXTRA_VERSION = 'DEV'; - const END_OF_MAINTENANCE = '07/2021'; - const END_OF_LIFE = '07/2021'; + const END_OF_MAINTENANCE = '05/2021'; + const END_OF_LIFE = '01/2022'; public function __construct(string $environment, bool $debug) { From e8136e599847130f54ff70e47fc9e5070bc4860b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 10 Nov 2020 08:54:37 +0100 Subject: [PATCH 029/396] Update VERSION for 5.2.0-RC1 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 3522aaa770..5f604808da 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.2.0-DEV'; + const VERSION = '5.2.0-RC1'; const VERSION_ID = 50200; const MAJOR_VERSION = 5; const MINOR_VERSION = 2; const RELEASE_VERSION = 0; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = 'RC1'; const END_OF_MAINTENANCE = '07/2021'; const END_OF_LIFE = '07/2021'; From f3c0a008f0e81dde72d8b8fa6c6a5b417e864155 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 10 Nov 2020 09:06:25 +0100 Subject: [PATCH 030/396] Bump Symfony version to 5.2.0 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 5f604808da..3522aaa770 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.2.0-RC1'; + const VERSION = '5.2.0-DEV'; const VERSION_ID = 50200; const MAJOR_VERSION = 5; const MINOR_VERSION = 2; const RELEASE_VERSION = 0; - const EXTRA_VERSION = 'RC1'; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '07/2021'; const END_OF_LIFE = '07/2021'; From bfe099ec08ee84a1c228754435018cf5b96bd492 Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Fri, 13 Nov 2020 13:20:22 +0100 Subject: [PATCH 031/396] Update ExceptionEvent.php --- Event/ExceptionEvent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Event/ExceptionEvent.php b/Event/ExceptionEvent.php index 3dae0d4ce6..313a3615b2 100644 --- a/Event/ExceptionEvent.php +++ b/Event/ExceptionEvent.php @@ -18,7 +18,7 @@ * current request. The propagation of this event is stopped as soon as a * response is set. * - * You can also call setException() to replace the thrown exception. This + * You can also call setThrowable() to replace the thrown exception. This * exception will be thrown if no response is set during processing of this * event. * From 7b7dd57b262a20c6bca60a28d2b3ee6b7e5479fd Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 17 Nov 2020 19:23:27 +0100 Subject: [PATCH 032/396] do not depend on the actual time to fix a transient test --- Tests/HttpCache/ResponseCacheStrategyTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Tests/HttpCache/ResponseCacheStrategyTest.php b/Tests/HttpCache/ResponseCacheStrategyTest.php index fd67af368b..62179ba154 100644 --- a/Tests/HttpCache/ResponseCacheStrategyTest.php +++ b/Tests/HttpCache/ResponseCacheStrategyTest.php @@ -239,6 +239,7 @@ public function testResponseIsExpirableButNotValidateableWhenMasterResponseCombi } /** + * @group time-sensitive * @dataProvider cacheControlMergingProvider */ public function testCacheControlMerging(array $expects, array $master, array $surrogates) From 4e5b640676b7ca24e0052c0cb9a3382839fdc658 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 21 Nov 2020 09:45:53 +0100 Subject: [PATCH 033/396] Update VERSION for 5.2.0-RC2 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 3522aaa770..aa069bb7e9 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.2.0-DEV'; + const VERSION = '5.2.0-RC2'; const VERSION_ID = 50200; const MAJOR_VERSION = 5; const MINOR_VERSION = 2; const RELEASE_VERSION = 0; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = 'RC2'; const END_OF_MAINTENANCE = '07/2021'; const END_OF_LIFE = '07/2021'; From cc3826064b4117e4a66b99060c77551b2b87f624 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 21 Nov 2020 09:49:39 +0100 Subject: [PATCH 034/396] Bump Symfony version to 5.2.0 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index aa069bb7e9..3522aaa770 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.2.0-RC2'; + const VERSION = '5.2.0-DEV'; const VERSION_ID = 50200; const MAJOR_VERSION = 5; const MINOR_VERSION = 2; const RELEASE_VERSION = 0; - const EXTRA_VERSION = 'RC2'; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '07/2021'; const END_OF_LIFE = '07/2021'; From 9f5605ee05406d8afa40dc4f2954c6a61de3a984 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 29 Nov 2020 10:23:08 +0100 Subject: [PATCH 035/396] Update VERSION for 4.4.17 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 746eec8869..88b77741c5 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '4.4.17-DEV'; + const VERSION = '4.4.17'; const VERSION_ID = 40417; const MAJOR_VERSION = 4; const MINOR_VERSION = 4; const RELEASE_VERSION = 17; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '11/2022'; const END_OF_LIFE = '11/2023'; From 2a35d1406f69921a5d3d0ed8545f45a26c26f64b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 29 Nov 2020 10:27:10 +0100 Subject: [PATCH 036/396] Bump Symfony version to 4.4.18 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 88b77741c5..cda7223b9a 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '4.4.17'; - const VERSION_ID = 40417; + const VERSION = '4.4.18-DEV'; + const VERSION_ID = 40418; const MAJOR_VERSION = 4; const MINOR_VERSION = 4; - const RELEASE_VERSION = 17; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 18; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '11/2022'; const END_OF_LIFE = '11/2023'; From 2d0daaf17c9fe14eb3519b94b83d746554ecfd9c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 29 Nov 2020 10:27:52 +0100 Subject: [PATCH 037/396] Update VERSION for 5.1.9 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 55e50173ba..4134ff870e 100644 --- a/Kernel.php +++ b/Kernel.php @@ -73,12 +73,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.1.9-DEV'; + const VERSION = '5.1.9'; const VERSION_ID = 50109; const MAJOR_VERSION = 5; const MINOR_VERSION = 1; const RELEASE_VERSION = 9; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '01/2021'; const END_OF_LIFE = '01/2021'; From 9b836ad5efed0bba9de02f14785b2de61cd70c6c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 29 Nov 2020 10:31:15 +0100 Subject: [PATCH 038/396] Bump Symfony version to 5.1.10 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 4134ff870e..76a07f8f08 100644 --- a/Kernel.php +++ b/Kernel.php @@ -73,12 +73,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.1.9'; - const VERSION_ID = 50109; + const VERSION = '5.1.10-DEV'; + const VERSION_ID = 50110; const MAJOR_VERSION = 5; const MINOR_VERSION = 1; - const RELEASE_VERSION = 9; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 10; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '01/2021'; const END_OF_LIFE = '01/2021'; From 9a66282aafef9f6a3eef662bdc10657126c090f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Auswo=CC=88ger?= Date: Sun, 29 Nov 2020 22:21:38 +0100 Subject: [PATCH 039/396] Fix bug with whitespace in Kernel::stripComments() --- Kernel.php | 5 +++++ Tests/KernelTest.php | 51 ++++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/Kernel.php b/Kernel.php index cda7223b9a..2eaf01573a 100644 --- a/Kernel.php +++ b/Kernel.php @@ -858,6 +858,9 @@ public static function stripComments($source) // replace multiple new lines with a single newline $rawChunk .= preg_replace(['/\n{2,}/S'], "\n", $token[1]); } elseif (\in_array($token[0], [\T_COMMENT, \T_DOC_COMMENT])) { + if (!\in_array($rawChunk[\strlen($rawChunk) - 1], [' ', "\n", "\r", "\t"], true)) { + $rawChunk .= ' '; + } $ignoreSpace = true; } else { $rawChunk .= $token[1]; @@ -865,6 +868,8 @@ public static function stripComments($source) // The PHP-open tag already has a new-line if (\T_OPEN_TAG === $token[0]) { $ignoreSpace = true; + } else { + $ignoreSpace = false; } } } diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index b4075c98ba..2b486e6673 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -239,10 +239,37 @@ public function testHandleBootsTheKernel() $kernel->handle($request, $type, $catch); } - public function testStripComments() + /** + * @dataProvider getStripCommentsCodes + */ + public function testStripComments(string $source, string $expected) + { + $output = Kernel::stripComments($source); + + // Heredocs are preserved, making the output mixing Unix and Windows line + // endings, switching to "\n" everywhere on Windows to avoid failure. + if ('\\' === \DIRECTORY_SEPARATOR) { + $expected = str_replace("\r\n", "\n", $expected); + $output = str_replace("\r\n", "\n", $output); + } + + $this->assertEquals($expected, $output); + } + + public function getStripCommentsCodes(): array { - $source = <<<'EOF' + return [ + ['assertEquals($expected, $output); +EOF + ], + ]; } /** From 38907e5ccb2d9d371191a946734afc83c7a03160 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 30 Nov 2020 06:54:18 +0100 Subject: [PATCH 040/396] Update VERSION for 5.2.0 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 3522aaa770..285507a21e 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.2.0-DEV'; + const VERSION = '5.2.0'; const VERSION_ID = 50200; const MAJOR_VERSION = 5; const MINOR_VERSION = 2; const RELEASE_VERSION = 0; - const EXTRA_VERSION = 'DEV'; + const EXTRA_VERSION = ''; const END_OF_MAINTENANCE = '07/2021'; const END_OF_LIFE = '07/2021'; From 57e8b0f832d6c5228544ff5f151677c10bb93d51 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 30 Nov 2020 06:59:51 +0100 Subject: [PATCH 041/396] Bump Symfony version to 5.2.1 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 285507a21e..9f6971378c 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '5.2.0'; - const VERSION_ID = 50200; + const VERSION = '5.2.1-DEV'; + const VERSION_ID = 50201; const MAJOR_VERSION = 5; const MINOR_VERSION = 2; - const RELEASE_VERSION = 0; - const EXTRA_VERSION = ''; + const RELEASE_VERSION = 1; + const EXTRA_VERSION = 'DEV'; const END_OF_MAINTENANCE = '07/2021'; const END_OF_LIFE = '07/2021'; From 2292c59f379d35f505093dc0cb439d30e76348bc Mon Sep 17 00:00:00 2001 From: kick-the-bucket Date: Mon, 30 Nov 2020 18:59:21 +0200 Subject: [PATCH 042/396] Remove unused @throws tags and handling of never thrown exceptions --- DataCollector/RequestDataCollector.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/DataCollector/RequestDataCollector.php b/DataCollector/RequestDataCollector.php index ba68c6b99a..56bc6ec194 100644 --- a/DataCollector/RequestDataCollector.php +++ b/DataCollector/RequestDataCollector.php @@ -53,12 +53,7 @@ public function collect(Request $request, Response $response/*, \Throwable $exce } } - try { - $content = $request->getContent(); - } catch (\LogicException $e) { - // the user already got the request content as a resource - $content = false; - } + $content = $request->getContent(); $sessionMetadata = []; $sessionAttributes = []; From 1a32690616a0d9c0aa7473e46cc4c26ba6a87c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 30 Nov 2020 20:36:42 +0100 Subject: [PATCH 043/396] [HttpKernel] Marked the class `Symfony\Component\HttpKernel\EventListener\DebugHandlersListener` as internal --- CHANGELOG.md | 5 +++++ EventListener/DebugHandlersListener.php | 2 ++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index db28213343..a5444039b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +5.3.0 +----- + + * marked the class `Symfony\Component\HttpKernel\EventListener\DebugHandlersListener` as internal + 5.2.0 ----- diff --git a/EventListener/DebugHandlersListener.php b/EventListener/DebugHandlersListener.php index 6b677edd7c..ee711798e9 100644 --- a/EventListener/DebugHandlersListener.php +++ b/EventListener/DebugHandlersListener.php @@ -27,6 +27,8 @@ * @author Nicolas Grekas * * @final + * + * @internal since Symfony 5.3 */ class DebugHandlersListener implements EventSubscriberInterface { From 1eb9998bf3877878cfea68fa594316300945e8fa Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 8 Dec 2020 17:59:59 +0100 Subject: [PATCH 044/396] Apply "visibility_required" CS rule to constants php-cs-fixer fix --rules='{"visibility_required": ["property", "method", "const"]}' --- EventListener/AbstractSessionListener.php | 2 +- HttpKernelInterface.php | 4 ++-- Kernel.php | 18 +++++++++--------- KernelEvents.php | 16 ++++++++-------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/EventListener/AbstractSessionListener.php b/EventListener/AbstractSessionListener.php index ce38d88608..0e99ee55c2 100644 --- a/EventListener/AbstractSessionListener.php +++ b/EventListener/AbstractSessionListener.php @@ -37,7 +37,7 @@ */ abstract class AbstractSessionListener implements EventSubscriberInterface { - const NO_AUTO_CACHE_CONTROL_HEADER = 'Symfony-Session-NoAutoCacheControl'; + public const NO_AUTO_CACHE_CONTROL_HEADER = 'Symfony-Session-NoAutoCacheControl'; protected $container; private $sessionUsageStack = []; diff --git a/HttpKernelInterface.php b/HttpKernelInterface.php index 7595d29d04..85fedbbe26 100644 --- a/HttpKernelInterface.php +++ b/HttpKernelInterface.php @@ -21,8 +21,8 @@ */ interface HttpKernelInterface { - const MASTER_REQUEST = 1; - const SUB_REQUEST = 2; + public const MASTER_REQUEST = 1; + public const SUB_REQUEST = 2; /** * Handles a Request to convert it to a Response. diff --git a/Kernel.php b/Kernel.php index 2eaf01573a..18fbb9ebe7 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,15 +76,15 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - const VERSION = '4.4.18-DEV'; - const VERSION_ID = 40418; - const MAJOR_VERSION = 4; - const MINOR_VERSION = 4; - const RELEASE_VERSION = 18; - const EXTRA_VERSION = 'DEV'; - - const END_OF_MAINTENANCE = '11/2022'; - const END_OF_LIFE = '11/2023'; + public const VERSION = '4.4.18-DEV'; + public const VERSION_ID = 40418; + public const MAJOR_VERSION = 4; + public const MINOR_VERSION = 4; + public const RELEASE_VERSION = 18; + public const EXTRA_VERSION = 'DEV'; + + public const END_OF_MAINTENANCE = '11/2022'; + public const END_OF_LIFE = '11/2023'; public function __construct(string $environment, bool $debug) { diff --git a/KernelEvents.php b/KernelEvents.php index 682561c324..b16141c602 100644 --- a/KernelEvents.php +++ b/KernelEvents.php @@ -27,7 +27,7 @@ final class KernelEvents * * @Event("Symfony\Component\HttpKernel\Event\RequestEvent") */ - const REQUEST = 'kernel.request'; + public const REQUEST = 'kernel.request'; /** * The EXCEPTION event occurs when an uncaught exception appears. @@ -37,7 +37,7 @@ final class KernelEvents * * @Event("Symfony\Component\HttpKernel\Event\ExceptionEvent") */ - const EXCEPTION = 'kernel.exception'; + public const EXCEPTION = 'kernel.exception'; /** * The VIEW event occurs when the return value of a controller @@ -48,7 +48,7 @@ final class KernelEvents * * @Event("Symfony\Component\HttpKernel\Event\ViewEvent") */ - const VIEW = 'kernel.view'; + public const VIEW = 'kernel.view'; /** * The CONTROLLER event occurs once a controller was found for @@ -59,7 +59,7 @@ final class KernelEvents * * @Event("Symfony\Component\HttpKernel\Event\ControllerEvent") */ - const CONTROLLER = 'kernel.controller'; + public const CONTROLLER = 'kernel.controller'; /** * The CONTROLLER_ARGUMENTS event occurs once controller arguments have been resolved. @@ -69,7 +69,7 @@ final class KernelEvents * * @Event("Symfony\Component\HttpKernel\Event\ControllerArgumentsEvent") */ - const CONTROLLER_ARGUMENTS = 'kernel.controller_arguments'; + public const CONTROLLER_ARGUMENTS = 'kernel.controller_arguments'; /** * The RESPONSE event occurs once a response was created for @@ -80,7 +80,7 @@ final class KernelEvents * * @Event("Symfony\Component\HttpKernel\Event\ResponseEvent") */ - const RESPONSE = 'kernel.response'; + public const RESPONSE = 'kernel.response'; /** * The TERMINATE event occurs once a response was sent. @@ -89,7 +89,7 @@ final class KernelEvents * * @Event("Symfony\Component\HttpKernel\Event\TerminateEvent") */ - const TERMINATE = 'kernel.terminate'; + public const TERMINATE = 'kernel.terminate'; /** * The FINISH_REQUEST event occurs when a response was generated for a request. @@ -99,5 +99,5 @@ final class KernelEvents * * @Event("Symfony\Component\HttpKernel\Event\FinishRequestEvent") */ - const FINISH_REQUEST = 'kernel.finish_request'; + public const FINISH_REQUEST = 'kernel.finish_request'; } From dc6703d71c0d80d24aa0114353d7c97b231f5b83 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 9 Dec 2020 11:47:41 +0100 Subject: [PATCH 045/396] Add missing param annotation abouts $fileLinkFormat --- DataCollector/DumpDataCollector.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DataCollector/DumpDataCollector.php b/DataCollector/DumpDataCollector.php index f864e355f9..df4ec5f670 100644 --- a/DataCollector/DumpDataCollector.php +++ b/DataCollector/DumpDataCollector.php @@ -14,6 +14,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Debug\FileLinkFormatter; use Symfony\Component\Stopwatch\Stopwatch; use Symfony\Component\VarDumper\Cloner\Data; use Symfony\Component\VarDumper\Cloner\VarCloner; @@ -43,6 +44,7 @@ class DumpDataCollector extends DataCollector implements DataDumperInterface private $sourceContextProvider; /** + * @param string|FileLinkFormatter|null $fileLinkFormat * @param DataDumperInterface|Connection|null $dumper */ public function __construct(Stopwatch $stopwatch = null, $fileLinkFormat = null, string $charset = null, RequestStack $requestStack = null, $dumper = null) From b5c5333a197df480370b6f5fc2f293ef0d624d98 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 11 Dec 2020 13:39:31 +0100 Subject: [PATCH 046/396] Remove void return type from test methods --- Tests/KernelTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index 2b486e6673..18974a720b 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -663,7 +663,7 @@ public function testKernelStartTimeIsResetWhileBootingAlreadyBootedKernel() $this->assertGreaterThan($preReBoot, $kernel->getStartTime()); } - public function testAnonymousKernelGeneratesValidContainerClass(): void + public function testAnonymousKernelGeneratesValidContainerClass() { $kernel = new class('test', true) extends Kernel { public function registerBundles(): iterable From 889b3dc757f2f84dbe0d58d17fb5544ab34da3f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 7 Dec 2020 13:47:12 +0100 Subject: [PATCH 047/396] Fix cache:clear with buildDir --- Kernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel.php b/Kernel.php index 55b59bc9b2..5fd4c05115 100644 --- a/Kernel.php +++ b/Kernel.php @@ -609,7 +609,7 @@ protected function getKernelParameters() 'kernel.runtime_environment' => '%env(default:kernel.environment:APP_RUNTIME_ENV)%', 'kernel.debug' => $this->debug, 'kernel.build_dir' => realpath($buildDir = $this->warmupDir ?: $this->getBuildDir()) ?: $buildDir, - 'kernel.cache_dir' => realpath($this->getCacheDir()) ?: $this->getCacheDir(), + 'kernel.cache_dir' => realpath($cacheDir = ($this->getCacheDir() === $this->getBuildDir() ? ($this->warmupDir ?: $this->getCacheDir()) : $this->getCacheDir())) ?: $cacheDir, 'kernel.logs_dir' => realpath($this->getLogDir()) ?: $this->getLogDir(), 'kernel.bundles' => $bundles, 'kernel.bundles_metadata' => $bundlesMetadata, From eaff9a43e74513508867ecfa66ef94fbb96ab128 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 18 Dec 2020 14:32:33 +0100 Subject: [PATCH 048/396] Update VERSION for 4.4.18 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 18fbb9ebe7..d0ea1ff626 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.18-DEV'; + public const VERSION = '4.4.18'; public const VERSION_ID = 40418; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; public const RELEASE_VERSION = 18; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From f953fa44b0a08d0597ad0c115efc523630d029f7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 18 Dec 2020 14:39:05 +0100 Subject: [PATCH 049/396] Bump Symfony version to 4.4.19 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index d0ea1ff626..22c3751b43 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.18'; - public const VERSION_ID = 40418; + public const VERSION = '4.4.19-DEV'; + public const VERSION_ID = 40419; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; - public const RELEASE_VERSION = 18; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 19; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From 006feae3085f3ae2ee392dd419e910fdfd20a2ea Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 18 Dec 2020 14:43:29 +0100 Subject: [PATCH 050/396] Update VERSION for 5.1.10 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 6c197e8c33..98f3116824 100644 --- a/Kernel.php +++ b/Kernel.php @@ -73,12 +73,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.1.10-DEV'; + public const VERSION = '5.1.10'; public const VERSION_ID = 50110; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 1; public const RELEASE_VERSION = 10; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '01/2021'; public const END_OF_LIFE = '01/2021'; From 2f7650a6883014c8819e32ee12b7a251ec9d9644 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 18 Dec 2020 14:48:52 +0100 Subject: [PATCH 051/396] Bump Symfony version to 5.1.11 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 98f3116824..d381651a7b 100644 --- a/Kernel.php +++ b/Kernel.php @@ -73,12 +73,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.1.10'; - public const VERSION_ID = 50110; + public const VERSION = '5.1.11-DEV'; + public const VERSION_ID = 50111; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 1; - public const RELEASE_VERSION = 10; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 11; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '01/2021'; public const END_OF_LIFE = '01/2021'; From 1feb619286d819180f7b8bc0dc44f516d9c62647 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 18 Dec 2020 14:49:39 +0100 Subject: [PATCH 052/396] Update VERSION for 5.2.1 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 5fd4c05115..b898bf25bd 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.1-DEV'; + public const VERSION = '5.2.1'; public const VERSION_ID = 50201; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; public const RELEASE_VERSION = 1; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 411267211b33b7dfa9e7cddb9ded743bd06d6c44 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 18 Dec 2020 15:09:16 +0100 Subject: [PATCH 053/396] Bump Symfony version to 5.2.2 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index b898bf25bd..82180d97c3 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.1'; - public const VERSION_ID = 50201; + public const VERSION = '5.2.2-DEV'; + public const VERSION_ID = 50202; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; - public const RELEASE_VERSION = 1; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 2; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 2455a111174c991e6145beec6eeed1d366a742b7 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 27 Dec 2020 00:49:32 +0100 Subject: [PATCH 054/396] CS: Apply ternary_to_null_coalescing fixer --- DataCollector/ConfigDataCollector.php | 2 +- DataCollector/LoggerDataCollector.php | 12 ++++++------ DataCollector/RequestDataCollector.php | 6 +++--- EventListener/RouterListener.php | 2 +- Fragment/AbstractSurrogateFragmentRenderer.php | 4 ++-- Fragment/HIncludeFragmentRenderer.php | 2 +- HttpCache/Esi.php | 2 +- HttpCache/Store.php | 4 ++-- Log/Logger.php | 2 +- UriSigner.php | 6 +++--- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/DataCollector/ConfigDataCollector.php b/DataCollector/ConfigDataCollector.php index f005f1d970..179c7515c7 100644 --- a/DataCollector/ConfigDataCollector.php +++ b/DataCollector/ConfigDataCollector.php @@ -219,7 +219,7 @@ public function getPhpVersion() */ public function getPhpVersionExtra() { - return isset($this->data['php_version_extra']) ? $this->data['php_version_extra'] : null; + return $this->data['php_version_extra'] ?? null; } /** diff --git a/DataCollector/LoggerDataCollector.php b/DataCollector/LoggerDataCollector.php index 07dd254d33..2797a347c8 100644 --- a/DataCollector/LoggerDataCollector.php +++ b/DataCollector/LoggerDataCollector.php @@ -81,32 +81,32 @@ public function lateCollect() public function getLogs() { - return isset($this->data['logs']) ? $this->data['logs'] : []; + return $this->data['logs'] ?? []; } public function getPriorities() { - return isset($this->data['priorities']) ? $this->data['priorities'] : []; + return $this->data['priorities'] ?? []; } public function countErrors() { - return isset($this->data['error_count']) ? $this->data['error_count'] : 0; + return $this->data['error_count'] ?? 0; } public function countDeprecations() { - return isset($this->data['deprecation_count']) ? $this->data['deprecation_count'] : 0; + return $this->data['deprecation_count'] ?? 0; } public function countWarnings() { - return isset($this->data['warning_count']) ? $this->data['warning_count'] : 0; + return $this->data['warning_count'] ?? 0; } public function countScreams() { - return isset($this->data['scream_count']) ? $this->data['scream_count'] : 0; + return $this->data['scream_count'] ?? 0; } public function getCompilerLogs() diff --git a/DataCollector/RequestDataCollector.php b/DataCollector/RequestDataCollector.php index 56bc6ec194..0e3c13ba06 100644 --- a/DataCollector/RequestDataCollector.php +++ b/DataCollector/RequestDataCollector.php @@ -88,7 +88,7 @@ public function collect(Request $request, Response $response/*, \Throwable $exce 'format' => $request->getRequestFormat(), 'content' => $content, 'content_type' => $response->headers->get('Content-Type', 'text/html'), - 'status_text' => isset(Response::$statusTexts[$statusCode]) ? Response::$statusTexts[$statusCode] : '', + 'status_text' => Response::$statusTexts[$statusCode] ?? '', 'status_code' => $statusCode, 'request_query' => $request->query->all(), 'request_request' => $request->request->all(), @@ -339,12 +339,12 @@ public function getController() */ public function getRedirect() { - return isset($this->data['redirect']) ? $this->data['redirect'] : false; + return $this->data['redirect'] ?? false; } public function getForwardToken() { - return isset($this->data['forward_token']) ? $this->data['forward_token'] : null; + return $this->data['forward_token'] ?? null; } /** diff --git a/EventListener/RouterListener.php b/EventListener/RouterListener.php index ee88debae4..0071979688 100644 --- a/EventListener/RouterListener.php +++ b/EventListener/RouterListener.php @@ -116,7 +116,7 @@ public function onKernelRequest(GetResponseEvent $event) if (null !== $this->logger) { $this->logger->info('Matched route "{route}".', [ - 'route' => isset($parameters['_route']) ? $parameters['_route'] : 'n/a', + 'route' => $parameters['_route'] ?? 'n/a', 'route_parameters' => $parameters, 'request_uri' => $request->getUri(), 'method' => $request->getMethod(), diff --git a/Fragment/AbstractSurrogateFragmentRenderer.php b/Fragment/AbstractSurrogateFragmentRenderer.php index f81199d883..06d8c380bd 100644 --- a/Fragment/AbstractSurrogateFragmentRenderer.php +++ b/Fragment/AbstractSurrogateFragmentRenderer.php @@ -71,12 +71,12 @@ public function render($uri, Request $request, array $options = []) $uri = $this->generateSignedFragmentUri($uri, $request); } - $alt = isset($options['alt']) ? $options['alt'] : null; + $alt = $options['alt'] ?? null; if ($alt instanceof ControllerReference) { $alt = $this->generateSignedFragmentUri($alt, $request); } - $tag = $this->surrogate->renderIncludeTag($uri, $alt, isset($options['ignore_errors']) ? $options['ignore_errors'] : false, isset($options['comment']) ? $options['comment'] : ''); + $tag = $this->surrogate->renderIncludeTag($uri, $alt, $options['ignore_errors'] ?? false, $options['comment'] ?? ''); return new Response($tag); } diff --git a/Fragment/HIncludeFragmentRenderer.php b/Fragment/HIncludeFragmentRenderer.php index cca653342c..9004102f7e 100644 --- a/Fragment/HIncludeFragmentRenderer.php +++ b/Fragment/HIncludeFragmentRenderer.php @@ -100,7 +100,7 @@ public function render($uri, Request $request, array $options = []) // We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content. $uri = str_replace('&', '&', $uri); - $template = isset($options['default']) ? $options['default'] : $this->globalDefaultTemplate; + $template = $options['default'] ?? $this->globalDefaultTemplate; if (null !== $this->templating && $template && $this->templateExists($template)) { $content = $this->templating->render($template); } else { diff --git a/HttpCache/Esi.php b/HttpCache/Esi.php index 3d461a7fe3..0bad63e748 100644 --- a/HttpCache/Esi.php +++ b/HttpCache/Esi.php @@ -97,7 +97,7 @@ public function process(Request $request, Response $response) $chunks[$i] = sprintf('surrogate->handle($this, %s, %s, %s) ?>'."\n", var_export($options['src'], true), - var_export(isset($options['alt']) ? $options['alt'] : '', true), + var_export($options['alt'] ?? '', true), isset($options['onerror']) && 'continue' === $options['onerror'] ? 'true' : 'false' ); ++$i; diff --git a/HttpCache/Store.php b/HttpCache/Store.php index 9536d78879..bfaaebe944 100644 --- a/HttpCache/Store.php +++ b/HttpCache/Store.php @@ -277,8 +277,8 @@ private function requestsMatch(?string $vary, array $env1, array $env2): bool foreach (preg_split('/[\s,]+/', $vary) as $header) { $key = str_replace('_', '-', strtolower($header)); - $v1 = isset($env1[$key]) ? $env1[$key] : null; - $v2 = isset($env2[$key]) ? $env2[$key] : null; + $v1 = $env1[$key] ?? null; + $v2 = $env2[$key] ?? null; if ($v1 !== $v2) { return false; } diff --git a/Log/Logger.php b/Log/Logger.php index c97673dd89..0181817bdf 100644 --- a/Log/Logger.php +++ b/Log/Logger.php @@ -43,7 +43,7 @@ public function __construct(string $minLevel = null, $output = null, callable $f $minLevel = null === $output || 'php://stdout' === $output || 'php://stderr' === $output ? LogLevel::ERROR : LogLevel::WARNING; if (isset($_ENV['SHELL_VERBOSITY']) || isset($_SERVER['SHELL_VERBOSITY'])) { - switch ((int) (isset($_ENV['SHELL_VERBOSITY']) ? $_ENV['SHELL_VERBOSITY'] : $_SERVER['SHELL_VERBOSITY'])) { + switch ((int) ($_ENV['SHELL_VERBOSITY'] ?? $_SERVER['SHELL_VERBOSITY'])) { case -1: $minLevel = LogLevel::ERROR; break; case 1: $minLevel = LogLevel::NOTICE; break; case 2: $minLevel = LogLevel::INFO; break; diff --git a/UriSigner.php b/UriSigner.php index a11a05f848..e4f988b265 100644 --- a/UriSigner.php +++ b/UriSigner.php @@ -93,12 +93,12 @@ private function buildUrl(array $url, array $params = []): string $url['query'] = http_build_query($params, '', '&'); $scheme = isset($url['scheme']) ? $url['scheme'].'://' : ''; - $host = isset($url['host']) ? $url['host'] : ''; + $host = $url['host'] ?? ''; $port = isset($url['port']) ? ':'.$url['port'] : ''; - $user = isset($url['user']) ? $url['user'] : ''; + $user = $url['user'] ?? ''; $pass = isset($url['pass']) ? ':'.$url['pass'] : ''; $pass = ($user || $pass) ? "$pass@" : ''; - $path = isset($url['path']) ? $url['path'] : ''; + $path = $url['path'] ?? ''; $query = isset($url['query']) && $url['query'] ? '?'.$url['query'] : ''; $fragment = isset($url['fragment']) ? '#'.$url['fragment'] : ''; From aca93aee3b5c9bd9f13d0e60b179bb40dd814413 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 1 Jan 2021 10:24:35 +0100 Subject: [PATCH 055/396] Bump license year --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 9e936ec044..9ff2d0d630 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2020 Fabien Potencier +Copyright (c) 2004-2021 Fabien Potencier Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 62b9794344217e2ba9c61aebb1f26237d778cce7 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 4 Jan 2021 12:47:14 +0100 Subject: [PATCH 056/396] harden test to not depend on the actual time --- Tests/Profiler/FileProfilerStorageTest.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/Tests/Profiler/FileProfilerStorageTest.php b/Tests/Profiler/FileProfilerStorageTest.php index e0480cc1e8..d2daa67bce 100644 --- a/Tests/Profiler/FileProfilerStorageTest.php +++ b/Tests/Profiler/FileProfilerStorageTest.php @@ -190,26 +190,25 @@ public function testRetrieveByUrl() public function testStoreTime() { - $dt = new \DateTime('now'); - $start = $dt->getTimestamp(); + $start = $now = time(); for ($i = 0; $i < 3; ++$i) { - $dt->modify('+1 minute'); + $now += 60; $profile = new Profile('time_'.$i); $profile->setIp('127.0.0.1'); $profile->setUrl('http://foo.bar'); - $profile->setTime($dt->getTimestamp()); + $profile->setTime($now); $profile->setMethod('GET'); $this->storage->write($profile); } - $records = $this->storage->find('', '', 3, 'GET', $start, time() + 3 * 60); + $records = $this->storage->find('', '', 3, 'GET', $start, $start + 3 * 60); $this->assertCount(3, $records, '->find() returns all previously added records'); $this->assertEquals('time_2', $records[0]['token'], '->find() returns records ordered by time in descendant order'); $this->assertEquals('time_1', $records[1]['token'], '->find() returns records ordered by time in descendant order'); $this->assertEquals('time_0', $records[2]['token'], '->find() returns records ordered by time in descendant order'); - $records = $this->storage->find('', '', 3, 'GET', $start, time() + 2 * 60); + $records = $this->storage->find('', '', 3, 'GET', $start, $start + 2 * 60); $this->assertCount(2, $records, '->find() should return only first two of the previously added records'); } From 91b3efe1aed585971d8063d0ecf2833bdc47fd5f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 10 Jan 2021 09:16:05 +0100 Subject: [PATCH 057/396] Improve composer.json descriptions --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 59dd77b637..459e5f4682 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "symfony/http-kernel", "type": "library", - "description": "Symfony HttpKernel Component", + "description": "Provides a structured process for converting a Request into a Response", "keywords": [], "homepage": "https://symfony.com", "license": "MIT", From c9a14960a283d8d5c8ea9fb3ba0a61794481fa3b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 10 Jan 2021 13:29:43 +0100 Subject: [PATCH 058/396] Use ::class keyword when possible --- Tests/Controller/ArgumentResolverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/Controller/ArgumentResolverTest.php b/Tests/Controller/ArgumentResolverTest.php index f2a726de39..c0ed800bb4 100644 --- a/Tests/Controller/ArgumentResolverTest.php +++ b/Tests/Controller/ArgumentResolverTest.php @@ -132,7 +132,7 @@ public function testGetArgumentsFailsOnUnresolvedValue() self::$resolver->getArguments($request, $controller); $this->fail('->getArguments() throws a \RuntimeException exception if it cannot determine the argument value'); } catch (\Exception $e) { - $this->assertInstanceOf('\RuntimeException', $e, '->getArguments() throws a \RuntimeException exception if it cannot determine the argument value'); + $this->assertInstanceOf(\RuntimeException::class, $e, '->getArguments() throws a \RuntimeException exception if it cannot determine the argument value'); } } From 41a1b8c907bcfcd583817f7f404b7e864c51e64d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Jan 2021 09:47:58 +0100 Subject: [PATCH 059/396] Use ::class keyword when possible --- DataCollector/ConfigDataCollector.php | 2 +- Kernel.php | 4 +-- Tests/Bundle/BundleTest.php | 2 +- Tests/CacheClearer/ChainCacheClearerTest.php | 2 +- Tests/CacheClearer/Psr6CacheClearerTest.php | 2 +- .../CacheWarmer/CacheWarmerAggregateTest.php | 2 +- Tests/CacheWarmer/CacheWarmerTest.php | 2 +- Tests/Config/FileLocatorTest.php | 6 ++--- .../NotTaggedControllerValueResolverTest.php | 8 +++--- .../ServiceValueResolverTest.php | 2 +- Tests/Controller/ArgumentResolverTest.php | 12 ++++----- .../ContainerControllerResolverTest.php | 4 +-- Tests/Controller/ControllerResolverTest.php | 4 +-- .../ArgumentMetadataTest.php | 2 +- .../DataCollector/ConfigDataCollectorTest.php | 2 +- .../DataCollector/LoggerDataCollectorTest.php | 6 ++--- .../RequestDataCollectorTest.php | 16 ++++++------ Tests/DataCollector/TimeDataCollectorTest.php | 2 +- Tests/Debug/TraceableEventDispatcherTest.php | 8 +++--- .../FragmentRendererPassTest.php | 2 +- .../LazyLoadingFragmentHandlerTest.php | 6 ++--- ...sterControllerArgumentLocatorsPassTest.php | 16 ++++++------ .../ResettableServicePassTest.php | 2 +- .../AddRequestFormatsListenerTest.php | 4 +-- .../DebugHandlersListenerTest.php | 8 +++--- Tests/EventListener/ErrorListenerTest.php | 10 +++---- Tests/EventListener/ExceptionListenerTest.php | 10 +++---- Tests/EventListener/FragmentListenerTest.php | 4 +-- .../EventListener/LocaleAwareListenerTest.php | 2 +- Tests/EventListener/LocaleListenerTest.php | 12 ++++----- Tests/EventListener/ProfilerListenerTest.php | 10 +++---- Tests/EventListener/ResponseListenerTest.php | 2 +- Tests/EventListener/RouterListenerTest.php | 26 +++++++++---------- Tests/EventListener/SurrogateListenerTest.php | 6 ++--- .../EventListener/TestSessionListenerTest.php | 4 +-- .../EventListener/TranslatorListenerTest.php | 4 +-- .../ValidateRequestListenerTest.php | 4 +-- Tests/Fragment/EsiFragmentRendererTest.php | 6 ++--- Tests/Fragment/FragmentHandlerTest.php | 10 +++---- .../Fragment/HIncludeFragmentRendererTest.php | 4 +-- Tests/Fragment/InlineFragmentRendererTest.php | 10 +++---- .../Fragment/RoutableFragmentRendererTest.php | 4 +-- Tests/Fragment/SsiFragmentRendererTest.php | 6 ++--- Tests/HttpCache/EsiTest.php | 6 ++--- Tests/HttpCache/HttpCacheTest.php | 8 +++--- Tests/HttpCache/SsiTest.php | 6 ++--- Tests/HttpCache/StoreTest.php | 4 +-- Tests/HttpKernelBrowserTest.php | 10 +++---- Tests/HttpKernelTest.php | 10 +++---- Tests/KernelTest.php | 26 +++++++++---------- Tests/Log/LoggerTest.php | 6 ++--- 51 files changed, 168 insertions(+), 168 deletions(-) diff --git a/DataCollector/ConfigDataCollector.php b/DataCollector/ConfigDataCollector.php index 179c7515c7..d4b298c594 100644 --- a/DataCollector/ConfigDataCollector.php +++ b/DataCollector/ConfigDataCollector.php @@ -69,7 +69,7 @@ public function collect(Request $request, Response $response/*, \Throwable $exce 'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a', 'php_version' => \PHP_VERSION, 'php_architecture' => \PHP_INT_SIZE * 8, - 'php_intl_locale' => class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', + 'php_intl_locale' => class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', 'php_timezone' => date_default_timezone_get(), 'xdebug_enabled' => \extension_loaded('xdebug'), 'apcu_enabled' => \extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN), diff --git a/Kernel.php b/Kernel.php index 22c3751b43..b91fc66a9f 100644 --- a/Kernel.php +++ b/Kernel.php @@ -748,7 +748,7 @@ protected function getContainerBuilder() if ($this instanceof CompilerPassInterface) { $container->addCompilerPass($this, PassConfig::TYPE_BEFORE_OPTIMIZATION, -10000); } - if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator')) { + if (class_exists(\ProxyManager\Configuration::class) && class_exists(RuntimeInstantiator::class)) { $container->setProxyInstantiator(new RuntimeInstantiator()); } @@ -766,7 +766,7 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container // cache the container $dumper = new PhpDumper($container); - if (class_exists('ProxyManager\Configuration') && class_exists('Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper')) { + if (class_exists(\ProxyManager\Configuration::class) && class_exists(ProxyDumper::class)) { $dumper->setProxyDumper(new ProxyDumper()); } diff --git a/Tests/Bundle/BundleTest.php b/Tests/Bundle/BundleTest.php index be03734dc4..0937eebcc4 100644 --- a/Tests/Bundle/BundleTest.php +++ b/Tests/Bundle/BundleTest.php @@ -30,7 +30,7 @@ public function testGetContainerExtension() public function testGetContainerExtensionWithInvalidClass() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface'); $bundle = new ExtensionNotValidBundle(); $bundle->getContainerExtension(); diff --git a/Tests/CacheClearer/ChainCacheClearerTest.php b/Tests/CacheClearer/ChainCacheClearerTest.php index b97559e321..a0b4bd8c41 100644 --- a/Tests/CacheClearer/ChainCacheClearerTest.php +++ b/Tests/CacheClearer/ChainCacheClearerTest.php @@ -41,6 +41,6 @@ public function testInjectClearersInConstructor() protected function getMockClearer() { - return $this->getMockBuilder('Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface')->getMock(); + return $this->getMockBuilder(\Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface::class)->getMock(); } } diff --git a/Tests/CacheClearer/Psr6CacheClearerTest.php b/Tests/CacheClearer/Psr6CacheClearerTest.php index 6e0a47e930..c7c683428e 100644 --- a/Tests/CacheClearer/Psr6CacheClearerTest.php +++ b/Tests/CacheClearer/Psr6CacheClearerTest.php @@ -39,7 +39,7 @@ public function testClearPool() public function testClearPoolThrowsExceptionOnUnreferencedPool() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Cache pool not found: "unknown"'); (new Psr6CacheClearer())->clearPool('unknown'); } diff --git a/Tests/CacheWarmer/CacheWarmerAggregateTest.php b/Tests/CacheWarmer/CacheWarmerAggregateTest.php index 4266c0a182..cf9493a295 100644 --- a/Tests/CacheWarmer/CacheWarmerAggregateTest.php +++ b/Tests/CacheWarmer/CacheWarmerAggregateTest.php @@ -70,7 +70,7 @@ public function testWarmupDoesNotCallWarmupOnOptionalWarmersWhenEnableOptionalWa protected function getCacheWarmerMock() { - $warmer = $this->getMockBuilder('Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface') + $warmer = $this->getMockBuilder(\Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface::class) ->disableOriginalConstructor() ->getMock(); diff --git a/Tests/CacheWarmer/CacheWarmerTest.php b/Tests/CacheWarmer/CacheWarmerTest.php index 8359d99f5f..c3286d0020 100644 --- a/Tests/CacheWarmer/CacheWarmerTest.php +++ b/Tests/CacheWarmer/CacheWarmerTest.php @@ -38,7 +38,7 @@ public function testWriteCacheFileCreatesTheFile() public function testWriteNonWritableCacheFileThrowsARuntimeException() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $nonWritableFile = '/this/file/is/very/probably/not/writable'; $warmer = new TestCacheWarmer($nonWritableFile); $warmer->warmUp(\dirname($nonWritableFile)); diff --git a/Tests/Config/FileLocatorTest.php b/Tests/Config/FileLocatorTest.php index 6bfaeca2f5..d992286752 100644 --- a/Tests/Config/FileLocatorTest.php +++ b/Tests/Config/FileLocatorTest.php @@ -18,7 +18,7 @@ class FileLocatorTest extends TestCase { public function testLocate() { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock(); $kernel ->expects($this->atLeastOnce()) ->method('locateResource') @@ -30,7 +30,7 @@ public function testLocate() $kernel ->expects($this->never()) ->method('locateResource'); - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $locator->locate('/some/path'); } @@ -39,7 +39,7 @@ public function testLocate() */ public function testLocateWithGlobalResourcePath() { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock(); $kernel ->expects($this->atLeastOnce()) ->method('locateResource') diff --git a/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php b/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php index 4f85b0f351..efb7322efa 100644 --- a/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php +++ b/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php @@ -55,7 +55,7 @@ public function testDoNotSupportEmptyController() public function testController() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); $this->expectExceptionMessage('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"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); @@ -66,7 +66,7 @@ public function testController() public function testControllerWithATrailingBackSlash() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); $this->expectExceptionMessage('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"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); @@ -77,7 +77,7 @@ public function testControllerWithATrailingBackSlash() public function testControllerWithMethodNameStartUppercase() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); $this->expectExceptionMessage('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"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); @@ -88,7 +88,7 @@ public function testControllerWithMethodNameStartUppercase() public function testControllerNameIsAnArray() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); $this->expectExceptionMessage('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"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); diff --git a/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php b/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php index 4036727bce..743eefa3e5 100644 --- a/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php +++ b/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php @@ -107,7 +107,7 @@ public function testControllerNameIsAnArray() public function testErrorIsTruncated() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); $this->expectExceptionMessage('Cannot autowire argument $dummy of "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyController::index()": it references class "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyService" but no such service exists.'); $container = new ContainerBuilder(); $container->addCompilerPass(new RegisterControllerArgumentLocatorsPass()); diff --git a/Tests/Controller/ArgumentResolverTest.php b/Tests/Controller/ArgumentResolverTest.php index c0ed800bb4..da521ff204 100644 --- a/Tests/Controller/ArgumentResolverTest.php +++ b/Tests/Controller/ArgumentResolverTest.php @@ -164,7 +164,7 @@ public function testGetVariadicArguments() public function testGetVariadicArgumentsWithoutArrayInRequest() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $request = Request::create('/'); $request->attributes->set('foo', 'foo'); $request->attributes->set('bar', 'foo'); @@ -175,7 +175,7 @@ public function testGetVariadicArgumentsWithoutArrayInRequest() public function testGetArgumentWithoutArray() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $factory = new ArgumentMetadataFactory(); $valueResolver = $this->getMockBuilder(ArgumentValueResolverInterface::class)->getMock(); $resolver = new ArgumentResolver($factory, [$valueResolver]); @@ -192,7 +192,7 @@ public function testGetArgumentWithoutArray() public function testIfExceptionIsThrownWhenMissingAnArgument() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $request = Request::create('/'); $controller = [$this, 'controllerWithFoo']; @@ -251,7 +251,7 @@ public function testGetSessionArgumentsWithInterface() public function testGetSessionMissMatchWithInterface() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $session = $this->getMockBuilder(SessionInterface::class)->getMock(); $request = Request::create('/'); $request->setSession($session); @@ -262,7 +262,7 @@ public function testGetSessionMissMatchWithInterface() public function testGetSessionMissMatchWithImplementation() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $session = new Session(new MockArraySessionStorage()); $request = Request::create('/'); $request->setSession($session); @@ -273,7 +273,7 @@ public function testGetSessionMissMatchWithImplementation() public function testGetSessionMissMatchOnNull() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $request = Request::create('/'); $controller = [$this, 'controllerWithExtendingSession']; diff --git a/Tests/Controller/ContainerControllerResolverTest.php b/Tests/Controller/ContainerControllerResolverTest.php index c39dac3ca5..7f4564688c 100644 --- a/Tests/Controller/ContainerControllerResolverTest.php +++ b/Tests/Controller/ContainerControllerResolverTest.php @@ -151,7 +151,7 @@ public function getControllers() public function testExceptionWhenUsingRemovedControllerServiceWithClassNameAsName() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Controller "Symfony\Component\HttpKernel\Tests\Controller\ControllerTestService" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?'); $container = $this->getMockBuilder(Container::class)->getMock(); $container->expects($this->once()) @@ -175,7 +175,7 @@ public function testExceptionWhenUsingRemovedControllerServiceWithClassNameAsNam public function testExceptionWhenUsingRemovedControllerService() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Controller "app.my_controller" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?'); $container = $this->getMockBuilder(Container::class)->getMock(); $container->expects($this->once()) diff --git a/Tests/Controller/ControllerResolverTest.php b/Tests/Controller/ControllerResolverTest.php index de6dfc2546..834f925c43 100644 --- a/Tests/Controller/ControllerResolverTest.php +++ b/Tests/Controller/ControllerResolverTest.php @@ -20,7 +20,7 @@ class ControllerResolverTest extends TestCase { public function testGetControllerWithoutControllerParameter() { - $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); + $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $logger->expects($this->once())->method('warning')->with('Unable to look for the controller as the "_controller" parameter is missing.'); $resolver = $this->createControllerResolver($logger); @@ -94,7 +94,7 @@ public function testGetControllerWithInvokableClass() public function testGetControllerOnObjectWithoutInvokeMethod() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $resolver = $this->createControllerResolver(); $request = Request::create('/'); diff --git a/Tests/ControllerMetadata/ArgumentMetadataTest.php b/Tests/ControllerMetadata/ArgumentMetadataTest.php index 5ce4b1f76b..fef6cd0002 100644 --- a/Tests/ControllerMetadata/ArgumentMetadataTest.php +++ b/Tests/ControllerMetadata/ArgumentMetadataTest.php @@ -34,7 +34,7 @@ public function testDefaultValueAvailable() public function testDefaultValueUnavailable() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $argument = new ArgumentMetadata('foo', 'string', false, false, null, false); $this->assertFalse($argument->isNullable()); diff --git a/Tests/DataCollector/ConfigDataCollectorTest.php b/Tests/DataCollector/ConfigDataCollectorTest.php index b7f2cd90f3..df6af954f3 100644 --- a/Tests/DataCollector/ConfigDataCollectorTest.php +++ b/Tests/DataCollector/ConfigDataCollectorTest.php @@ -33,7 +33,7 @@ public function testCollect() $this->assertMatchesRegularExpression('~^'.preg_quote($c->getPhpVersion(), '~').'~', \PHP_VERSION); $this->assertMatchesRegularExpression('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', \PHP_VERSION); $this->assertSame(\PHP_INT_SIZE * 8, $c->getPhpArchitecture()); - $this->assertSame(class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale()); + $this->assertSame(class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale()); $this->assertSame(date_default_timezone_get(), $c->getPhpTimezone()); $this->assertSame(Kernel::VERSION, $c->getSymfonyVersion()); $this->assertSame(4 === Kernel::MINOR_VERSION, $c->isSymfonyLts()); diff --git a/Tests/DataCollector/LoggerDataCollectorTest.php b/Tests/DataCollector/LoggerDataCollectorTest.php index de9364bb47..4204b8ef03 100644 --- a/Tests/DataCollector/LoggerDataCollectorTest.php +++ b/Tests/DataCollector/LoggerDataCollectorTest.php @@ -24,7 +24,7 @@ class LoggerDataCollectorTest extends TestCase public function testCollectWithUnexpectedFormat() { $logger = $this - ->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface') + ->getMockBuilder(DebugLoggerInterface::class) ->setMethods(['countErrors', 'getLogs', 'clear']) ->getMock(); $logger->expects($this->once())->method('countErrors')->willReturn(123); @@ -91,7 +91,7 @@ public function testWithSubRequest() public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount, $expectedScreamCount, $expectedPriorities = null) { $logger = $this - ->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface') + ->getMockBuilder(DebugLoggerInterface::class) ->setMethods(['countErrors', 'getLogs', 'clear']) ->getMock(); $logger->expects($this->once())->method('countErrors')->willReturn($nb); @@ -123,7 +123,7 @@ public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount public function testReset() { $logger = $this - ->getMockBuilder('Symfony\Component\HttpKernel\Log\DebugLoggerInterface') + ->getMockBuilder(DebugLoggerInterface::class) ->setMethods(['countErrors', 'getLogs', 'clear']) ->getMock(); $logger->expects($this->once())->method('clear'); diff --git a/Tests/DataCollector/RequestDataCollectorTest.php b/Tests/DataCollector/RequestDataCollectorTest.php index 852839c9b1..bb29b4ba52 100644 --- a/Tests/DataCollector/RequestDataCollectorTest.php +++ b/Tests/DataCollector/RequestDataCollectorTest.php @@ -39,12 +39,12 @@ public function testCollect() $attributes = $c->getRequestAttributes(); $this->assertSame('request', $c->getName()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestHeaders()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestServer()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestCookies()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $attributes); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestRequest()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestQuery()); + $this->assertInstanceOf(ParameterBag::class, $c->getRequestHeaders()); + $this->assertInstanceOf(ParameterBag::class, $c->getRequestServer()); + $this->assertInstanceOf(ParameterBag::class, $c->getRequestCookies()); + $this->assertInstanceOf(ParameterBag::class, $attributes); + $this->assertInstanceOf(ParameterBag::class, $c->getRequestRequest()); + $this->assertInstanceOf(ParameterBag::class, $c->getRequestQuery()); $this->assertInstanceOf(ParameterBag::class, $c->getResponseCookies()); $this->assertSame('html', $c->getFormat()); $this->assertEquals('foobar', $c->getRoute()); @@ -54,7 +54,7 @@ public function testCollect() $this->assertContainsEquals(__FILE__, $attributes->get('resource')); $this->assertSame('stdClass', $attributes->get('object')->getType()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getResponseHeaders()); + $this->assertInstanceOf(ParameterBag::class, $c->getResponseHeaders()); $this->assertSame('OK', $c->getStatusText()); $this->assertSame(200, $c->getStatusCode()); $this->assertSame('application/json', $c->getContentType()); @@ -288,7 +288,7 @@ protected function createResponse() */ protected function injectController($collector, $controller, $request) { - $resolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock(); + $resolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ControllerResolverInterface::class)->getMock(); $httpKernel = new HttpKernel(new EventDispatcher(), $resolver, null, $this->getMockBuilder(ArgumentResolverInterface::class)->getMock()); $event = new ControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST); $collector->onKernelController($event); diff --git a/Tests/DataCollector/TimeDataCollectorTest.php b/Tests/DataCollector/TimeDataCollectorTest.php index 9de9eb599a..ab231ac4c5 100644 --- a/Tests/DataCollector/TimeDataCollectorTest.php +++ b/Tests/DataCollector/TimeDataCollectorTest.php @@ -43,7 +43,7 @@ public function testCollect() $c->collect($request, new Response()); $this->assertEquals(0, $c->getStartTime()); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock(); $kernel->expects($this->once())->method('getStartTime')->willReturn(123456.0); $c = new TimeDataCollector($kernel); diff --git a/Tests/Debug/TraceableEventDispatcherTest.php b/Tests/Debug/TraceableEventDispatcherTest.php index cf8a3b8a1e..c4d42ec648 100644 --- a/Tests/Debug/TraceableEventDispatcherTest.php +++ b/Tests/Debug/TraceableEventDispatcherTest.php @@ -45,7 +45,7 @@ public function testStopwatchSections() public function testStopwatchCheckControllerOnRequestEvent() { - $stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch') + $stopwatch = $this->getMockBuilder(Stopwatch::class) ->setMethods(['isStarted']) ->getMock(); $stopwatch->expects($this->once()) @@ -61,7 +61,7 @@ public function testStopwatchCheckControllerOnRequestEvent() public function testStopwatchStopControllerOnRequestEvent() { - $stopwatch = $this->getMockBuilder('Symfony\Component\Stopwatch\Stopwatch') + $stopwatch = $this->getMockBuilder(Stopwatch::class) ->setMethods(['isStarted', 'stop']) ->getMock(); $stopwatch->expects($this->once()) @@ -110,9 +110,9 @@ public function testListenerCanRemoveItselfWhenExecuted() protected function getHttpKernel($dispatcher, $controller) { - $controllerResolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ControllerResolverInterface')->getMock(); + $controllerResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ControllerResolverInterface::class)->getMock(); $controllerResolver->expects($this->once())->method('getController')->willReturn($controller); - $argumentResolver = $this->getMockBuilder('Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface')->getMock(); + $argumentResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface::class)->getMock(); $argumentResolver->expects($this->once())->method('getArguments')->willReturn([]); return new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver); diff --git a/Tests/DependencyInjection/FragmentRendererPassTest.php b/Tests/DependencyInjection/FragmentRendererPassTest.php index 49567d40be..ab0efe32f5 100644 --- a/Tests/DependencyInjection/FragmentRendererPassTest.php +++ b/Tests/DependencyInjection/FragmentRendererPassTest.php @@ -29,7 +29,7 @@ class FragmentRendererPassTest extends TestCase */ public function testContentRendererWithoutInterface() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $builder = new ContainerBuilder(); $fragmentHandlerDefinition = $builder->register('fragment.handler'); $builder->register('my_content_renderer', 'Symfony\Component\DependencyInjection\Definition') diff --git a/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php b/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php index 39a1cb73b1..493178d470 100644 --- a/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php +++ b/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php @@ -20,14 +20,14 @@ class LazyLoadingFragmentHandlerTest extends TestCase { public function testRender() { - $renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock(); + $renderer = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface::class)->getMock(); $renderer->expects($this->once())->method('getName')->willReturn('foo'); $renderer->expects($this->any())->method('render')->willReturn(new Response()); - $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock(); + $requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock(); $requestStack->expects($this->any())->method('getCurrentRequest')->willReturn(Request::create('/')); - $container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock(); + $container = $this->getMockBuilder(\Psr\Container\ContainerInterface::class)->getMock(); $container->expects($this->once())->method('has')->with('foo')->willReturn(true); $container->expects($this->once())->method('get')->willReturn($renderer); diff --git a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php index a3b7969be1..8a65b4ff38 100644 --- a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php +++ b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php @@ -27,7 +27,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase { public function testInvalidClass() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Class "Symfony\Component\HttpKernel\Tests\DependencyInjection\NotFound" used for service "foo" cannot be found.'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -42,7 +42,7 @@ public function testInvalidClass() public function testNoAction() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Missing "action" attribute on tag "controller.service_arguments" {"argument":"bar"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -57,7 +57,7 @@ public function testNoAction() public function testNoArgument() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Missing "argument" attribute on tag "controller.service_arguments" {"action":"fooAction"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -72,7 +72,7 @@ public function testNoArgument() public function testNoService() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Missing "id" attribute on tag "controller.service_arguments" {"action":"fooAction","argument":"bar"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -87,7 +87,7 @@ public function testNoService() public function testInvalidMethod() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid "action" attribute on tag "controller.service_arguments" for service "foo": no public "barAction()" method found on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -102,7 +102,7 @@ public function testInvalidMethod() public function testInvalidArgument() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid "controller.service_arguments" tag for service "foo": method "fooAction()" has no "baz" argument on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -197,7 +197,7 @@ public function testSkipSetContainer() public function testExceptionOnNonExistentTypeHint() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClass". Did you forget to add a use statement?'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -211,7 +211,7 @@ public function testExceptionOnNonExistentTypeHint() public function testExceptionOnNonExistentTypeHintDifferentNamespace() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassDifferentNamespaceController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Acme\NonExistentClass".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); diff --git a/Tests/DependencyInjection/ResettableServicePassTest.php b/Tests/DependencyInjection/ResettableServicePassTest.php index 9dbc2b08a4..b28f90d362 100644 --- a/Tests/DependencyInjection/ResettableServicePassTest.php +++ b/Tests/DependencyInjection/ResettableServicePassTest.php @@ -57,7 +57,7 @@ public function testCompilerPass() public function testMissingMethod() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\RuntimeException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); $this->expectExceptionMessage('Tag "kernel.reset" requires the "method" attribute to be set.'); $container = new ContainerBuilder(); $container->register(ResettableService::class) diff --git a/Tests/EventListener/AddRequestFormatsListenerTest.php b/Tests/EventListener/AddRequestFormatsListenerTest.php index da8dc6fb0b..6c4459fc2a 100644 --- a/Tests/EventListener/AddRequestFormatsListenerTest.php +++ b/Tests/EventListener/AddRequestFormatsListenerTest.php @@ -41,7 +41,7 @@ protected function tearDown(): void public function testIsAnEventSubscriber() { - $this->assertInstanceOf('Symfony\Component\EventDispatcher\EventSubscriberInterface', $this->listener); + $this->assertInstanceOf(\Symfony\Component\EventDispatcher\EventSubscriberInterface::class, $this->listener); } public function testRegisteredEvent() @@ -66,7 +66,7 @@ public function testSetAdditionalFormats() protected function getRequestMock() { - return $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock(); + return $this->getMockBuilder(Request::class)->getMock(); } protected function getRequestEventMock(Request $request) diff --git a/Tests/EventListener/DebugHandlersListenerTest.php b/Tests/EventListener/DebugHandlersListenerTest.php index 7e336a1d6c..fb18d63fbe 100644 --- a/Tests/EventListener/DebugHandlersListenerTest.php +++ b/Tests/EventListener/DebugHandlersListenerTest.php @@ -35,7 +35,7 @@ class DebugHandlersListenerTest extends TestCase { public function testConfigure() { - $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); + $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); $userHandler = function () {}; $listener = new DebugHandlersListener($userHandler, $logger); $eHandler = new ErrorHandler(); @@ -67,7 +67,7 @@ public function testConfigureForHttpKernelWithNoTerminateWithException() $listener = new DebugHandlersListener(null); $eHandler = new ErrorHandler(); $event = new KernelEvent( - $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), + $this->getMockBuilder(HttpKernelInterface::class)->getMock(), Request::create('/'), HttpKernelInterface::MASTER_REQUEST ); @@ -91,7 +91,7 @@ public function testConsoleEvent() { $dispatcher = new EventDispatcher(); $listener = new DebugHandlersListener(null); - $app = $this->getMockBuilder('Symfony\Component\Console\Application')->getMock(); + $app = $this->getMockBuilder(Application::class)->getMock(); $app->expects($this->once())->method('getHelperSet')->willReturn(new HelperSet()); $command = new Command(__FUNCTION__); $command->setApplication($app); @@ -121,7 +121,7 @@ public function testConsoleEvent() } $xHandler = $eHandler->setExceptionHandler('var_dump'); - $this->assertInstanceOf('Closure', $xHandler); + $this->assertInstanceOf(\Closure::class, $xHandler); $app->expects($this->once()) ->method(method_exists(Application::class, 'renderThrowable') ? 'renderThrowable' : 'renderException'); diff --git a/Tests/EventListener/ErrorListenerTest.php b/Tests/EventListener/ErrorListenerTest.php index cdf6874f35..4428e3d1a6 100644 --- a/Tests/EventListener/ErrorListenerTest.php +++ b/Tests/EventListener/ErrorListenerTest.php @@ -99,7 +99,7 @@ public function testHandleWithLogger($event, $event2) public function provider() { - if (!class_exists('Symfony\Component\HttpFoundation\Request')) { + if (!class_exists(Request::class)) { return [[null, null]]; } @@ -115,9 +115,9 @@ public function provider() public function testSubRequestFormat() { - $listener = new ErrorListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock()); + $listener = new ErrorListener('foo', $this->getMockBuilder(LoggerInterface::class)->getMock()); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); @@ -135,12 +135,12 @@ public function testSubRequestFormat() public function testCSPHeaderIsRemoved() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); - $listener = new ErrorListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(), true); + $listener = new ErrorListener('foo', $this->getMockBuilder(LoggerInterface::class)->getMock(), true); $dispatcher->addSubscriber($listener); diff --git a/Tests/EventListener/ExceptionListenerTest.php b/Tests/EventListener/ExceptionListenerTest.php index 28113c14af..91ff62d906 100644 --- a/Tests/EventListener/ExceptionListenerTest.php +++ b/Tests/EventListener/ExceptionListenerTest.php @@ -96,7 +96,7 @@ public function testHandleWithLogger($event, $event2) public function provider() { - if (!class_exists('Symfony\Component\HttpFoundation\Request')) { + if (!class_exists(Request::class)) { return [[null, null]]; } @@ -112,9 +112,9 @@ public function provider() public function testSubRequestFormat() { - $listener = new ExceptionListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock()); + $listener = new ExceptionListener('foo', $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock()); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); @@ -132,12 +132,12 @@ public function testSubRequestFormat() public function testCSPHeaderIsRemoved() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); - $listener = new ExceptionListener('foo', $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(), true); + $listener = new ExceptionListener('foo', $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(), true); $dispatcher->addSubscriber($listener); diff --git a/Tests/EventListener/FragmentListenerTest.php b/Tests/EventListener/FragmentListenerTest.php index 5b045a8fc4..e0b857debd 100644 --- a/Tests/EventListener/FragmentListenerTest.php +++ b/Tests/EventListener/FragmentListenerTest.php @@ -52,7 +52,7 @@ public function testOnlyTriggeredIfControllerWasNotDefinedYet() public function testAccessDeniedWithNonSafeMethods() { - $this->expectException('Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException'); + $this->expectException(\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException::class); $request = Request::create('http://example.com/_fragment', 'POST'); $listener = new FragmentListener(new UriSigner('foo')); @@ -63,7 +63,7 @@ public function testAccessDeniedWithNonSafeMethods() public function testAccessDeniedWithWrongSignature() { - $this->expectException('Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException'); + $this->expectException(\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException::class); $request = Request::create('http://example.com/_fragment', 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']); $listener = new FragmentListener(new UriSigner('foo')); diff --git a/Tests/EventListener/LocaleAwareListenerTest.php b/Tests/EventListener/LocaleAwareListenerTest.php index 0064429048..0d14e5a987 100644 --- a/Tests/EventListener/LocaleAwareListenerTest.php +++ b/Tests/EventListener/LocaleAwareListenerTest.php @@ -110,7 +110,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest() private function createHttpKernel() { - return $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + return $this->getMockBuilder(HttpKernelInterface::class)->getMock(); } private function createRequest($locale) diff --git a/Tests/EventListener/LocaleListenerTest.php b/Tests/EventListener/LocaleListenerTest.php index cb502a89ee..705600d70e 100644 --- a/Tests/EventListener/LocaleListenerTest.php +++ b/Tests/EventListener/LocaleListenerTest.php @@ -26,7 +26,7 @@ class LocaleListenerTest extends TestCase protected function setUp(): void { - $this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->disableOriginalConstructor()->getMock(); + $this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->disableOriginalConstructor()->getMock(); } public function testIsAnEventSubscriber() @@ -70,10 +70,10 @@ public function testLocaleFromRequestAttribute() public function testLocaleSetForRoutingContext() { // the request context is updated - $context = $this->getMockBuilder('Symfony\Component\Routing\RequestContext')->getMock(); + $context = $this->getMockBuilder(\Symfony\Component\Routing\RequestContext::class)->getMock(); $context->expects($this->once())->method('setParameter')->with('_locale', 'es'); - $router = $this->getMockBuilder('Symfony\Component\Routing\Router')->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); + $router = $this->getMockBuilder(\Symfony\Component\Routing\Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); $router->expects($this->once())->method('getContext')->willReturn($context); $request = Request::create('/'); @@ -86,10 +86,10 @@ public function testLocaleSetForRoutingContext() public function testRouterResetWithParentRequestOnKernelFinishRequest() { // the request context is updated - $context = $this->getMockBuilder('Symfony\Component\Routing\RequestContext')->getMock(); + $context = $this->getMockBuilder(\Symfony\Component\Routing\RequestContext::class)->getMock(); $context->expects($this->once())->method('setParameter')->with('_locale', 'es'); - $router = $this->getMockBuilder('Symfony\Component\Routing\Router')->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); + $router = $this->getMockBuilder(\Symfony\Component\Routing\Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); $router->expects($this->once())->method('getContext')->willReturn($context); $parentRequest = Request::create('/'); @@ -116,6 +116,6 @@ public function testRequestLocaleIsNotOverridden() private function getEvent(Request $request): RequestEvent { - return new RequestEvent($this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); + return new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); } } diff --git a/Tests/EventListener/ProfilerListenerTest.php b/Tests/EventListener/ProfilerListenerTest.php index 3aaff12316..4b076ef17d 100644 --- a/Tests/EventListener/ProfilerListenerTest.php +++ b/Tests/EventListener/ProfilerListenerTest.php @@ -30,7 +30,7 @@ public function testKernelTerminate() { $profile = new Profile('token'); - $profiler = $this->getMockBuilder('Symfony\Component\HttpKernel\Profiler\Profiler') + $profiler = $this->getMockBuilder(\Symfony\Component\HttpKernel\Profiler\Profiler::class) ->disableOriginalConstructor() ->getMock(); @@ -38,17 +38,17 @@ public function testKernelTerminate() ->method('collect') ->willReturn($profile); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock(); - $masterRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') + $masterRequest = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Request::class) ->disableOriginalConstructor() ->getMock(); - $subRequest = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') + $subRequest = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Request::class) ->disableOriginalConstructor() ->getMock(); - $response = $this->getMockBuilder('Symfony\Component\HttpFoundation\Response') + $response = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Response::class) ->disableOriginalConstructor() ->getMock(); diff --git a/Tests/EventListener/ResponseListenerTest.php b/Tests/EventListener/ResponseListenerTest.php index 1aaa64bc89..31cfa38477 100644 --- a/Tests/EventListener/ResponseListenerTest.php +++ b/Tests/EventListener/ResponseListenerTest.php @@ -32,7 +32,7 @@ protected function setUp(): void $listener = new ResponseListener('UTF-8'); $this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); - $this->kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $this->kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); } protected function tearDown(): void diff --git a/Tests/EventListener/RouterListenerTest.php b/Tests/EventListener/RouterListenerTest.php index 2c1e7721b4..59e63deea8 100644 --- a/Tests/EventListener/RouterListenerTest.php +++ b/Tests/EventListener/RouterListenerTest.php @@ -33,7 +33,7 @@ class RouterListenerTest extends TestCase protected function setUp(): void { - $this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->disableOriginalConstructor()->getMock(); + $this->requestStack = $this->getMockBuilder(RequestStack::class)->disableOriginalConstructor()->getMock(); } /** @@ -41,7 +41,7 @@ protected function setUp(): void */ public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHttpPort, $expectedHttpsPort) { - $urlMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\UrlMatcherInterface') + $urlMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\UrlMatcherInterface::class) ->disableOriginalConstructor() ->getMock(); $context = new RequestContext(); @@ -81,7 +81,7 @@ private function createRequestEventForUri(string $uri): RequestEvent public function testInvalidMatcher() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); new RouterListener(new \stdClass(), $this->requestStack); } @@ -91,10 +91,10 @@ public function testRequestMatcher() $request = Request::create('http://localhost/'); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); + $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); $requestMatcher->expects($this->once()) ->method('matchRequest') - ->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request')) + ->with($this->isInstanceOf(Request::class)) ->willReturn([]); $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext()); @@ -107,10 +107,10 @@ public function testSubRequestWithDifferentMethod() $request = Request::create('http://localhost/', 'post'); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); + $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); $requestMatcher->expects($this->any()) ->method('matchRequest') - ->with($this->isInstanceOf('Symfony\Component\HttpFoundation\Request')) + ->with($this->isInstanceOf(Request::class)) ->willReturn([]); $context = new RequestContext(); @@ -133,12 +133,12 @@ public function testSubRequestWithDifferentMethod() */ public function testLoggingParameter($parameter, $log, $parameters) { - $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); + $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); $requestMatcher->expects($this->once()) ->method('matchRequest') ->willReturn($parameter); - $logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock(); + $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); $logger->expects($this->once()) ->method('info') ->with($this->equalTo($log), $this->equalTo($parameters)); @@ -162,7 +162,7 @@ public function testWithBadRequest() { $requestStack = new RequestStack(); - $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); + $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); $requestMatcher->expects($this->never())->method('matchRequest'); $dispatcher = new EventDispatcher(); @@ -184,7 +184,7 @@ public function testNoRoutingConfigurationResponse() { $requestStack = new RequestStack(); - $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); + $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); $requestMatcher ->expects($this->once()) ->method('matchRequest') @@ -204,12 +204,12 @@ public function testNoRoutingConfigurationResponse() public function testRequestWithBadHost() { - $this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException'); + $this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class); $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = Request::create('http://bad host %22/'); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $requestMatcher = $this->getMockBuilder('Symfony\Component\Routing\Matcher\RequestMatcherInterface')->getMock(); + $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext()); $listener->onKernelRequest($event); diff --git a/Tests/EventListener/SurrogateListenerTest.php b/Tests/EventListener/SurrogateListenerTest.php index fc51de252e..e4b8b2d558 100644 --- a/Tests/EventListener/SurrogateListenerTest.php +++ b/Tests/EventListener/SurrogateListenerTest.php @@ -26,7 +26,7 @@ class SurrogateListenerTest extends TestCase public function testFilterDoesNothingForSubRequests() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $response = new Response('foo '); $listener = new SurrogateListener(new Esi()); @@ -40,7 +40,7 @@ public function testFilterDoesNothingForSubRequests() public function testFilterWhenThereIsSomeEsiIncludes() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $response = new Response('foo '); $listener = new SurrogateListener(new Esi()); @@ -54,7 +54,7 @@ public function testFilterWhenThereIsSomeEsiIncludes() public function testFilterWhenThereIsNoEsiIncludes() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $response = new Response('foo'); $listener = new SurrogateListener(new Esi()); diff --git a/Tests/EventListener/TestSessionListenerTest.php b/Tests/EventListener/TestSessionListenerTest.php index 1d9ea37977..e0a5cc69da 100644 --- a/Tests/EventListener/TestSessionListenerTest.php +++ b/Tests/EventListener/TestSessionListenerTest.php @@ -42,7 +42,7 @@ class TestSessionListenerTest extends TestCase protected function setUp(): void { - $this->listener = $this->getMockForAbstractClass('Symfony\Component\HttpKernel\EventListener\AbstractTestSessionListener'); + $this->listener = $this->getMockForAbstractClass(\Symfony\Component\HttpKernel\EventListener\AbstractTestSessionListener::class); $this->session = $this->getSession(); $this->listener->expects($this->any()) ->method('getSession') @@ -209,7 +209,7 @@ private function fixSessionId($sessionId) private function getSession() { - $mock = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\Session') + $mock = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\Session::class) ->disableOriginalConstructor() ->getMock(); diff --git a/Tests/EventListener/TranslatorListenerTest.php b/Tests/EventListener/TranslatorListenerTest.php index e5447079dc..1fe4d1f2fa 100644 --- a/Tests/EventListener/TranslatorListenerTest.php +++ b/Tests/EventListener/TranslatorListenerTest.php @@ -31,7 +31,7 @@ class TranslatorListenerTest extends TestCase protected function setUp(): void { $this->translator = $this->getMockBuilder(LocaleAwareInterface::class)->getMock(); - $this->requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock(); + $this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock(); $this->listener = new TranslatorListener($this->translator, $this->requestStack); } @@ -105,7 +105,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest() private function createHttpKernel() { - return $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + return $this->getMockBuilder(HttpKernelInterface::class)->getMock(); } private function createRequest($locale) diff --git a/Tests/EventListener/ValidateRequestListenerTest.php b/Tests/EventListener/ValidateRequestListenerTest.php index 7cec68143b..96b686d91b 100644 --- a/Tests/EventListener/ValidateRequestListenerTest.php +++ b/Tests/EventListener/ValidateRequestListenerTest.php @@ -28,9 +28,9 @@ protected function tearDown(): void public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps() { - $this->expectException('Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException'); + $this->expectException(\Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException::class); $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); $request = new Request(); $request->setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_FOR | Request::HEADER_FORWARDED); diff --git a/Tests/Fragment/EsiFragmentRendererTest.php b/Tests/Fragment/EsiFragmentRendererTest.php index df74ade154..c9af77149c 100644 --- a/Tests/Fragment/EsiFragmentRendererTest.php +++ b/Tests/Fragment/EsiFragmentRendererTest.php @@ -67,7 +67,7 @@ public function testRenderControllerReference() public function testRenderControllerReferenceWithoutSignerThrowsException() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy()); $request = Request::create('/'); @@ -79,7 +79,7 @@ public function testRenderControllerReferenceWithoutSignerThrowsException() public function testRenderAltControllerReferenceWithoutSignerThrowsException() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $strategy = new EsiFragmentRenderer(new Esi(), $this->getInlineStrategy()); $request = Request::create('/'); @@ -91,7 +91,7 @@ public function testRenderAltControllerReferenceWithoutSignerThrowsException() private function getInlineStrategy($called = false) { - $inline = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer')->disableOriginalConstructor()->getMock(); + $inline = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer::class)->disableOriginalConstructor()->getMock(); if ($called) { $inline->expects($this->once())->method('render'); diff --git a/Tests/Fragment/FragmentHandlerTest.php b/Tests/Fragment/FragmentHandlerTest.php index 15e543a214..fa011c8f29 100644 --- a/Tests/Fragment/FragmentHandlerTest.php +++ b/Tests/Fragment/FragmentHandlerTest.php @@ -25,7 +25,7 @@ class FragmentHandlerTest extends TestCase protected function setUp(): void { - $this->requestStack = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack') + $this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class) ->disableOriginalConstructor() ->getMock() ; @@ -38,14 +38,14 @@ protected function setUp(): void public function testRenderWhenRendererDoesNotExist() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $handler = new FragmentHandler($this->requestStack); $handler->render('/', 'foo'); } public function testRenderWithUnknownRenderer() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $handler = $this->getHandler($this->returnValue(new Response('foo'))); $handler->render('/', 'bar'); @@ -53,7 +53,7 @@ public function testRenderWithUnknownRenderer() public function testDeliverWithUnsuccessfulResponse() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Error when rendering "http://localhost/" (Status code is 404).'); $handler = $this->getHandler($this->returnValue(new Response('foo', 404))); @@ -69,7 +69,7 @@ public function testRender() protected function getHandler($returnValue, $arguments = []) { - $renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock(); + $renderer = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface::class)->getMock(); $renderer ->expects($this->any()) ->method('getName') diff --git a/Tests/Fragment/HIncludeFragmentRendererTest.php b/Tests/Fragment/HIncludeFragmentRendererTest.php index cdef37565b..ae1cb15516 100644 --- a/Tests/Fragment/HIncludeFragmentRendererTest.php +++ b/Tests/Fragment/HIncludeFragmentRendererTest.php @@ -23,7 +23,7 @@ class HIncludeFragmentRendererTest extends TestCase { public function testRenderExceptionWhenControllerAndNoSigner() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $strategy = new HIncludeFragmentRenderer(); $strategy->render(new ControllerReference('main_controller', [], []), Request::create('/')); } @@ -86,7 +86,7 @@ public function testRenderWithTwigAndDefaultText() */ public function testRenderWithDefaultTextLegacy() { - $engine = $this->getMockBuilder('Symfony\\Component\\Templating\\EngineInterface')->getMock(); + $engine = $this->getMockBuilder(\Symfony\Component\Templating\EngineInterface::class)->getMock(); $engine->expects($this->once()) ->method('exists') ->with('default') diff --git a/Tests/Fragment/InlineFragmentRendererTest.php b/Tests/Fragment/InlineFragmentRendererTest.php index a064a76c7d..c25297dbe4 100644 --- a/Tests/Fragment/InlineFragmentRendererTest.php +++ b/Tests/Fragment/InlineFragmentRendererTest.php @@ -71,7 +71,7 @@ public function testRenderWithTrustedHeaderDisabled() public function testRenderExceptionNoIgnoreErrors() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); $dispatcher->expects($this->never())->method('dispatch'); @@ -106,7 +106,7 @@ public function testRenderExceptionIgnoreErrorsWithAlt() private function getKernel($returnValue) { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock(); $kernel ->expects($this->any()) ->method('handle') @@ -118,7 +118,7 @@ private function getKernel($returnValue) public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() { - $controllerResolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface')->getMock(); + $controllerResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ControllerResolverInterface::class)->getMock(); $controllerResolver ->expects($this->once()) ->method('getController') @@ -129,7 +129,7 @@ public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() }) ; - $argumentResolver = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Controller\\ArgumentResolverInterface')->getMock(); + $argumentResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface::class)->getMock(); $argumentResolver ->expects($this->once()) ->method('getArguments') @@ -258,7 +258,7 @@ public function testIpAddressOfRangedTrustedProxyIsSetAsRemote() */ private function getKernelExpectingRequest(Request $request, $strict = false) { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); + $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock(); $kernel ->expects($this->once()) ->method('handle') diff --git a/Tests/Fragment/RoutableFragmentRendererTest.php b/Tests/Fragment/RoutableFragmentRendererTest.php index 151adb0e97..5980284afe 100644 --- a/Tests/Fragment/RoutableFragmentRendererTest.php +++ b/Tests/Fragment/RoutableFragmentRendererTest.php @@ -60,7 +60,7 @@ public function testGenerateFragmentUriWithARequest() */ public function testGenerateFragmentUriWithNonScalar($controller) { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->callGenerateFragmentUriMethod($controller, Request::create('/')); } @@ -74,7 +74,7 @@ public function getGenerateFragmentUriDataWithNonScalar() private function callGenerateFragmentUriMethod(ControllerReference $reference, Request $request, $absolute = false) { - $renderer = $this->getMockForAbstractClass('Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer'); + $renderer = $this->getMockForAbstractClass(\Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer::class); $r = new \ReflectionObject($renderer); $m = $r->getMethod('generateFragmentUri'); $m->setAccessible(true); diff --git a/Tests/Fragment/SsiFragmentRendererTest.php b/Tests/Fragment/SsiFragmentRendererTest.php index df30e67727..db203f91de 100644 --- a/Tests/Fragment/SsiFragmentRendererTest.php +++ b/Tests/Fragment/SsiFragmentRendererTest.php @@ -58,7 +58,7 @@ public function testRenderControllerReference() public function testRenderControllerReferenceWithoutSignerThrowsException() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy()); $request = Request::create('/'); @@ -70,7 +70,7 @@ public function testRenderControllerReferenceWithoutSignerThrowsException() public function testRenderAltControllerReferenceWithoutSignerThrowsException() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $strategy = new SsiFragmentRenderer(new Ssi(), $this->getInlineStrategy()); $request = Request::create('/'); @@ -82,7 +82,7 @@ public function testRenderAltControllerReferenceWithoutSignerThrowsException() private function getInlineStrategy($called = false) { - $inline = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer')->disableOriginalConstructor()->getMock(); + $inline = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer::class)->disableOriginalConstructor()->getMock(); if ($called) { $inline->expects($this->once())->method('render'); diff --git a/Tests/HttpCache/EsiTest.php b/Tests/HttpCache/EsiTest.php index cdf729e331..5246721a64 100644 --- a/Tests/HttpCache/EsiTest.php +++ b/Tests/HttpCache/EsiTest.php @@ -155,7 +155,7 @@ public function testProcessEscapesPhpTags() public function testProcessWhenNoSrcInAnEsi() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $esi = new Esi(); $request = Request::create('/'); @@ -193,7 +193,7 @@ public function testHandle() public function testHandleWhenResponseIsNot200() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $esi = new Esi(); $response = new Response('foo'); $response->setStatusCode(404); @@ -222,7 +222,7 @@ public function testHandleWhenResponseIsNot200AndAltIsPresent() protected function getCache($request, $response) { - $cache = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpCache\HttpCache')->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); + $cache = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); $cache->expects($this->any()) ->method('getRequest') ->willReturn($request) diff --git a/Tests/HttpCache/HttpCacheTest.php b/Tests/HttpCache/HttpCacheTest.php index 6ad64e4791..932f46c6ef 100644 --- a/Tests/HttpCache/HttpCacheTest.php +++ b/Tests/HttpCache/HttpCacheTest.php @@ -25,7 +25,7 @@ class HttpCacheTest extends HttpCacheTestCase { public function testTerminateDelegatesTerminationOnlyForTerminableInterface() { - $storeMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpCache\\StoreInterface') + $storeMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\StoreInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -37,7 +37,7 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface() $this->assertFalse($kernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface'); // implements TerminableInterface - $kernelMock = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel') + $kernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\Kernel::class) ->disableOriginalConstructor() ->setMethods(['terminate', 'registerBundles', 'registerContainerConfiguration']) ->getMock(); @@ -1488,8 +1488,8 @@ public function testDoesNotCacheOptionsRequest() public function testUsesOriginalRequestForSurrogate() { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernelInterface')->getMock(); - $store = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpCache\StoreInterface')->getMock(); + $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $store = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\StoreInterface::class)->getMock(); $kernel ->expects($this->exactly(2)) diff --git a/Tests/HttpCache/SsiTest.php b/Tests/HttpCache/SsiTest.php index 3d68052cdc..23c7410a28 100644 --- a/Tests/HttpCache/SsiTest.php +++ b/Tests/HttpCache/SsiTest.php @@ -122,7 +122,7 @@ public function testProcessEscapesPhpTags() public function testProcessWhenNoSrcInAnSsi() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $ssi = new Ssi(); $request = Request::create('/'); @@ -160,7 +160,7 @@ public function testHandle() public function testHandleWhenResponseIsNot200() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $ssi = new Ssi(); $response = new Response('foo'); $response->setStatusCode(404); @@ -189,7 +189,7 @@ public function testHandleWhenResponseIsNot200AndAltIsPresent() protected function getCache($request, $response) { - $cache = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpCache\HttpCache')->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); + $cache = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); $cache->expects($this->any()) ->method('getRequest') ->willReturn($request) diff --git a/Tests/HttpCache/StoreTest.php b/Tests/HttpCache/StoreTest.php index fc1ef64663..da1f649127 100644 --- a/Tests/HttpCache/StoreTest.php +++ b/Tests/HttpCache/StoreTest.php @@ -157,7 +157,7 @@ public function testFindsAStoredEntryWithLookup() $response = $this->store->lookup($this->request); $this->assertNotNull($response); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); + $this->assertInstanceOf(Response::class, $response); } public function testDoesNotFindAnEntryWithLookupWhenNoneExists() @@ -206,7 +206,7 @@ public function testInvalidatesMetaAndEntityStoreEntriesWithInvalidate() $this->storeSimpleEntry(); $this->store->invalidate($this->request); $response = $this->store->lookup($this->request); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response); + $this->assertInstanceOf(Response::class, $response); $this->assertFalse($response->isFresh()); } diff --git a/Tests/HttpKernelBrowserTest.php b/Tests/HttpKernelBrowserTest.php index 4d4fe5ae72..eab6c5221c 100644 --- a/Tests/HttpKernelBrowserTest.php +++ b/Tests/HttpKernelBrowserTest.php @@ -30,10 +30,10 @@ public function testDoRequest() $client->request('GET', '/'); $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request'); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Request', $client->getInternalRequest()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\Request', $client->getRequest()); - $this->assertInstanceOf('Symfony\Component\BrowserKit\Response', $client->getInternalResponse()); - $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $client->getResponse()); + $this->assertInstanceOf(\Symfony\Component\BrowserKit\Request::class, $client->getInternalRequest()); + $this->assertInstanceOf(\Symfony\Component\HttpFoundation\Request::class, $client->getRequest()); + $this->assertInstanceOf(\Symfony\Component\BrowserKit\Response::class, $client->getInternalResponse()); + $this->assertInstanceOf(Response::class, $client->getResponse()); $client->request('GET', 'http://www.example.com/'); $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request'); @@ -148,7 +148,7 @@ public function testUploadedFileWhenSizeExceedsUploadMaxFileSize() $client = new HttpKernelBrowser($kernel); $file = $this - ->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile') + ->getMockBuilder(UploadedFile::class) ->setConstructorArgs([$source, 'original', 'mime/original', \UPLOAD_ERR_OK, true]) ->setMethods(['getSize', 'getClientSize']) ->getMock() diff --git a/Tests/HttpKernelTest.php b/Tests/HttpKernelTest.php index 7a5b0b8c60..5c954261b6 100644 --- a/Tests/HttpKernelTest.php +++ b/Tests/HttpKernelTest.php @@ -31,7 +31,7 @@ class HttpKernelTest extends TestCase { public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }); $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true); @@ -39,7 +39,7 @@ public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue() public function testHandleWhenControllerThrowsAnExceptionAndCatchIsFalseAndNoListenerIsRegistered() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }); $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false); @@ -156,7 +156,7 @@ public function testHandleWhenAListenerReturnsAResponse() public function testHandleWhenNoControllerIsFound() { - $this->expectException('Symfony\Component\HttpKernel\Exception\NotFoundHttpException'); + $this->expectException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class); $dispatcher = new EventDispatcher(); $kernel = $this->getHttpKernel($dispatcher, false); @@ -303,7 +303,7 @@ public function testVerifyRequestStackPushPopDuringHandle() { $request = new Request(); - $stack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->setMethods(['push', 'pop'])->getMock(); + $stack = $this->getMockBuilder(RequestStack::class)->setMethods(['push', 'pop'])->getMock(); $stack->expects($this->once())->method('push')->with($this->equalTo($request)); $stack->expects($this->once())->method('pop'); @@ -315,7 +315,7 @@ public function testVerifyRequestStackPushPopDuringHandle() public function testInconsistentClientIpsOnMasterRequests() { - $this->expectException('Symfony\Component\HttpKernel\Exception\BadRequestHttpException'); + $this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class); $request = new Request(); $request->setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_FOR | Request::HEADER_FORWARDED); $request->server->set('REMOTE_ADDR', '1.1.1.1'); diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index 18974a720b..570e6f0298 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -77,7 +77,7 @@ public function testClone() public function testClassNameValidityGetter() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The environment "test.env" contains invalid characters, it can only contain characters allowed in PHP class names.'); // We check the classname that will be generated by using a $env that // contains invalid characters. @@ -125,7 +125,7 @@ public function testBootInitializesBundlesAndContainer() public function testBootSetsTheContainerToTheBundles() { - $bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock(); + $bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock(); $bundle->expects($this->once()) ->method('setContainer'); @@ -167,7 +167,7 @@ public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce() public function testShutdownCallsShutdownOnAllBundles() { - $bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock(); + $bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock(); $bundle->expects($this->once()) ->method('shutdown'); @@ -179,7 +179,7 @@ public function testShutdownCallsShutdownOnAllBundles() public function testShutdownGivesNullContainerToAllBundles() { - $bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock(); + $bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock(); $bundle->expects($this->exactly(2)) ->method('setContainer') ->withConsecutive( @@ -202,7 +202,7 @@ public function testHandleCallsHandleOnHttpKernel() $catch = true; $request = new Request(); - $httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel') + $httpKernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernel::class) ->disableOriginalConstructor() ->getMock(); $httpKernelMock @@ -224,7 +224,7 @@ public function testHandleBootsTheKernel() $catch = true; $request = new Request(); - $httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel') + $httpKernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernel::class) ->disableOriginalConstructor() ->getMock(); @@ -381,25 +381,25 @@ public function testSerialize() public function testLocateResourceThrowsExceptionWhenNameIsNotValid() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->getKernel()->locateResource('Foo'); } public function testLocateResourceThrowsExceptionWhenNameIsUnsafe() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $this->getKernel()->locateResource('@FooBundle/../bar'); } public function testLocateResourceThrowsExceptionWhenBundleDoesNotExist() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $this->getKernel()->locateResource('@FooBundle/config/routing.xml'); } public function testLocateResourceThrowsExceptionWhenResourceDoesNotExist() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $kernel = $this->getKernel(['getBundle']); $kernel ->expects($this->once()) @@ -501,7 +501,7 @@ public function testLocateResourceOnDirectories() public function testInitializeBundleThrowsExceptionWhenRegisteringTwoBundlesWithTheSameName() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $this->expectExceptionMessage('Trying to register two bundles with the same name "DuplicateName"'); $fooBundle = $this->getBundle(__DIR__.'/Fixtures/FooBundle', null, 'FooBundle', 'DuplicateName'); $barBundle = $this->getBundle(__DIR__.'/Fixtures/BarBundle', null, 'BarBundle', 'DuplicateName'); @@ -547,7 +547,7 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface() $this->assertFalse($httpKernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface'); // implements TerminableInterface - $httpKernelMock = $this->getMockBuilder('Symfony\Component\HttpKernel\HttpKernel') + $httpKernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernel::class) ->disableOriginalConstructor() ->setMethods(['terminate']) ->getMock(); @@ -690,7 +690,7 @@ public function getContainerClass(): string protected function getBundle($dir = null, $parent = null, $className = null, $bundleName = null): BundleInterface { $bundle = $this - ->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface') + ->getMockBuilder(BundleInterface::class) ->setMethods(['getPath', 'getName']) ->disableOriginalConstructor() ; diff --git a/Tests/Log/LoggerTest.php b/Tests/Log/LoggerTest.php index 607ab31cb8..fb2b43cc82 100644 --- a/Tests/Log/LoggerTest.php +++ b/Tests/Log/LoggerTest.php @@ -109,19 +109,19 @@ public function testLogLevelDisabled() public function testThrowsOnInvalidLevel() { - $this->expectException('Psr\Log\InvalidArgumentException'); + $this->expectException(\Psr\Log\InvalidArgumentException::class); $this->logger->log('invalid level', 'Foo'); } public function testThrowsOnInvalidMinLevel() { - $this->expectException('Psr\Log\InvalidArgumentException'); + $this->expectException(\Psr\Log\InvalidArgumentException::class); new Logger('invalid'); } public function testInvalidOutput() { - $this->expectException('Psr\Log\InvalidArgumentException'); + $this->expectException(\Psr\Log\InvalidArgumentException::class); new Logger(LogLevel::DEBUG, '/'); } From 95be53e07c46bae4f8c20d2753cead1ba8aceeb6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Jan 2021 11:11:08 +0100 Subject: [PATCH 060/396] Use ::class keyword when possible --- Tests/Config/FileLocatorTest.php | 4 ++-- ...egisterControllerArgumentLocatorsPassTest.php | 16 ++++++++-------- Tests/Fragment/HIncludeFragmentRendererTest.php | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Tests/Config/FileLocatorTest.php b/Tests/Config/FileLocatorTest.php index 9f1d093b52..43bf5bce87 100644 --- a/Tests/Config/FileLocatorTest.php +++ b/Tests/Config/FileLocatorTest.php @@ -18,7 +18,7 @@ class FileLocatorTest extends TestCase { public function testLocate() { - $kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock(); + $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock(); $kernel ->expects($this->atLeastOnce()) ->method('locateResource') @@ -30,7 +30,7 @@ public function testLocate() $kernel ->expects($this->never()) ->method('locateResource'); - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $locator->locate('/some/path'); } } diff --git a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php index 2cda6c4f56..af58576161 100644 --- a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php +++ b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php @@ -27,7 +27,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase { public function testInvalidClass() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Class "Symfony\Component\HttpKernel\Tests\DependencyInjection\NotFound" used for service "foo" cannot be found.'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -42,7 +42,7 @@ public function testInvalidClass() public function testNoAction() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Missing "action" attribute on tag "controller.service_arguments" {"argument":"bar"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -57,7 +57,7 @@ public function testNoAction() public function testNoArgument() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Missing "argument" attribute on tag "controller.service_arguments" {"action":"fooAction"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -72,7 +72,7 @@ public function testNoArgument() public function testNoService() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Missing "id" attribute on tag "controller.service_arguments" {"action":"fooAction","argument":"bar"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -87,7 +87,7 @@ public function testNoService() public function testInvalidMethod() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid "action" attribute on tag "controller.service_arguments" for service "foo": no public "barAction()" method found on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -102,7 +102,7 @@ public function testInvalidMethod() public function testInvalidArgument() { - $this->expectException('Symfony\Component\DependencyInjection\Exception\InvalidArgumentException'); + $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); $this->expectExceptionMessage('Invalid "controller.service_arguments" tag for service "foo": method "fooAction()" has no "baz" argument on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -197,7 +197,7 @@ public function testSkipSetContainer() public function testExceptionOnNonExistentTypeHint() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClass". Did you forget to add a use statement?'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -217,7 +217,7 @@ public function testExceptionOnNonExistentTypeHint() public function testExceptionOnNonExistentTypeHintDifferentNamespace() { - $this->expectException('RuntimeException'); + $this->expectException(\RuntimeException::class); $this->expectExceptionMessage('Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassDifferentNamespaceController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Acme\NonExistentClass".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); diff --git a/Tests/Fragment/HIncludeFragmentRendererTest.php b/Tests/Fragment/HIncludeFragmentRendererTest.php index 87587c8009..2dd09aca3e 100644 --- a/Tests/Fragment/HIncludeFragmentRendererTest.php +++ b/Tests/Fragment/HIncludeFragmentRendererTest.php @@ -23,7 +23,7 @@ class HIncludeFragmentRendererTest extends TestCase { public function testRenderExceptionWhenControllerAndNoSigner() { - $this->expectException('LogicException'); + $this->expectException(\LogicException::class); $strategy = new HIncludeFragmentRenderer(); $strategy->render(new ControllerReference('main_controller', [], []), Request::create('/')); } From 77c6e178bd2e293a1b892bca27b42ddf39172001 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 11 Jan 2021 11:45:43 +0100 Subject: [PATCH 061/396] Use ::class keyword when possible --- Tests/Fragment/FragmentHandlerTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/Fragment/FragmentHandlerTest.php b/Tests/Fragment/FragmentHandlerTest.php index 56f1016067..3e3429c4e8 100644 --- a/Tests/Fragment/FragmentHandlerTest.php +++ b/Tests/Fragment/FragmentHandlerTest.php @@ -26,7 +26,7 @@ class FragmentHandlerTest extends TestCase protected function setUp(): void { - $this->requestStack = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\RequestStack') + $this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class) ->disableOriginalConstructor() ->getMock() ; @@ -39,14 +39,14 @@ protected function setUp(): void public function testRenderWhenRendererDoesNotExist() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $handler = new FragmentHandler($this->requestStack); $handler->render('/', 'foo'); } public function testRenderWithUnknownRenderer() { - $this->expectException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); $handler = $this->getHandler($this->returnValue(new Response('foo'))); $handler->render('/', 'bar'); @@ -59,7 +59,7 @@ public function testDeliverWithUnsuccessfulResponse() $handler->render('/', 'foo'); $this->fail('->render() throws a \RuntimeException exception if response is not successful'); } catch (\Exception $e) { - $this->assertInstanceOf('\RuntimeException', $e); + $this->assertInstanceOf(\RuntimeException::class, $e); $this->assertEquals(0, $e->getCode()); $this->assertEquals('Error when rendering "http://localhost/" (Status code is 404).', $e->getMessage()); @@ -79,7 +79,7 @@ public function testRender() protected function getHandler($returnValue, $arguments = []) { - $renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock(); + $renderer = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface::class)->getMock(); $renderer ->expects($this->any()) ->method('getName') From 9579bea317a26811bfcfecea051ba3ba02d6a6d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Sat, 12 Dec 2020 16:46:18 +0100 Subject: [PATCH 062/396] Dont allow unserializing classes with a destructor --- DataCollector/DataCollector.php | 4 ++++ DataCollector/DumpDataCollector.php | 2 +- Kernel.php | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/DataCollector/DataCollector.php b/DataCollector/DataCollector.php index 832a5d9ebf..3938dab6a1 100644 --- a/DataCollector/DataCollector.php +++ b/DataCollector/DataCollector.php @@ -123,6 +123,10 @@ public function __sleep() public function __wakeup() { if (__CLASS__ !== $c = (new \ReflectionMethod($this, 'unserialize'))->getDeclaringClass()->name) { + if (\is_object($this->data)) { + throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); + } + @trigger_error(sprintf('Implementing the "%s::unserialize()" method is deprecated since Symfony 4.3, store all the serialized state in the "data" property instead.', $c), \E_USER_DEPRECATED); $this->unserialize($this->data); } diff --git a/DataCollector/DumpDataCollector.php b/DataCollector/DumpDataCollector.php index df4ec5f670..af8b3a9458 100644 --- a/DataCollector/DumpDataCollector.php +++ b/DataCollector/DumpDataCollector.php @@ -184,7 +184,7 @@ public function __wakeup() $fileLinkFormat = array_pop($this->data); $this->dataCount = \count($this->data); - self::__construct($this->stopwatch, $fileLinkFormat, $charset); + self::__construct($this->stopwatch, \is_string($fileLinkFormat) || $fileLinkFormat instanceof FileLinkFormatter ? $fileLinkFormat : null, \is_string($charset) ? $charset : null); } public function getDumpsCount() diff --git a/Kernel.php b/Kernel.php index b91fc66a9f..c9317c81ca 100644 --- a/Kernel.php +++ b/Kernel.php @@ -920,6 +920,10 @@ public function __sleep() public function __wakeup() { + if (\is_object($this->environment) || \is_object($this->debug)) { + throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); + } + if (__CLASS__ !== $c = (new \ReflectionMethod($this, 'serialize'))->getDeclaringClass()->name) { @trigger_error(sprintf('Implementing the "%s::serialize()" method is deprecated since Symfony 4.3.', $c), \E_USER_DEPRECATED); $this->unserialize($this->serialized); From 3ca6f2f9983a3bd007b5149bc8edd6275a6d7836 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Thu, 14 Jan 2021 08:17:09 +0100 Subject: [PATCH 063/396] No patch version in CHANGELOG --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5444039b0..e20b6c881d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ CHANGELOG ========= -5.3.0 ------ +5.3 +--- * marked the class `Symfony\Component\HttpKernel\EventListener\DebugHandlersListener` as internal From dd23275704a4f73da76ace9bbc479ac15ba09406 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 14 Jan 2021 00:57:45 +0100 Subject: [PATCH 064/396] [travis] use PHP 8.0 to patch return types and run deps=low --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 459e5f4682..0094dc575f 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "symfony/translation": "^4.2|^5.0", "symfony/translation-contracts": "^1.1|^2", "psr/cache": "~1.0", - "twig/twig": "^1.34|^2.4|^3.0" + "twig/twig": "^1.43|^2.13|^3.0.4" }, "provide": { "psr/log-implementation": "1.0" @@ -53,7 +53,7 @@ "symfony/console": ">=5", "symfony/dependency-injection": "<4.3", "symfony/translation": "<4.2", - "twig/twig": "<1.34|<2.4,>=2" + "twig/twig": "<1.43|<2.13,>=2" }, "suggest": { "symfony/browser-kit": "", From 27eff2a1cc7c86fb408fbd1f014bc9bab14fb485 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 14 Jan 2021 16:08:15 +0100 Subject: [PATCH 065/396] CS fix --- DataCollector/DumpDataCollector.php | 2 +- HttpCache/Store.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DataCollector/DumpDataCollector.php b/DataCollector/DumpDataCollector.php index af8b3a9458..ae751c4f2e 100644 --- a/DataCollector/DumpDataCollector.php +++ b/DataCollector/DumpDataCollector.php @@ -194,7 +194,7 @@ public function getDumpsCount() public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1) { - $data = fopen('php://memory', 'r+b'); + $data = fopen('php://memory', 'r+'); if ('html' === $format) { $dumper = new HtmlDumper($data, $this->charset); diff --git a/HttpCache/Store.php b/HttpCache/Store.php index bfaaebe944..3b69289f17 100644 --- a/HttpCache/Store.php +++ b/HttpCache/Store.php @@ -69,7 +69,7 @@ public function lock(Request $request) if (!file_exists(\dirname($path)) && false === @mkdir(\dirname($path), 0777, true) && !is_dir(\dirname($path))) { return $path; } - $h = fopen($path, 'cb'); + $h = fopen($path, 'c'); if (!flock($h, \LOCK_EX | \LOCK_NB)) { fclose($h); @@ -114,7 +114,7 @@ public function isLocked(Request $request) return false; } - $h = fopen($path, 'rb'); + $h = fopen($path, 'r'); flock($h, \LOCK_EX | \LOCK_NB, $wouldBlock); flock($h, \LOCK_UN); // release the lock we just acquired fclose($h); @@ -379,7 +379,7 @@ private function save(string $key, string $data, bool $overwrite = true): bool } $tmpFile = tempnam(\dirname($path), basename($path)); - if (false === $fp = @fopen($tmpFile, 'wb')) { + if (false === $fp = @fopen($tmpFile, 'w')) { @unlink($tmpFile); return false; From 8445c3a1c2b1de33bc12337d66cedbbdbfc582ed Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 22 Jan 2021 17:56:23 +0100 Subject: [PATCH 066/396] [HttpKernel] Configure the ErrorHandler even when it is overriden --- EventListener/DebugHandlersListener.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/EventListener/DebugHandlersListener.php b/EventListener/DebugHandlersListener.php index f4781ccd8e..cfc277e330 100644 --- a/EventListener/DebugHandlersListener.php +++ b/EventListener/DebugHandlersListener.php @@ -33,6 +33,7 @@ */ class DebugHandlersListener implements EventSubscriberInterface { + private $earlyHandler; private $exceptionHandler; private $logger; private $levels; @@ -53,6 +54,10 @@ class DebugHandlersListener implements EventSubscriberInterface */ public function __construct(callable $exceptionHandler = null, LoggerInterface $logger = null, $levels = \E_ALL, ?int $throwAt = \E_ALL, bool $scream = true, $fileLinkFormat = null, bool $scope = true) { + $handler = set_exception_handler('var_dump'); + $this->earlyHandler = \is_array($handler) ? $handler[0] : null; + restore_exception_handler(); + $this->exceptionHandler = $exceptionHandler; $this->logger = $logger; $this->levels = null === $levels ? \E_ALL : $levels; @@ -79,6 +84,10 @@ public function configure(Event $event = null) $handler = \is_array($handler) ? $handler[0] : null; restore_exception_handler(); + if (!$handler instanceof ErrorHandler && !$handler instanceof LegacyErrorHandler) { + $handler = $this->earlyHandler; + } + if ($this->logger || null !== $this->throwAt) { if ($handler instanceof ErrorHandler || $handler instanceof LegacyErrorHandler) { if ($this->logger) { From df632a4552f2b2fffa74b76f674a7511e919dec8 Mon Sep 17 00:00:00 2001 From: Simon Berger Date: Sun, 24 Jan 2021 23:22:56 +0100 Subject: [PATCH 067/396] Changed private static array-properties to const --- HttpCache/ResponseCacheStrategy.php | 8 ++++---- Log/Logger.php | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/HttpCache/ResponseCacheStrategy.php b/HttpCache/ResponseCacheStrategy.php index c30fface60..1f09946846 100644 --- a/HttpCache/ResponseCacheStrategy.php +++ b/HttpCache/ResponseCacheStrategy.php @@ -27,12 +27,12 @@ class ResponseCacheStrategy implements ResponseCacheStrategyInterface /** * Cache-Control headers that are sent to the final response if they appear in ANY of the responses. */ - private static $overrideDirectives = ['private', 'no-cache', 'no-store', 'no-transform', 'must-revalidate', 'proxy-revalidate']; + private const OVERRIDE_DIRECTIVES = ['private', 'no-cache', 'no-store', 'no-transform', 'must-revalidate', 'proxy-revalidate']; /** * Cache-Control headers that are sent to the final response if they appear in ALL of the responses. */ - private static $inheritDirectives = ['public', 'immutable']; + private const INHERIT_DIRECTIVES = ['public', 'immutable']; private $embeddedResponses = 0; private $isNotCacheableResponseEmbedded = false; @@ -60,13 +60,13 @@ public function add(Response $response) { ++$this->embeddedResponses; - foreach (self::$overrideDirectives as $directive) { + foreach (self::OVERRIDE_DIRECTIVES as $directive) { if ($response->headers->hasCacheControlDirective($directive)) { $this->flagDirectives[$directive] = true; } } - foreach (self::$inheritDirectives as $directive) { + foreach (self::INHERIT_DIRECTIVES as $directive) { if (false !== $this->flagDirectives[$directive]) { $this->flagDirectives[$directive] = $response->headers->hasCacheControlDirective($directive); } diff --git a/Log/Logger.php b/Log/Logger.php index 0181817bdf..3922d2fe68 100644 --- a/Log/Logger.php +++ b/Log/Logger.php @@ -22,7 +22,7 @@ */ class Logger extends AbstractLogger { - private static $levels = [ + private const LEVELS = [ LogLevel::DEBUG => 0, LogLevel::INFO => 1, LogLevel::NOTICE => 2, @@ -52,11 +52,11 @@ public function __construct(string $minLevel = null, $output = null, callable $f } } - if (!isset(self::$levels[$minLevel])) { + if (!isset(self::LEVELS[$minLevel])) { throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $minLevel)); } - $this->minLevelIndex = self::$levels[$minLevel]; + $this->minLevelIndex = self::LEVELS[$minLevel]; $this->formatter = $formatter ?: [$this, 'format']; if ($output && false === $this->handle = \is_resource($output) ? $output : @fopen($output, 'a')) { throw new InvalidArgumentException(sprintf('Unable to open "%s".', $output)); @@ -70,11 +70,11 @@ public function __construct(string $minLevel = null, $output = null, callable $f */ public function log($level, $message, array $context = []) { - if (!isset(self::$levels[$level])) { + if (!isset(self::LEVELS[$level])) { throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); } - if (self::$levels[$level] < $this->minLevelIndex) { + if (self::LEVELS[$level] < $this->minLevelIndex) { return; } From ba084ae291409f62b9aba826f1a2d9425e3b52d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Tue, 26 Jan 2021 19:15:20 +0100 Subject: [PATCH 068/396] Fix transient tests --- Tests/Fragment/InlineFragmentRendererTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Tests/Fragment/InlineFragmentRendererTest.php b/Tests/Fragment/InlineFragmentRendererTest.php index c25297dbe4..156e16d03b 100644 --- a/Tests/Fragment/InlineFragmentRendererTest.php +++ b/Tests/Fragment/InlineFragmentRendererTest.php @@ -23,6 +23,9 @@ use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; +/** + * @group time-sensitive + */ class InlineFragmentRendererTest extends TestCase { public function testRender() @@ -253,8 +256,7 @@ public function testIpAddressOfRangedTrustedProxyIsSetAsRemote() } /** - * Creates a Kernel expecting a request equals to $request - * Allows delta in comparison in case REQUEST_TIME changed by 1 second. + * Creates a Kernel expecting a request equals to $request. */ private function getKernelExpectingRequest(Request $request, $strict = false) { @@ -262,7 +264,7 @@ private function getKernelExpectingRequest(Request $request, $strict = false) $kernel ->expects($this->once()) ->method('handle') - ->with($this->equalTo($request, 1)) + ->with($request) ->willReturn(new Response('foo')); return $kernel; From f75654ca581fabb3e3b719f03ace7d3f59a84bc4 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Fri, 22 Jan 2021 13:09:22 +0100 Subject: [PATCH 069/396] Use createMock() and use import instead of FQCN --- Tests/CacheClearer/ChainCacheClearerTest.php | 3 +- Tests/CacheClearer/Psr6CacheClearerTest.php | 4 +- .../CacheWarmer/CacheWarmerAggregateTest.php | 16 ++------ Tests/Config/FileLocatorTest.php | 5 ++- .../NotTaggedControllerValueResolverTest.php | 9 +++-- .../ServiceValueResolverTest.php | 3 +- Tests/Controller/ArgumentResolverTest.php | 6 +-- .../ContainerControllerResolverTest.php | 6 +-- Tests/Controller/ControllerResolverTest.php | 2 +- Tests/Controller/ErrorControllerTest.php | 4 +- Tests/DataCollector/DumpDataCollectorTest.php | 2 +- .../RequestDataCollectorTest.php | 7 ++-- Tests/DataCollector/TimeDataCollectorTest.php | 3 +- Tests/Debug/TraceableEventDispatcherTest.php | 6 ++- .../LazyLoadingFragmentHandlerTest.php | 9 +++-- ...sterControllerArgumentLocatorsPassTest.php | 17 ++++---- .../ResettableServicePassTest.php | 3 +- .../AddRequestFormatsListenerTest.php | 11 ++---- .../DebugHandlersListenerTest.php | 7 ++-- Tests/EventListener/ErrorListenerTest.php | 8 ++-- Tests/EventListener/ExceptionListenerTest.php | 9 +++-- Tests/EventListener/FragmentListenerTest.php | 7 ++-- .../EventListener/LocaleAwareListenerTest.php | 4 +- Tests/EventListener/LocaleListenerTest.php | 15 ++++--- Tests/EventListener/ProfilerListenerTest.php | 26 +++++-------- Tests/EventListener/ResponseListenerTest.php | 2 +- Tests/EventListener/RouterListenerTest.php | 39 ++++++++++--------- .../EventListener/SaveSessionListenerTest.php | 6 +-- Tests/EventListener/SessionListenerTest.php | 30 +++++++------- Tests/EventListener/SurrogateListenerTest.php | 6 +-- .../EventListener/TestSessionListenerTest.php | 18 ++++----- .../EventListener/TranslatorListenerTest.php | 7 ++-- .../ValidateRequestListenerTest.php | 5 ++- Tests/Fragment/EsiFragmentRendererTest.php | 3 +- Tests/Fragment/FragmentHandlerTest.php | 9 ++--- .../Fragment/HIncludeFragmentRendererTest.php | 3 +- Tests/Fragment/InlineFragmentRendererTest.php | 15 ++++--- .../Fragment/RoutableFragmentRendererTest.php | 3 +- Tests/Fragment/SsiFragmentRendererTest.php | 3 +- Tests/HttpCache/EsiTest.php | 3 +- Tests/HttpCache/HttpCacheTest.php | 10 +++-- Tests/HttpCache/SsiTest.php | 3 +- Tests/HttpClientKernelTest.php | 4 +- Tests/HttpKernelBrowserTest.php | 3 +- Tests/HttpKernelTest.php | 10 +++-- Tests/KernelTest.php | 14 ++++--- 46 files changed, 203 insertions(+), 185 deletions(-) diff --git a/Tests/CacheClearer/ChainCacheClearerTest.php b/Tests/CacheClearer/ChainCacheClearerTest.php index a0b4bd8c41..80c1b576be 100644 --- a/Tests/CacheClearer/ChainCacheClearerTest.php +++ b/Tests/CacheClearer/ChainCacheClearerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\CacheClearer; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface; use Symfony\Component\HttpKernel\CacheClearer\ChainCacheClearer; class ChainCacheClearerTest extends TestCase @@ -41,6 +42,6 @@ public function testInjectClearersInConstructor() protected function getMockClearer() { - return $this->getMockBuilder(\Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface::class)->getMock(); + return $this->createMock(CacheClearerInterface::class); } } diff --git a/Tests/CacheClearer/Psr6CacheClearerTest.php b/Tests/CacheClearer/Psr6CacheClearerTest.php index c7c683428e..0c6f1543ac 100644 --- a/Tests/CacheClearer/Psr6CacheClearerTest.php +++ b/Tests/CacheClearer/Psr6CacheClearerTest.php @@ -19,7 +19,7 @@ class Psr6CacheClearerTest extends TestCase { public function testClearPoolsInjectedInConstructor() { - $pool = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock(); + $pool = $this->createMock(CacheItemPoolInterface::class); $pool ->expects($this->once()) ->method('clear'); @@ -29,7 +29,7 @@ public function testClearPoolsInjectedInConstructor() public function testClearPool() { - $pool = $this->getMockBuilder(CacheItemPoolInterface::class)->getMock(); + $pool = $this->createMock(CacheItemPoolInterface::class); $pool ->expects($this->once()) ->method('clear'); diff --git a/Tests/CacheWarmer/CacheWarmerAggregateTest.php b/Tests/CacheWarmer/CacheWarmerAggregateTest.php index cf9493a295..c34cc9c400 100644 --- a/Tests/CacheWarmer/CacheWarmerAggregateTest.php +++ b/Tests/CacheWarmer/CacheWarmerAggregateTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerAggregate; +use Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface; class CacheWarmerAggregateTest extends TestCase { @@ -30,7 +31,7 @@ public static function tearDownAfterClass(): void public function testInjectWarmersUsingConstructor() { - $warmer = $this->getCacheWarmerMock(); + $warmer = $this->createMock(CacheWarmerInterface::class); $warmer ->expects($this->once()) ->method('warmUp'); @@ -40,7 +41,7 @@ public function testInjectWarmersUsingConstructor() public function testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsEnabled() { - $warmer = $this->getCacheWarmerMock(); + $warmer = $this->createMock(CacheWarmerInterface::class); $warmer ->expects($this->never()) ->method('isOptional'); @@ -55,7 +56,7 @@ public function testWarmupDoesCallWarmupOnOptionalWarmersWhenEnableOptionalWarme public function testWarmupDoesNotCallWarmupOnOptionalWarmersWhenEnableOptionalWarmersIsNotEnabled() { - $warmer = $this->getCacheWarmerMock(); + $warmer = $this->createMock(CacheWarmerInterface::class); $warmer ->expects($this->once()) ->method('isOptional') @@ -67,13 +68,4 @@ public function testWarmupDoesNotCallWarmupOnOptionalWarmersWhenEnableOptionalWa $aggregate = new CacheWarmerAggregate([$warmer]); $aggregate->warmUp(self::$cacheDir); } - - protected function getCacheWarmerMock() - { - $warmer = $this->getMockBuilder(\Symfony\Component\HttpKernel\CacheWarmer\CacheWarmerInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - return $warmer; - } } diff --git a/Tests/Config/FileLocatorTest.php b/Tests/Config/FileLocatorTest.php index d992286752..e70e49e83c 100644 --- a/Tests/Config/FileLocatorTest.php +++ b/Tests/Config/FileLocatorTest.php @@ -13,12 +13,13 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\Config\FileLocator; +use Symfony\Component\HttpKernel\KernelInterface; class FileLocatorTest extends TestCase { public function testLocate() { - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock(); + $kernel = $this->createMock(KernelInterface::class); $kernel ->expects($this->atLeastOnce()) ->method('locateResource') @@ -39,7 +40,7 @@ public function testLocate() */ public function testLocateWithGlobalResourcePath() { - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock(); + $kernel = $this->createMock(KernelInterface::class); $kernel ->expects($this->atLeastOnce()) ->method('locateResource') diff --git a/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php b/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php index efb7322efa..3cf2f0f185 100644 --- a/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php +++ b/Tests/Controller/ArgumentResolver/NotTaggedControllerValueResolverTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver; use PHPUnit\Framework\TestCase; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ArgumentResolver\NotTaggedControllerValueResolver; @@ -55,7 +56,7 @@ public function testDoNotSupportEmptyController() public function testController() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('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"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); @@ -66,7 +67,7 @@ public function testController() public function testControllerWithATrailingBackSlash() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('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"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); @@ -77,7 +78,7 @@ public function testControllerWithATrailingBackSlash() public function testControllerWithMethodNameStartUppercase() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('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"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); @@ -88,7 +89,7 @@ public function testControllerWithMethodNameStartUppercase() public function testControllerNameIsAnArray() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('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"?'); $resolver = new NotTaggedControllerValueResolver(new ServiceLocator([])); $argument = new ArgumentMetadata('dummy', \stdClass::class, false, false, null); diff --git a/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php b/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php index 743eefa3e5..69b9511c05 100644 --- a/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php +++ b/Tests/Controller/ArgumentResolver/ServiceValueResolverTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ArgumentResolver\ServiceValueResolver; @@ -107,7 +108,7 @@ public function testControllerNameIsAnArray() public function testErrorIsTruncated() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Cannot autowire argument $dummy of "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyController::index()": it references class "Symfony\Component\HttpKernel\Tests\Controller\ArgumentResolver\DummyService" but no such service exists.'); $container = new ContainerBuilder(); $container->addCompilerPass(new RegisterControllerArgumentLocatorsPass()); diff --git a/Tests/Controller/ArgumentResolverTest.php b/Tests/Controller/ArgumentResolverTest.php index da521ff204..40638b4fe6 100644 --- a/Tests/Controller/ArgumentResolverTest.php +++ b/Tests/Controller/ArgumentResolverTest.php @@ -177,7 +177,7 @@ public function testGetArgumentWithoutArray() { $this->expectException(\InvalidArgumentException::class); $factory = new ArgumentMetadataFactory(); - $valueResolver = $this->getMockBuilder(ArgumentValueResolverInterface::class)->getMock(); + $valueResolver = $this->createMock(ArgumentValueResolverInterface::class); $resolver = new ArgumentResolver($factory, [$valueResolver]); $valueResolver->expects($this->any())->method('supports')->willReturn(true); @@ -241,7 +241,7 @@ public function testGetSessionArgumentsWithExtendedSession() public function testGetSessionArgumentsWithInterface() { - $session = $this->getMockBuilder(SessionInterface::class)->getMock(); + $session = $this->createMock(SessionInterface::class); $request = Request::create('/'); $request->setSession($session); $controller = [$this, 'controllerWithSessionInterface']; @@ -252,7 +252,7 @@ public function testGetSessionArgumentsWithInterface() public function testGetSessionMissMatchWithInterface() { $this->expectException(\RuntimeException::class); - $session = $this->getMockBuilder(SessionInterface::class)->getMock(); + $session = $this->createMock(SessionInterface::class); $request = Request::create('/'); $request->setSession($session); $controller = [$this, 'controllerWithExtendingSession']; diff --git a/Tests/Controller/ContainerControllerResolverTest.php b/Tests/Controller/ContainerControllerResolverTest.php index 7f4564688c..1c239fc4c0 100644 --- a/Tests/Controller/ContainerControllerResolverTest.php +++ b/Tests/Controller/ContainerControllerResolverTest.php @@ -153,7 +153,7 @@ public function testExceptionWhenUsingRemovedControllerServiceWithClassNameAsNam { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Controller "Symfony\Component\HttpKernel\Tests\Controller\ControllerTestService" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?'); - $container = $this->getMockBuilder(Container::class)->getMock(); + $container = $this->createMock(Container::class); $container->expects($this->once()) ->method('has') ->with(ControllerTestService::class) @@ -177,7 +177,7 @@ public function testExceptionWhenUsingRemovedControllerService() { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Controller "app.my_controller" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?'); - $container = $this->getMockBuilder(Container::class)->getMock(); + $container = $this->createMock(Container::class); $container->expects($this->once()) ->method('has') ->with('app.my_controller') @@ -232,7 +232,7 @@ protected function createControllerResolver(LoggerInterface $logger = null, Cont protected function createMockContainer() { - return $this->getMockBuilder(ContainerInterface::class)->getMock(); + return $this->createMock(ContainerInterface::class); } } diff --git a/Tests/Controller/ControllerResolverTest.php b/Tests/Controller/ControllerResolverTest.php index 834f925c43..2afcfe4b4e 100644 --- a/Tests/Controller/ControllerResolverTest.php +++ b/Tests/Controller/ControllerResolverTest.php @@ -20,7 +20,7 @@ class ControllerResolverTest extends TestCase { public function testGetControllerWithoutControllerParameter() { - $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $logger->expects($this->once())->method('warning')->with('Unable to look for the controller as the "_controller" parameter is missing.'); $resolver = $this->createControllerResolver($logger); diff --git a/Tests/Controller/ErrorControllerTest.php b/Tests/Controller/ErrorControllerTest.php index fadd820ea6..1b3a833578 100644 --- a/Tests/Controller/ErrorControllerTest.php +++ b/Tests/Controller/ErrorControllerTest.php @@ -27,7 +27,7 @@ class ErrorControllerTest extends TestCase */ public function testInvokeController(Request $request, \Exception $exception, int $statusCode, string $content) { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $errorRenderer = new HtmlErrorRenderer(); $controller = new ErrorController($kernel, null, $errorRenderer); $response = $controller($exception); @@ -67,7 +67,7 @@ public function testPreviewController() $_controller = 'error_controller'; $code = 404; - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel ->expects($this->once()) ->method('handle') diff --git a/Tests/DataCollector/DumpDataCollectorTest.php b/Tests/DataCollector/DumpDataCollectorTest.php index a40a482278..c69166bf09 100644 --- a/Tests/DataCollector/DumpDataCollectorTest.php +++ b/Tests/DataCollector/DumpDataCollectorTest.php @@ -62,7 +62,7 @@ public function testDumpWithServerConnection() $data = new Data([[123]]); // Server is up, server dumper is used - $serverDumper = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock(); + $serverDumper = $this->createMock(Connection::class); $serverDumper->expects($this->once())->method('write')->willReturn(true); $collector = new DumpDataCollector(null, null, null, null, $serverDumper); diff --git a/Tests/DataCollector/RequestDataCollectorTest.php b/Tests/DataCollector/RequestDataCollectorTest.php index bb29b4ba52..e81a6e5b57 100644 --- a/Tests/DataCollector/RequestDataCollectorTest.php +++ b/Tests/DataCollector/RequestDataCollectorTest.php @@ -21,6 +21,7 @@ use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; +use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; use Symfony\Component\HttpKernel\Event\ControllerEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; @@ -203,7 +204,7 @@ public function testItAddsRedirectedAttributesWhenRequestContainsSpecificCookie( 'sf_redirect' => '{}', ]); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $c = new RequestDataCollector(); $c->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $this->createResponse())); @@ -288,8 +289,8 @@ protected function createResponse() */ protected function injectController($collector, $controller, $request) { - $resolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ControllerResolverInterface::class)->getMock(); - $httpKernel = new HttpKernel(new EventDispatcher(), $resolver, null, $this->getMockBuilder(ArgumentResolverInterface::class)->getMock()); + $resolver = $this->createMock(ControllerResolverInterface::class); + $httpKernel = new HttpKernel(new EventDispatcher(), $resolver, null, $this->createMock(ArgumentResolverInterface::class)); $event = new ControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST); $collector->onKernelController($event); } diff --git a/Tests/DataCollector/TimeDataCollectorTest.php b/Tests/DataCollector/TimeDataCollectorTest.php index ab231ac4c5..0496f1a3d1 100644 --- a/Tests/DataCollector/TimeDataCollectorTest.php +++ b/Tests/DataCollector/TimeDataCollectorTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector; +use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Stopwatch\Stopwatch; /** @@ -43,7 +44,7 @@ public function testCollect() $c->collect($request, new Response()); $this->assertEquals(0, $c->getStartTime()); - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock(); + $kernel = $this->createMock(KernelInterface::class); $kernel->expects($this->once())->method('getStartTime')->willReturn(123456.0); $c = new TimeDataCollector($kernel); diff --git a/Tests/Debug/TraceableEventDispatcherTest.php b/Tests/Debug/TraceableEventDispatcherTest.php index c4d42ec648..2fb050dafd 100644 --- a/Tests/Debug/TraceableEventDispatcherTest.php +++ b/Tests/Debug/TraceableEventDispatcherTest.php @@ -17,6 +17,8 @@ use Symfony\Component\HttpFoundation\Request; 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\Debug\TraceableEventDispatcher; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\Stopwatch\Stopwatch; @@ -110,9 +112,9 @@ public function testListenerCanRemoveItselfWhenExecuted() protected function getHttpKernel($dispatcher, $controller) { - $controllerResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ControllerResolverInterface::class)->getMock(); + $controllerResolver = $this->createMock(ControllerResolverInterface::class); $controllerResolver->expects($this->once())->method('getController')->willReturn($controller); - $argumentResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface::class)->getMock(); + $argumentResolver = $this->createMock(ArgumentResolverInterface::class); $argumentResolver->expects($this->once())->method('getArguments')->willReturn([]); return new HttpKernel($dispatcher, $controllerResolver, new RequestStack(), $argumentResolver); diff --git a/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php b/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php index 493178d470..c8db5e55e9 100644 --- a/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php +++ b/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php @@ -12,22 +12,25 @@ namespace Symfony\Component\HttpKernel\Tests\DependencyInjection; use PHPUnit\Framework\TestCase; +use Psr\Container\ContainerInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler; +use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface; class LazyLoadingFragmentHandlerTest extends TestCase { public function testRender() { - $renderer = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface::class)->getMock(); + $renderer = $this->createMock(FragmentRendererInterface::class); $renderer->expects($this->once())->method('getName')->willReturn('foo'); $renderer->expects($this->any())->method('render')->willReturn(new Response()); - $requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock(); + $requestStack = $this->createMock(RequestStack::class); $requestStack->expects($this->any())->method('getCurrentRequest')->willReturn(Request::create('/')); - $container = $this->getMockBuilder(\Psr\Container\ContainerInterface::class)->getMock(); + $container = $this->createMock(ContainerInterface::class); $container->expects($this->once())->method('has')->with('foo')->willReturn(true); $container->expects($this->once())->method('get')->willReturn($renderer); diff --git a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php index 8a65b4ff38..c00e1849fc 100644 --- a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php +++ b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php @@ -18,6 +18,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareTrait; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\ServiceLocator; use Symfony\Component\DependencyInjection\TypedReference; @@ -27,7 +28,7 @@ class RegisterControllerArgumentLocatorsPassTest extends TestCase { public function testInvalidClass() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Class "Symfony\Component\HttpKernel\Tests\DependencyInjection\NotFound" used for service "foo" cannot be found.'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -42,7 +43,7 @@ public function testInvalidClass() public function testNoAction() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Missing "action" attribute on tag "controller.service_arguments" {"argument":"bar"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -57,7 +58,7 @@ public function testNoAction() public function testNoArgument() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Missing "argument" attribute on tag "controller.service_arguments" {"action":"fooAction"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -72,7 +73,7 @@ public function testNoArgument() public function testNoService() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Missing "id" attribute on tag "controller.service_arguments" {"action":"fooAction","argument":"bar"} for service "foo".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -87,7 +88,7 @@ public function testNoService() public function testInvalidMethod() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid "action" attribute on tag "controller.service_arguments" for service "foo": no public "barAction()" method found on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -102,7 +103,7 @@ public function testInvalidMethod() public function testInvalidArgument() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Invalid "controller.service_arguments" tag for service "foo": method "fooAction()" has no "baz" argument on class "Symfony\Component\HttpKernel\Tests\DependencyInjection\RegisterTestController".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -197,7 +198,7 @@ public function testSkipSetContainer() public function testExceptionOnNonExistentTypeHint() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClass". Did you forget to add a use statement?'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); @@ -211,7 +212,7 @@ public function testExceptionOnNonExistentTypeHint() public function testExceptionOnNonExistentTypeHintDifferentNamespace() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Cannot determine controller argument for "Symfony\Component\HttpKernel\Tests\DependencyInjection\NonExistentClassDifferentNamespaceController::fooAction()": the $nonExistent argument is type-hinted with the non-existent class or interface: "Acme\NonExistentClass".'); $container = new ContainerBuilder(); $container->register('argument_resolver.service')->addArgument([]); diff --git a/Tests/DependencyInjection/ResettableServicePassTest.php b/Tests/DependencyInjection/ResettableServicePassTest.php index b28f90d362..4c110e3a26 100644 --- a/Tests/DependencyInjection/ResettableServicePassTest.php +++ b/Tests/DependencyInjection/ResettableServicePassTest.php @@ -6,6 +6,7 @@ use Symfony\Component\DependencyInjection\Argument\IteratorArgument; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\DependencyInjection\Exception\RuntimeException; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass; use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; @@ -57,7 +58,7 @@ public function testCompilerPass() public function testMissingMethod() { - $this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Tag "kernel.reset" requires the "method" attribute to be set.'); $container = new ContainerBuilder(); $container->register(ResettableService::class) diff --git a/Tests/EventListener/AddRequestFormatsListenerTest.php b/Tests/EventListener/AddRequestFormatsListenerTest.php index 6c4459fc2a..def3831851 100644 --- a/Tests/EventListener/AddRequestFormatsListenerTest.php +++ b/Tests/EventListener/AddRequestFormatsListenerTest.php @@ -12,6 +12,7 @@ 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\RequestEvent; use Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener; @@ -41,7 +42,7 @@ protected function tearDown(): void public function testIsAnEventSubscriber() { - $this->assertInstanceOf(\Symfony\Component\EventDispatcher\EventSubscriberInterface::class, $this->listener); + $this->assertInstanceOf(EventSubscriberInterface::class, $this->listener); } public function testRegisteredEvent() @@ -66,16 +67,12 @@ public function testSetAdditionalFormats() protected function getRequestMock() { - return $this->getMockBuilder(Request::class)->getMock(); + return $this->createMock(Request::class); } protected function getRequestEventMock(Request $request) { - $event = $this - ->getMockBuilder(RequestEvent::class) - ->disableOriginalConstructor() - ->getMock(); - + $event = $this->createMock(RequestEvent::class); $event->expects($this->any()) ->method('getRequest') ->willReturn($request); diff --git a/Tests/EventListener/DebugHandlersListenerTest.php b/Tests/EventListener/DebugHandlersListenerTest.php index fb18d63fbe..8d74b2c0dd 100644 --- a/Tests/EventListener/DebugHandlersListenerTest.php +++ b/Tests/EventListener/DebugHandlersListenerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; @@ -35,7 +36,7 @@ class DebugHandlersListenerTest extends TestCase { public function testConfigure() { - $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $userHandler = function () {}; $listener = new DebugHandlersListener($userHandler, $logger); $eHandler = new ErrorHandler(); @@ -67,7 +68,7 @@ public function testConfigureForHttpKernelWithNoTerminateWithException() $listener = new DebugHandlersListener(null); $eHandler = new ErrorHandler(); $event = new KernelEvent( - $this->getMockBuilder(HttpKernelInterface::class)->getMock(), + $this->createMock(HttpKernelInterface::class), Request::create('/'), HttpKernelInterface::MASTER_REQUEST ); @@ -91,7 +92,7 @@ public function testConsoleEvent() { $dispatcher = new EventDispatcher(); $listener = new DebugHandlersListener(null); - $app = $this->getMockBuilder(Application::class)->getMock(); + $app = $this->createMock(Application::class); $app->expects($this->once())->method('getHelperSet')->willReturn(new HelperSet()); $command = new Command(__FUNCTION__); $command->setApplication($app); diff --git a/Tests/EventListener/ErrorListenerTest.php b/Tests/EventListener/ErrorListenerTest.php index 4428e3d1a6..2cd1091a7f 100644 --- a/Tests/EventListener/ErrorListenerTest.php +++ b/Tests/EventListener/ErrorListenerTest.php @@ -115,9 +115,9 @@ public function provider() public function testSubRequestFormat() { - $listener = new ErrorListener('foo', $this->getMockBuilder(LoggerInterface::class)->getMock()); + $listener = new ErrorListener('foo', $this->createMock(LoggerInterface::class)); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); @@ -135,12 +135,12 @@ public function testSubRequestFormat() public function testCSPHeaderIsRemoved() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); - $listener = new ErrorListener('foo', $this->getMockBuilder(LoggerInterface::class)->getMock(), true); + $listener = new ErrorListener('foo', $this->createMock(LoggerInterface::class), true); $dispatcher->addSubscriber($listener); diff --git a/Tests/EventListener/ExceptionListenerTest.php b/Tests/EventListener/ExceptionListenerTest.php index 91ff62d906..6163f5b56e 100644 --- a/Tests/EventListener/ExceptionListenerTest.php +++ b/Tests/EventListener/ExceptionListenerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -112,9 +113,9 @@ public function provider() public function testSubRequestFormat() { - $listener = new ExceptionListener('foo', $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock()); + $listener = new ExceptionListener('foo', $this->createMock(LoggerInterface::class)); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); @@ -132,12 +133,12 @@ public function testSubRequestFormat() public function testCSPHeaderIsRemoved() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel->expects($this->once())->method('handle')->willReturnCallback(function (Request $request) { return new Response($request->getRequestFormat()); }); - $listener = new ExceptionListener('foo', $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(), true); + $listener = new ExceptionListener('foo', $this->createMock(LoggerInterface::class), true); $dispatcher->addSubscriber($listener); diff --git a/Tests/EventListener/FragmentListenerTest.php b/Tests/EventListener/FragmentListenerTest.php index e0b857debd..5720420dbf 100644 --- a/Tests/EventListener/FragmentListenerTest.php +++ b/Tests/EventListener/FragmentListenerTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\FragmentListener; +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\UriSigner; @@ -52,7 +53,7 @@ public function testOnlyTriggeredIfControllerWasNotDefinedYet() public function testAccessDeniedWithNonSafeMethods() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException::class); + $this->expectException(AccessDeniedHttpException::class); $request = Request::create('http://example.com/_fragment', 'POST'); $listener = new FragmentListener(new UriSigner('foo')); @@ -63,7 +64,7 @@ public function testAccessDeniedWithNonSafeMethods() public function testAccessDeniedWithWrongSignature() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException::class); + $this->expectException(AccessDeniedHttpException::class); $request = Request::create('http://example.com/_fragment', 'GET', [], [], [], ['REMOTE_ADDR' => '10.0.0.1']); $listener = new FragmentListener(new UriSigner('foo')); @@ -113,6 +114,6 @@ public function testRemovesPathWithControllerNotDefined() private function createRequestEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST) { - return new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, $requestType); + return new RequestEvent($this->createMock(HttpKernelInterface::class), $request, $requestType); } } diff --git a/Tests/EventListener/LocaleAwareListenerTest.php b/Tests/EventListener/LocaleAwareListenerTest.php index 0d14e5a987..20c9f9d8c9 100644 --- a/Tests/EventListener/LocaleAwareListenerTest.php +++ b/Tests/EventListener/LocaleAwareListenerTest.php @@ -28,7 +28,7 @@ class LocaleAwareListenerTest extends TestCase protected function setUp(): void { - $this->localeAwareService = $this->getMockBuilder(LocaleAwareInterface::class)->getMock(); + $this->localeAwareService = $this->createMock(LocaleAwareInterface::class); $this->requestStack = new RequestStack(); $this->listener = new LocaleAwareListener(new \ArrayIterator([$this->localeAwareService]), $this->requestStack); } @@ -110,7 +110,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest() private function createHttpKernel() { - return $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + return $this->createMock(HttpKernelInterface::class); } private function createRequest($locale) diff --git a/Tests/EventListener/LocaleListenerTest.php b/Tests/EventListener/LocaleListenerTest.php index 705600d70e..186ce43b1d 100644 --- a/Tests/EventListener/LocaleListenerTest.php +++ b/Tests/EventListener/LocaleListenerTest.php @@ -14,11 +14,14 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventSubscriberInterface; 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\LocaleListener; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; +use Symfony\Component\Routing\RequestContext; +use Symfony\Component\Routing\Router; class LocaleListenerTest extends TestCase { @@ -26,7 +29,7 @@ class LocaleListenerTest extends TestCase protected function setUp(): void { - $this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->disableOriginalConstructor()->getMock(); + $this->requestStack = $this->createMock(RequestStack::class); } public function testIsAnEventSubscriber() @@ -70,10 +73,10 @@ public function testLocaleFromRequestAttribute() public function testLocaleSetForRoutingContext() { // the request context is updated - $context = $this->getMockBuilder(\Symfony\Component\Routing\RequestContext::class)->getMock(); + $context = $this->createMock(RequestContext::class); $context->expects($this->once())->method('setParameter')->with('_locale', 'es'); - $router = $this->getMockBuilder(\Symfony\Component\Routing\Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); + $router = $this->getMockBuilder(Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); $router->expects($this->once())->method('getContext')->willReturn($context); $request = Request::create('/'); @@ -86,10 +89,10 @@ public function testLocaleSetForRoutingContext() public function testRouterResetWithParentRequestOnKernelFinishRequest() { // the request context is updated - $context = $this->getMockBuilder(\Symfony\Component\Routing\RequestContext::class)->getMock(); + $context = $this->createMock(RequestContext::class); $context->expects($this->once())->method('setParameter')->with('_locale', 'es'); - $router = $this->getMockBuilder(\Symfony\Component\Routing\Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); + $router = $this->getMockBuilder(Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); $router->expects($this->once())->method('getContext')->willReturn($context); $parentRequest = Request::create('/'); @@ -116,6 +119,6 @@ public function testRequestLocaleIsNotOverridden() private function getEvent(Request $request): RequestEvent { - return new RequestEvent($this->getMockBuilder(HttpKernelInterface::class)->getMock(), $request, HttpKernelInterface::MASTER_REQUEST); + return new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST); } } diff --git a/Tests/EventListener/ProfilerListenerTest.php b/Tests/EventListener/ProfilerListenerTest.php index 4b076ef17d..8f7aca2a00 100644 --- a/Tests/EventListener/ProfilerListenerTest.php +++ b/Tests/EventListener/ProfilerListenerTest.php @@ -12,14 +12,18 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener; use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Response; 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\HttpKernelInterface; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\Profiler\Profile; +use Symfony\Component\HttpKernel\Profiler\Profiler; class ProfilerListenerTest extends TestCase { @@ -30,27 +34,15 @@ public function testKernelTerminate() { $profile = new Profile('token'); - $profiler = $this->getMockBuilder(\Symfony\Component\HttpKernel\Profiler\Profiler::class) - ->disableOriginalConstructor() - ->getMock(); - + $profiler = $this->createMock(Profiler::class); $profiler->expects($this->once()) ->method('collect') ->willReturn($profile); - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock(); - - $masterRequest = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Request::class) - ->disableOriginalConstructor() - ->getMock(); - - $subRequest = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Request::class) - ->disableOriginalConstructor() - ->getMock(); - - $response = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Response::class) - ->disableOriginalConstructor() - ->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); + $masterRequest = $this->createMock(Request::class); + $subRequest = $this->createMock(Request::class); + $response = $this->createMock(Response::class); $requestStack = new RequestStack(); $requestStack->push($masterRequest); diff --git a/Tests/EventListener/ResponseListenerTest.php b/Tests/EventListener/ResponseListenerTest.php index 31cfa38477..6c5af2a6dd 100644 --- a/Tests/EventListener/ResponseListenerTest.php +++ b/Tests/EventListener/ResponseListenerTest.php @@ -32,7 +32,7 @@ protected function setUp(): void $listener = new ResponseListener('UTF-8'); $this->dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); - $this->kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $this->kernel = $this->createMock(HttpKernelInterface::class); } protected function tearDown(): void diff --git a/Tests/EventListener/RouterListenerTest.php b/Tests/EventListener/RouterListenerTest.php index 59e63deea8..cc46fd8db5 100644 --- a/Tests/EventListener/RouterListenerTest.php +++ b/Tests/EventListener/RouterListenerTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\Tests\EventListener; use PHPUnit\Framework\TestCase; +use Psr\Log\LoggerInterface; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -22,9 +23,12 @@ use Symfony\Component\HttpKernel\EventListener\ErrorListener; use Symfony\Component\HttpKernel\EventListener\RouterListener; use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\Routing\Exception\NoConfigurationException; +use Symfony\Component\Routing\Matcher\RequestMatcherInterface; +use Symfony\Component\Routing\Matcher\UrlMatcherInterface; use Symfony\Component\Routing\RequestContext; class RouterListenerTest extends TestCase @@ -33,7 +37,7 @@ class RouterListenerTest extends TestCase protected function setUp(): void { - $this->requestStack = $this->getMockBuilder(RequestStack::class)->disableOriginalConstructor()->getMock(); + $this->requestStack = $this->createMock(RequestStack::class); } /** @@ -41,9 +45,8 @@ protected function setUp(): void */ public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHttpPort, $expectedHttpsPort) { - $urlMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\UrlMatcherInterface::class) - ->disableOriginalConstructor() - ->getMock(); + $urlMatcher = $this->createMock(UrlMatcherInterface::class); + $context = new RequestContext(); $context->setHttpPort($defaultHttpPort); $context->setHttpsPort($defaultHttpsPort); @@ -72,7 +75,7 @@ public function getPortData() private function createRequestEventForUri(string $uri): RequestEvent { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create($uri); $request->attributes->set('_controller', null); // Prevents going in to routing process @@ -87,11 +90,11 @@ public function testInvalidMatcher() public function testRequestMatcher() { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://localhost/'); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher->expects($this->once()) ->method('matchRequest') ->with($this->isInstanceOf(Request::class)) @@ -103,11 +106,11 @@ public function testRequestMatcher() public function testSubRequestWithDifferentMethod() { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://localhost/', 'post'); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher->expects($this->any()) ->method('matchRequest') ->with($this->isInstanceOf(Request::class)) @@ -119,7 +122,7 @@ public function testSubRequestWithDifferentMethod() $listener->onKernelRequest($event); // sub-request with another HTTP method - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://localhost/', 'get'); $event = new RequestEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST); @@ -133,17 +136,17 @@ public function testSubRequestWithDifferentMethod() */ public function testLoggingParameter($parameter, $log, $parameters) { - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher->expects($this->once()) ->method('matchRequest') ->willReturn($parameter); - $logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock(); + $logger = $this->createMock(LoggerInterface::class); $logger->expects($this->once()) ->method('info') ->with($this->equalTo($log), $this->equalTo($parameters)); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://localhost/'); $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext(), $logger); @@ -162,7 +165,7 @@ public function testWithBadRequest() { $requestStack = new RequestStack(); - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher->expects($this->never())->method('matchRequest'); $dispatcher = new EventDispatcher(); @@ -184,7 +187,7 @@ public function testNoRoutingConfigurationResponse() { $requestStack = new RequestStack(); - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher ->expects($this->once()) ->method('matchRequest') @@ -204,12 +207,12 @@ public function testNoRoutingConfigurationResponse() public function testRequestWithBadHost() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $this->expectException(BadRequestHttpException::class); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://bad host %22/'); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); - $requestMatcher = $this->getMockBuilder(\Symfony\Component\Routing\Matcher\RequestMatcherInterface::class)->getMock(); + $requestMatcher = $this->createMock(RequestMatcherInterface::class); $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext()); $listener->onKernelRequest($event); diff --git a/Tests/EventListener/SaveSessionListenerTest.php b/Tests/EventListener/SaveSessionListenerTest.php index 6cdd7476c9..f79b73c5fe 100644 --- a/Tests/EventListener/SaveSessionListenerTest.php +++ b/Tests/EventListener/SaveSessionListenerTest.php @@ -27,7 +27,7 @@ class SaveSessionListenerTest extends TestCase public function testOnlyTriggeredOnMasterRequest() { $listener = new SaveSessionListener(); - $event = $this->getMockBuilder(ResponseEvent::class)->disableOriginalConstructor()->getMock(); + $event = $this->createMock(ResponseEvent::class); $event->expects($this->once())->method('isMasterRequest')->willReturn(false); $event->expects($this->never())->method('getRequest'); @@ -38,9 +38,9 @@ public function testOnlyTriggeredOnMasterRequest() public function testSessionSaved() { $listener = new SaveSessionListener(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); - $session = $this->getMockBuilder(SessionInterface::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(SessionInterface::class); $session->expects($this->once())->method('isStarted')->willReturn(true); $session->expects($this->once())->method('save'); diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index 8131ff2ea1..de1069606b 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -32,7 +32,7 @@ class SessionListenerTest extends TestCase public function testOnlyTriggeredOnMasterRequest() { $listener = $this->getMockForAbstractClass(AbstractSessionListener::class); - $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); + $event = $this->createMock(RequestEvent::class); $event->expects($this->once())->method('isMasterRequest')->willReturn(false); $event->expects($this->never())->method('getRequest'); @@ -42,12 +42,12 @@ public function testOnlyTriggeredOnMasterRequest() public function testSessionIsSet() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); - $requestStack = $this->getMockBuilder(RequestStack::class)->getMock(); + $requestStack = $this->createMock(RequestStack::class); $requestStack->expects($this->once())->method('getMasterRequest')->willReturn(null); - $sessionStorage = $this->getMockBuilder(NativeSessionStorage::class)->getMock(); + $sessionStorage = $this->createMock(NativeSessionStorage::class); $sessionStorage->expects($this->never())->method('setOptions')->with(['cookie_secure' => true]); $container = new Container(); @@ -58,7 +58,7 @@ public function testSessionIsSet() $request = new Request(); $listener = new SessionListener($container); - $event = $this->getMockBuilder(RequestEvent::class)->disableOriginalConstructor()->getMock(); + $event = $this->createMock(RequestEvent::class); $event->expects($this->once())->method('isMasterRequest')->willReturn(true); $event->expects($this->once())->method('getRequest')->willReturn($request); @@ -70,14 +70,14 @@ public function testSessionIsSet() public function testResponseIsPrivateIfSessionStarted() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1)); $container = new Container(); $container->set('initialized_session', $session); $listener = new SessionListener($container); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); @@ -95,14 +95,14 @@ public function testResponseIsPrivateIfSessionStarted() public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1)); $container = new Container(); $container->set('initialized_session', $session); $listener = new SessionListener($container); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); @@ -122,7 +122,7 @@ public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent() public function testUninitializedSession() { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $response = new Response(); $response->setSharedMaxAge(60); $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true'); @@ -143,7 +143,7 @@ public function testUninitializedSession() public function testSurrogateMasterRequestIsPublic() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->expects($this->exactly(4))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1, 1, 1)); $container = new Container(); @@ -151,7 +151,7 @@ public function testSurrogateMasterRequestIsPublic() $container->set('session', $session); $listener = new SessionListener($container); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $response = new Response(); @@ -182,9 +182,9 @@ public function testSurrogateMasterRequestIsPublic() public function testGetSessionIsCalledOnce() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); - $sessionStorage = $this->getMockBuilder(NativeSessionStorage::class)->getMock(); - $kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); + $session = $this->createMock(Session::class); + $sessionStorage = $this->createMock(NativeSessionStorage::class); + $kernel = $this->createMock(KernelInterface::class); $sessionStorage->expects($this->once()) ->method('setOptions') diff --git a/Tests/EventListener/SurrogateListenerTest.php b/Tests/EventListener/SurrogateListenerTest.php index e4b8b2d558..fc7e4d83ac 100644 --- a/Tests/EventListener/SurrogateListenerTest.php +++ b/Tests/EventListener/SurrogateListenerTest.php @@ -26,7 +26,7 @@ class SurrogateListenerTest extends TestCase public function testFilterDoesNothingForSubRequests() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $response = new Response('foo '); $listener = new SurrogateListener(new Esi()); @@ -40,7 +40,7 @@ public function testFilterDoesNothingForSubRequests() public function testFilterWhenThereIsSomeEsiIncludes() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $response = new Response('foo '); $listener = new SurrogateListener(new Esi()); @@ -54,7 +54,7 @@ public function testFilterWhenThereIsSomeEsiIncludes() public function testFilterWhenThereIsNoEsiIncludes() { $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $response = new Response('foo'); $listener = new SurrogateListener(new Esi()); diff --git a/Tests/EventListener/TestSessionListenerTest.php b/Tests/EventListener/TestSessionListenerTest.php index e0a5cc69da..2ec6581694 100644 --- a/Tests/EventListener/TestSessionListenerTest.php +++ b/Tests/EventListener/TestSessionListenerTest.php @@ -14,9 +14,11 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpFoundation\Session\Session; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; +use Symfony\Component\HttpKernel\EventListener\AbstractTestSessionListener; use Symfony\Component\HttpKernel\EventListener\SessionListener; use Symfony\Component\HttpKernel\EventListener\TestSessionListener; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -42,7 +44,7 @@ class TestSessionListenerTest extends TestCase protected function setUp(): void { - $this->listener = $this->getMockForAbstractClass(\Symfony\Component\HttpKernel\EventListener\AbstractTestSessionListener::class); + $this->listener = $this->getMockForAbstractClass(AbstractTestSessionListener::class); $this->session = $this->getSession(); $this->listener->expects($this->any()) ->method('getSession') @@ -95,7 +97,7 @@ public function testEmptySessionWithNewSessionIdDoesSendCookie() $this->sessionIsEmpty(); $this->fixSessionId('456'); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); @@ -114,7 +116,7 @@ public function testSessionWithNewSessionIdAndNewCookieDoesNotSendAnotherCookie( $this->sessionIsEmpty(); $this->fixSessionId('456'); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); @@ -145,7 +147,7 @@ public function testUnstartedSessionIsNotSave() public function testDoesNotThrowIfRequestDoesNotHaveASession() { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); $this->listener->onKernelResponse($event); @@ -157,7 +159,7 @@ private function filterResponse(Request $request, $type = HttpKernelInterface::M { $request->setSession($this->session); $response = $response ?: new Response(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $event = new ResponseEvent($kernel, $request, $type, $response); $this->listener->onKernelResponse($event); @@ -209,11 +211,7 @@ private function fixSessionId($sessionId) private function getSession() { - $mock = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Session\Session::class) - ->disableOriginalConstructor() - ->getMock(); - - // set return value for getName() + $mock = $this->createMock(Session::class); $mock->expects($this->any())->method('getName')->willReturn('MOCKSESSID'); return $mock; diff --git a/Tests/EventListener/TranslatorListenerTest.php b/Tests/EventListener/TranslatorListenerTest.php index 1fe4d1f2fa..26097696dd 100644 --- a/Tests/EventListener/TranslatorListenerTest.php +++ b/Tests/EventListener/TranslatorListenerTest.php @@ -13,6 +13,7 @@ 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\TranslatorListener; @@ -30,8 +31,8 @@ class TranslatorListenerTest extends TestCase protected function setUp(): void { - $this->translator = $this->getMockBuilder(LocaleAwareInterface::class)->getMock(); - $this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock(); + $this->translator = $this->createMock(LocaleAwareInterface::class); + $this->requestStack = $this->createMock(RequestStack::class); $this->listener = new TranslatorListener($this->translator, $this->requestStack); } @@ -105,7 +106,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest() private function createHttpKernel() { - return $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + return $this->createMock(HttpKernelInterface::class); } private function createRequest($locale) diff --git a/Tests/EventListener/ValidateRequestListenerTest.php b/Tests/EventListener/ValidateRequestListenerTest.php index 96b686d91b..d23832d80a 100644 --- a/Tests/EventListener/ValidateRequestListenerTest.php +++ b/Tests/EventListener/ValidateRequestListenerTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener; @@ -28,9 +29,9 @@ protected function tearDown(): void public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps() { - $this->expectException(\Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException::class); + $this->expectException(ConflictingHeadersException::class); $dispatcher = new EventDispatcher(); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $request->setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_FOR | Request::HEADER_FORWARDED); diff --git a/Tests/Fragment/EsiFragmentRendererTest.php b/Tests/Fragment/EsiFragmentRendererTest.php index c9af77149c..3817f4897e 100644 --- a/Tests/Fragment/EsiFragmentRendererTest.php +++ b/Tests/Fragment/EsiFragmentRendererTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpKernel\Fragment\EsiFragmentRenderer; +use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer; use Symfony\Component\HttpKernel\HttpCache\Esi; use Symfony\Component\HttpKernel\UriSigner; @@ -91,7 +92,7 @@ public function testRenderAltControllerReferenceWithoutSignerThrowsException() private function getInlineStrategy($called = false) { - $inline = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer::class)->disableOriginalConstructor()->getMock(); + $inline = $this->createMock(InlineFragmentRenderer::class); if ($called) { $inline->expects($this->once())->method('render'); diff --git a/Tests/Fragment/FragmentHandlerTest.php b/Tests/Fragment/FragmentHandlerTest.php index fa011c8f29..7ad4f3e704 100644 --- a/Tests/Fragment/FragmentHandlerTest.php +++ b/Tests/Fragment/FragmentHandlerTest.php @@ -13,8 +13,10 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Fragment\FragmentHandler; +use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface; /** * @group time-sensitive @@ -25,10 +27,7 @@ class FragmentHandlerTest extends TestCase protected function setUp(): void { - $this->requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class) - ->disableOriginalConstructor() - ->getMock() - ; + $this->requestStack = $this->createMock(RequestStack::class); $this->requestStack ->expects($this->any()) ->method('getCurrentRequest') @@ -69,7 +68,7 @@ public function testRender() protected function getHandler($returnValue, $arguments = []) { - $renderer = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface::class)->getMock(); + $renderer = $this->createMock(FragmentRendererInterface::class); $renderer ->expects($this->any()) ->method('getName') diff --git a/Tests/Fragment/HIncludeFragmentRendererTest.php b/Tests/Fragment/HIncludeFragmentRendererTest.php index ae1cb15516..665c1d458a 100644 --- a/Tests/Fragment/HIncludeFragmentRendererTest.php +++ b/Tests/Fragment/HIncludeFragmentRendererTest.php @@ -16,6 +16,7 @@ use Symfony\Component\HttpKernel\Controller\ControllerReference; use Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer; use Symfony\Component\HttpKernel\UriSigner; +use Symfony\Component\Templating\EngineInterface; use Twig\Environment; use Twig\Loader\ArrayLoader; @@ -86,7 +87,7 @@ public function testRenderWithTwigAndDefaultText() */ public function testRenderWithDefaultTextLegacy() { - $engine = $this->getMockBuilder(\Symfony\Component\Templating\EngineInterface::class)->getMock(); + $engine = $this->createMock(EngineInterface::class); $engine->expects($this->once()) ->method('exists') ->with('default') diff --git a/Tests/Fragment/InlineFragmentRendererTest.php b/Tests/Fragment/InlineFragmentRendererTest.php index c25297dbe4..c70a1ae6f0 100644 --- a/Tests/Fragment/InlineFragmentRendererTest.php +++ b/Tests/Fragment/InlineFragmentRendererTest.php @@ -16,10 +16,13 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer; use Symfony\Component\HttpKernel\HttpKernel; +use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; @@ -72,7 +75,7 @@ public function testRenderWithTrustedHeaderDisabled() public function testRenderExceptionNoIgnoreErrors() { $this->expectException(\RuntimeException::class); - $dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); + $dispatcher = $this->createMock(EventDispatcherInterface::class); $dispatcher->expects($this->never())->method('dispatch'); $strategy = new InlineFragmentRenderer($this->getKernel($this->throwException(new \RuntimeException('foo'))), $dispatcher); @@ -86,7 +89,7 @@ public function testRenderExceptionIgnoreErrors() $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 = $this->createMock(EventDispatcherInterface::class); $dispatcher->expects($this->once())->method('dispatch')->with($expectedEvent, KernelEvents::EXCEPTION); $strategy = new InlineFragmentRenderer($kernel, $dispatcher); @@ -106,7 +109,7 @@ public function testRenderExceptionIgnoreErrorsWithAlt() private function getKernel($returnValue) { - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel ->expects($this->any()) ->method('handle') @@ -118,7 +121,7 @@ private function getKernel($returnValue) public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() { - $controllerResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ControllerResolverInterface::class)->getMock(); + $controllerResolver = $this->createMock(ControllerResolverInterface::class); $controllerResolver ->expects($this->once()) ->method('getController') @@ -129,7 +132,7 @@ public function testExceptionInSubRequestsDoesNotMangleOutputBuffers() }) ; - $argumentResolver = $this->getMockBuilder(\Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface::class)->getMock(); + $argumentResolver = $this->createMock(ArgumentResolverInterface::class); $argumentResolver ->expects($this->once()) ->method('getArguments') @@ -258,7 +261,7 @@ public function testIpAddressOfRangedTrustedProxyIsSetAsRemote() */ private function getKernelExpectingRequest(Request $request, $strict = false) { - $kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernelInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $kernel ->expects($this->once()) ->method('handle') diff --git a/Tests/Fragment/RoutableFragmentRendererTest.php b/Tests/Fragment/RoutableFragmentRendererTest.php index 5980284afe..d17643c186 100644 --- a/Tests/Fragment/RoutableFragmentRendererTest.php +++ b/Tests/Fragment/RoutableFragmentRendererTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer; class RoutableFragmentRendererTest extends TestCase { @@ -74,7 +75,7 @@ public function getGenerateFragmentUriDataWithNonScalar() private function callGenerateFragmentUriMethod(ControllerReference $reference, Request $request, $absolute = false) { - $renderer = $this->getMockForAbstractClass(\Symfony\Component\HttpKernel\Fragment\RoutableFragmentRenderer::class); + $renderer = $this->getMockForAbstractClass(RoutableFragmentRenderer::class); $r = new \ReflectionObject($renderer); $m = $r->getMethod('generateFragmentUri'); $m->setAccessible(true); diff --git a/Tests/Fragment/SsiFragmentRendererTest.php b/Tests/Fragment/SsiFragmentRendererTest.php index db203f91de..63a92028f4 100644 --- a/Tests/Fragment/SsiFragmentRendererTest.php +++ b/Tests/Fragment/SsiFragmentRendererTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer; use Symfony\Component\HttpKernel\Fragment\SsiFragmentRenderer; use Symfony\Component\HttpKernel\HttpCache\Ssi; use Symfony\Component\HttpKernel\UriSigner; @@ -82,7 +83,7 @@ public function testRenderAltControllerReferenceWithoutSignerThrowsException() private function getInlineStrategy($called = false) { - $inline = $this->getMockBuilder(\Symfony\Component\HttpKernel\Fragment\InlineFragmentRenderer::class)->disableOriginalConstructor()->getMock(); + $inline = $this->createMock(InlineFragmentRenderer::class); if ($called) { $inline->expects($this->once())->method('render'); diff --git a/Tests/HttpCache/EsiTest.php b/Tests/HttpCache/EsiTest.php index 5246721a64..e708c2ae5f 100644 --- a/Tests/HttpCache/EsiTest.php +++ b/Tests/HttpCache/EsiTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\HttpCache\Esi; +use Symfony\Component\HttpKernel\HttpCache\HttpCache; class EsiTest extends TestCase { @@ -222,7 +223,7 @@ public function testHandleWhenResponseIsNot200AndAltIsPresent() protected function getCache($request, $response) { - $cache = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); + $cache = $this->getMockBuilder(HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); $cache->expects($this->any()) ->method('getRequest') ->willReturn($request) diff --git a/Tests/HttpCache/HttpCacheTest.php b/Tests/HttpCache/HttpCacheTest.php index 932f46c6ef..d9dd572bf1 100644 --- a/Tests/HttpCache/HttpCacheTest.php +++ b/Tests/HttpCache/HttpCacheTest.php @@ -16,7 +16,9 @@ use Symfony\Component\HttpKernel\HttpCache\Esi; use Symfony\Component\HttpKernel\HttpCache\HttpCache; use Symfony\Component\HttpKernel\HttpCache\Store; +use Symfony\Component\HttpKernel\HttpCache\StoreInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\Kernel; /** * @group time-sensitive @@ -25,7 +27,7 @@ class HttpCacheTest extends HttpCacheTestCase { public function testTerminateDelegatesTerminationOnlyForTerminableInterface() { - $storeMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\StoreInterface::class) + $storeMock = $this->getMockBuilder(StoreInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -37,7 +39,7 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface() $this->assertFalse($kernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface'); // implements TerminableInterface - $kernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\Kernel::class) + $kernelMock = $this->getMockBuilder(Kernel::class) ->disableOriginalConstructor() ->setMethods(['terminate', 'registerBundles', 'registerContainerConfiguration']) ->getMock(); @@ -1488,8 +1490,8 @@ public function testDoesNotCacheOptionsRequest() public function testUsesOriginalRequestForSurrogate() { - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->getMock(); - $store = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\StoreInterface::class)->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); + $store = $this->createMock(StoreInterface::class); $kernel ->expects($this->exactly(2)) diff --git a/Tests/HttpCache/SsiTest.php b/Tests/HttpCache/SsiTest.php index 23c7410a28..157c4d7455 100644 --- a/Tests/HttpCache/SsiTest.php +++ b/Tests/HttpCache/SsiTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\HttpCache\HttpCache; use Symfony\Component\HttpKernel\HttpCache\Ssi; class SsiTest extends TestCase @@ -189,7 +190,7 @@ public function testHandleWhenResponseIsNot200AndAltIsPresent() protected function getCache($request, $response) { - $cache = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpCache\HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); + $cache = $this->getMockBuilder(HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); $cache->expects($this->any()) ->method('getRequest') ->willReturn($request) diff --git a/Tests/HttpClientKernelTest.php b/Tests/HttpClientKernelTest.php index 2b904bf9a2..27b3a82e03 100644 --- a/Tests/HttpClientKernelTest.php +++ b/Tests/HttpClientKernelTest.php @@ -24,10 +24,10 @@ public function testHandlePassesMaxRedirectsHttpClientOption() $request = new Request(); $request->attributes->set('http_client_options', ['max_redirects' => 50]); - $response = $this->getMockBuilder(ResponseInterface::class)->getMock(); + $response = $this->createMock(ResponseInterface::class); $response->expects($this->once())->method('getStatusCode')->willReturn(200); - $client = $this->getMockBuilder(HttpClientInterface::class)->getMock(); + $client = $this->createMock(HttpClientInterface::class); $client ->expects($this->once()) ->method('request') diff --git a/Tests/HttpKernelBrowserTest.php b/Tests/HttpKernelBrowserTest.php index eab6c5221c..7cd4d52d39 100644 --- a/Tests/HttpKernelBrowserTest.php +++ b/Tests/HttpKernelBrowserTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\File\UploadedFile; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\HttpKernelBrowser; @@ -31,7 +32,7 @@ public function testDoRequest() $client->request('GET', '/'); $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request'); $this->assertInstanceOf(\Symfony\Component\BrowserKit\Request::class, $client->getInternalRequest()); - $this->assertInstanceOf(\Symfony\Component\HttpFoundation\Request::class, $client->getRequest()); + $this->assertInstanceOf(Request::class, $client->getRequest()); $this->assertInstanceOf(\Symfony\Component\BrowserKit\Response::class, $client->getInternalResponse()); $this->assertInstanceOf(Response::class, $client->getResponse()); diff --git a/Tests/HttpKernelTest.php b/Tests/HttpKernelTest.php index 5c954261b6..014dc752c3 100644 --- a/Tests/HttpKernelTest.php +++ b/Tests/HttpKernelTest.php @@ -21,8 +21,10 @@ use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\ControllerDoesNotReturnResponseException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; @@ -156,7 +158,7 @@ public function testHandleWhenAListenerReturnsAResponse() public function testHandleWhenNoControllerIsFound() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class); + $this->expectException(NotFoundHttpException::class); $dispatcher = new EventDispatcher(); $kernel = $this->getHttpKernel($dispatcher, false); @@ -315,7 +317,7 @@ public function testVerifyRequestStackPushPopDuringHandle() public function testInconsistentClientIpsOnMasterRequests() { - $this->expectException(\Symfony\Component\HttpKernel\Exception\BadRequestHttpException::class); + $this->expectException(BadRequestHttpException::class); $request = new Request(); $request->setTrustedProxies(['1.1.1.1'], Request::HEADER_X_FORWARDED_FOR | Request::HEADER_FORWARDED); $request->server->set('REMOTE_ADDR', '1.1.1.1'); @@ -339,13 +341,13 @@ private function getHttpKernel(EventDispatcherInterface $eventDispatcher, $contr $controller = function () { return new Response('Hello'); }; } - $controllerResolver = $this->getMockBuilder(ControllerResolverInterface::class)->getMock(); + $controllerResolver = $this->createMock(ControllerResolverInterface::class); $controllerResolver ->expects($this->any()) ->method('getController') ->willReturn($controller); - $argumentResolver = $this->getMockBuilder(ArgumentResolverInterface::class)->getMock(); + $argumentResolver = $this->createMock(ArgumentResolverInterface::class); $argumentResolver ->expects($this->any()) ->method('getArguments') diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index 570e6f0298..9e48e4274e 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -19,9 +19,11 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\Bundle\BundleInterface; use Symfony\Component\HttpKernel\DependencyInjection\ResettableServicePass; use Symfony\Component\HttpKernel\DependencyInjection\ServicesResetter; +use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\Tests\Fixtures\KernelForOverrideName; @@ -125,7 +127,7 @@ public function testBootInitializesBundlesAndContainer() public function testBootSetsTheContainerToTheBundles() { - $bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock(); + $bundle = $this->createMock(Bundle::class); $bundle->expects($this->once()) ->method('setContainer'); @@ -167,7 +169,7 @@ public function testBootKernelSeveralTimesOnlyInitializesBundlesOnce() public function testShutdownCallsShutdownOnAllBundles() { - $bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock(); + $bundle = $this->createMock(Bundle::class); $bundle->expects($this->once()) ->method('shutdown'); @@ -179,7 +181,7 @@ public function testShutdownCallsShutdownOnAllBundles() public function testShutdownGivesNullContainerToAllBundles() { - $bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock(); + $bundle = $this->createMock(Bundle::class); $bundle->expects($this->exactly(2)) ->method('setContainer') ->withConsecutive( @@ -202,7 +204,7 @@ public function testHandleCallsHandleOnHttpKernel() $catch = true; $request = new Request(); - $httpKernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernel::class) + $httpKernelMock = $this->getMockBuilder(HttpKernel::class) ->disableOriginalConstructor() ->getMock(); $httpKernelMock @@ -224,7 +226,7 @@ public function testHandleBootsTheKernel() $catch = true; $request = new Request(); - $httpKernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernel::class) + $httpKernelMock = $this->getMockBuilder(HttpKernel::class) ->disableOriginalConstructor() ->getMock(); @@ -547,7 +549,7 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface() $this->assertFalse($httpKernel->terminateCalled, 'terminate() is never called if the kernel class does not implement TerminableInterface'); // implements TerminableInterface - $httpKernelMock = $this->getMockBuilder(\Symfony\Component\HttpKernel\HttpKernel::class) + $httpKernelMock = $this->getMockBuilder(HttpKernel::class) ->disableOriginalConstructor() ->setMethods(['terminate']) ->getMock(); From b5799357d2f92b4d5405de43e6eceb556f4e6b49 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 27 Jan 2021 12:17:55 +0100 Subject: [PATCH 070/396] More cleanups and fixes --- Tests/EventListener/SessionListenerTest.php | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index 7d754a8414..48d06e5b80 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -216,14 +216,14 @@ public function testGetSessionIsCalledOnce() public function testSessionUsageExceptionIfStatelessAndSessionUsed() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1)); $container = new Container(); $container->set('initialized_session', $session); $listener = new SessionListener($container, true); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $request->attributes->set('_stateless', true); @@ -235,10 +235,10 @@ public function testSessionUsageExceptionIfStatelessAndSessionUsed() public function testSessionUsageLogIfStatelessAndSessionUsed() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1)); - $logger = $this->getMockBuilder(LoggerInterface::class)->disableOriginalConstructor()->getMock(); + $logger = $this->createMock(LoggerInterface::class); $logger->expects($this->exactly(1))->method('warning'); $container = new Container(); @@ -246,7 +246,7 @@ public function testSessionUsageLogIfStatelessAndSessionUsed() $container->set('logger', $logger); $listener = new SessionListener($container, false); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $request->attributes->set('_stateless', true); @@ -257,7 +257,7 @@ public function testSessionUsageLogIfStatelessAndSessionUsed() public function testSessionIsSavedWhenUnexpectedSessionExceptionThrown() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->method('isStarted')->willReturn(true); $session->expects($this->exactly(2))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1)); $session->expects($this->exactly(1))->method('save'); @@ -266,7 +266,7 @@ public function testSessionIsSavedWhenUnexpectedSessionExceptionThrown() $container->set('initialized_session', $session); $listener = new SessionListener($container, true); - $kernel = $this->getMockBuilder(HttpKernelInterface::class)->disableOriginalConstructor()->getMock(); + $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); $request->attributes->set('_stateless', true); @@ -280,7 +280,7 @@ public function testSessionIsSavedWhenUnexpectedSessionExceptionThrown() public function testSessionUsageCallbackWhenDebugAndStateless() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->method('isStarted')->willReturn(true); $session->expects($this->exactly(1))->method('save'); @@ -303,14 +303,14 @@ public function testSessionUsageCallbackWhenDebugAndStateless() public function testSessionUsageCallbackWhenNoDebug() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->method('isStarted')->willReturn(true); $session->expects($this->exactly(0))->method('save'); $request = new Request(); $request->attributes->set('_stateless', true); - $requestStack = $this->getMockBuilder(RequestStack::class)->getMock(); + $requestStack = $this->createMock(RequestStack::class); $requestStack->expects($this->never())->method('getMasterRequest')->willReturn($request); $container = new Container(); @@ -322,7 +322,7 @@ public function testSessionUsageCallbackWhenNoDebug() public function testSessionUsageCallbackWhenNoStateless() { - $session = $this->getMockBuilder(Session::class)->disableOriginalConstructor()->getMock(); + $session = $this->createMock(Session::class); $session->method('isStarted')->willReturn(true); $session->expects($this->never())->method('save'); From 07ea794a327d7c8c5d76e3058fde9fec6a711cb4 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 27 Jan 2021 14:50:53 +0100 Subject: [PATCH 071/396] Update VERSION for 4.4.19 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index c9317c81ca..19fead0808 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.19-DEV'; + public const VERSION = '4.4.19'; public const VERSION_ID = 40419; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; public const RELEASE_VERSION = 19; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From 55ad860f5f8467cb4a2e0bc08f58e9959134b023 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 27 Jan 2021 14:59:11 +0100 Subject: [PATCH 072/396] Bump Symfony version to 4.4.20 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 19fead0808..f2b1966ea5 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.19'; - public const VERSION_ID = 40419; + public const VERSION = '4.4.20-DEV'; + public const VERSION_ID = 40420; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; - public const RELEASE_VERSION = 19; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 20; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From 831b51e9370ece0febd0950dd819c63f996721c7 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 27 Jan 2021 15:45:46 +0100 Subject: [PATCH 073/396] Update VERSION for 5.2.2 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 186dbb490d..409f951939 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.2-DEV'; + public const VERSION = '5.2.2'; public const VERSION_ID = 50202; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; public const RELEASE_VERSION = 2; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From d4f242eaaedee6f2a8a83318b35d6668fefe3d2e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 27 Jan 2021 15:55:33 +0100 Subject: [PATCH 074/396] Bump Symfony version to 5.2.3 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 409f951939..a83b264db9 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.2'; - public const VERSION_ID = 50202; + public const VERSION = '5.2.3-DEV'; + public const VERSION_ID = 50203; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; - public const RELEASE_VERSION = 2; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 3; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From f368f7ef36b083beb6d2acfd1c79314fc3829f46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Sat, 17 Oct 2020 23:28:45 +0200 Subject: [PATCH 075/396] Deprecat service "session" --- DependencyInjection/RegisterControllerArgumentLocatorsPass.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php index a2a9a0c71b..e24e0e6d64 100644 --- a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php +++ b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php @@ -23,6 +23,7 @@ use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\DependencyInjection\TypedReference; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Session\SessionInterface; /** * Creates the service-locators required by ServiceValueResolver. @@ -165,7 +166,7 @@ public function process(ContainerBuilder $container) $invalidBehavior = ContainerInterface::RUNTIME_EXCEPTION_ON_INVALID_REFERENCE; } - if (Request::class === $type) { + if (Request::class === $type || SessionInterface::class === $type) { continue; } From 48df45950657aaaf94ad4b7db1bd4574eccc47a3 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 27 Jan 2021 14:04:45 +0100 Subject: [PATCH 076/396] Use createMock() instead of a getter --- Tests/CacheClearer/ChainCacheClearerTest.php | 7 +------ .../AddRequestFormatsListenerTest.php | 11 ++--------- Tests/EventListener/LocaleAwareListenerTest.php | 15 +++++---------- Tests/EventListener/TranslatorListenerTest.php | 15 +++++---------- 4 files changed, 13 insertions(+), 35 deletions(-) diff --git a/Tests/CacheClearer/ChainCacheClearerTest.php b/Tests/CacheClearer/ChainCacheClearerTest.php index 80c1b576be..80d9796070 100644 --- a/Tests/CacheClearer/ChainCacheClearerTest.php +++ b/Tests/CacheClearer/ChainCacheClearerTest.php @@ -31,7 +31,7 @@ public static function tearDownAfterClass(): void public function testInjectClearersInConstructor() { - $clearer = $this->getMockClearer(); + $clearer = $this->createMock(CacheClearerInterface::class); $clearer ->expects($this->once()) ->method('clear'); @@ -39,9 +39,4 @@ public function testInjectClearersInConstructor() $chainClearer = new ChainCacheClearer([$clearer]); $chainClearer->clear(self::$cacheDir); } - - protected function getMockClearer() - { - return $this->createMock(CacheClearerInterface::class); - } } diff --git a/Tests/EventListener/AddRequestFormatsListenerTest.php b/Tests/EventListener/AddRequestFormatsListenerTest.php index def3831851..fab9a8a38f 100644 --- a/Tests/EventListener/AddRequestFormatsListenerTest.php +++ b/Tests/EventListener/AddRequestFormatsListenerTest.php @@ -19,8 +19,6 @@ use Symfony\Component\HttpKernel\KernelEvents; /** - * Test AddRequestFormatsListener class. - * * @author Gildas Quemener */ class AddRequestFormatsListenerTest extends TestCase @@ -47,7 +45,7 @@ public function testIsAnEventSubscriber() public function testRegisteredEvent() { - $this->assertEquals( + $this->assertSame( [KernelEvents::REQUEST => ['onKernelRequest', 100]], AddRequestFormatsListener::getSubscribedEvents() ); @@ -55,7 +53,7 @@ public function testRegisteredEvent() public function testSetAdditionalFormats() { - $request = $this->getRequestMock(); + $request = $this->createMock(Request::class); $event = $this->getRequestEventMock($request); $request->expects($this->once()) @@ -65,11 +63,6 @@ public function testSetAdditionalFormats() $this->listener->onKernelRequest($event); } - protected function getRequestMock() - { - return $this->createMock(Request::class); - } - protected function getRequestEventMock(Request $request) { $event = $this->createMock(RequestEvent::class); diff --git a/Tests/EventListener/LocaleAwareListenerTest.php b/Tests/EventListener/LocaleAwareListenerTest.php index 20c9f9d8c9..ab92a79168 100644 --- a/Tests/EventListener/LocaleAwareListenerTest.php +++ b/Tests/EventListener/LocaleAwareListenerTest.php @@ -40,7 +40,7 @@ public function testLocaleIsSetInOnKernelRequest() ->method('setLocale') ->with($this->equalTo('fr')); - $event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); } @@ -57,7 +57,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest() $this->throwException(new \InvalidArgumentException()) ); - $event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); } @@ -71,7 +71,7 @@ public function testLocaleIsSetInOnKernelFinishRequestWhenParentRequestExists() $this->requestStack->push($this->createRequest('fr')); $this->requestStack->push($subRequest = $this->createRequest('de')); - $event = new FinishRequestEvent($this->createHttpKernel(), $subRequest, HttpKernelInterface::SUB_REQUEST); + $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $subRequest, HttpKernelInterface::SUB_REQUEST); $this->listener->onKernelFinishRequest($event); } @@ -84,7 +84,7 @@ public function testLocaleIsSetToDefaultOnKernelFinishRequestWhenParentRequestDo $this->requestStack->push($subRequest = $this->createRequest('de')); - $event = new FinishRequestEvent($this->createHttpKernel(), $subRequest, HttpKernelInterface::SUB_REQUEST); + $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $subRequest, HttpKernelInterface::SUB_REQUEST); $this->listener->onKernelFinishRequest($event); } @@ -104,15 +104,10 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest() $this->requestStack->push($this->createRequest('fr')); $this->requestStack->push($subRequest = $this->createRequest('de')); - $event = new FinishRequestEvent($this->createHttpKernel(), $subRequest, HttpKernelInterface::SUB_REQUEST); + $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $subRequest, HttpKernelInterface::SUB_REQUEST); $this->listener->onKernelFinishRequest($event); } - private function createHttpKernel() - { - return $this->createMock(HttpKernelInterface::class); - } - private function createRequest($locale) { $request = new Request(); diff --git a/Tests/EventListener/TranslatorListenerTest.php b/Tests/EventListener/TranslatorListenerTest.php index 26097696dd..1eb86b7fb9 100644 --- a/Tests/EventListener/TranslatorListenerTest.php +++ b/Tests/EventListener/TranslatorListenerTest.php @@ -43,7 +43,7 @@ public function testLocaleIsSetInOnKernelRequest() ->method('setLocale') ->with($this->equalTo('fr')); - $event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); } @@ -60,7 +60,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest() $this->throwException(new \InvalidArgumentException()) ); - $event = new RequestEvent($this->createHttpKernel(), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); $this->listener->onKernelRequest($event); } @@ -72,7 +72,7 @@ public function testLocaleIsSetInOnKernelFinishRequestWhenParentRequestExists() ->with($this->equalTo('fr')); $this->setMasterRequest($this->createRequest('fr')); - $event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST); + $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST); $this->listener->onKernelFinishRequest($event); } @@ -82,7 +82,7 @@ public function testLocaleIsNotSetInOnKernelFinishRequestWhenParentRequestDoesNo ->expects($this->never()) ->method('setLocale'); - $event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST); + $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST); $this->listener->onKernelFinishRequest($event); } @@ -100,15 +100,10 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest() ); $this->setMasterRequest($this->createRequest('fr')); - $event = new FinishRequestEvent($this->createHttpKernel(), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST); + $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('de'), HttpKernelInterface::SUB_REQUEST); $this->listener->onKernelFinishRequest($event); } - private function createHttpKernel() - { - return $this->createMock(HttpKernelInterface::class); - } - private function createRequest($locale) { $request = new Request(); From 6c087988b152fe13a57a93fd711b7ae6e162a7d0 Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Fri, 29 Jan 2021 12:00:10 +0100 Subject: [PATCH 077/396] Show full URI when route not found When accessing a route that does not exist, Symfony throws a `NotFoundHttpException` that says `No route found for "POST /path"`. On some projects this might be good enough to find the root cause, but on projects that have lots of routes on different hosts, it becomes hard to understand how the request was initiated. Was it done over HTTP or HTTPS? What was the hostname? Did the user specify a port? To make this easier, we now show the full URI of the path, like this: `No route found for "POST https://www.symfony.com/path"`. --- EventListener/RouterListener.php | 4 +- Tests/EventListener/RouterListenerTest.php | 57 ++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/EventListener/RouterListener.php b/EventListener/RouterListener.php index c10897a9e2..9c36f7cb58 100644 --- a/EventListener/RouterListener.php +++ b/EventListener/RouterListener.php @@ -127,7 +127,7 @@ public function onKernelRequest(RequestEvent $event) unset($parameters['_route'], $parameters['_controller']); $request->attributes->set('_route_params', $parameters); } catch (ResourceNotFoundException $e) { - $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getPathInfo()); + $message = sprintf('No route found for "%s %s"', $request->getMethod(), $request->getUriForPath($request->getPathInfo())); if ($referer = $request->headers->get('referer')) { $message .= sprintf(' (from "%s")', $referer); @@ -135,7 +135,7 @@ public function onKernelRequest(RequestEvent $event) throw new NotFoundHttpException($message, $e); } catch (MethodNotAllowedException $e) { - $message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod(), $request->getPathInfo(), implode(', ', $e->getAllowedMethods())); + $message = sprintf('No route found for "%s %s": Method Not Allowed (Allow: %s)', $request->getMethod(), $request->getUriForPath($request->getPathInfo()), implode(', ', $e->getAllowedMethods())); throw new MethodNotAllowedHttpException($e->getAllowedMethods(), $message, $e); } diff --git a/Tests/EventListener/RouterListenerTest.php b/Tests/EventListener/RouterListenerTest.php index cc46fd8db5..453bf5b0e3 100644 --- a/Tests/EventListener/RouterListenerTest.php +++ b/Tests/EventListener/RouterListenerTest.php @@ -24,9 +24,13 @@ use Symfony\Component\HttpKernel\EventListener\RouterListener; use Symfony\Component\HttpKernel\EventListener\ValidateRequestListener; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; +use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Exception\NoConfigurationException; +use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Matcher\RequestMatcherInterface; use Symfony\Component\Routing\Matcher\UrlMatcherInterface; use Symfony\Component\Routing\RequestContext; @@ -217,4 +221,57 @@ public function testRequestWithBadHost() $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext()); $listener->onKernelRequest($event); } + + public function testResourceNotFoundException() + { + $this->expectException(NotFoundHttpException::class); + $this->expectExceptionMessage('No route found for "GET https://www.symfony.com/path" (from "https://www.google.com")'); + + $context = new RequestContext(); + + $urlMatcher = $this->createMock(UrlMatcherInterface::class); + + $urlMatcher->expects($this->any()) + ->method('getContext') + ->willReturn($context); + + $urlMatcher->expects($this->any()) + ->method('match') + ->willThrowException(new ResourceNotFoundException()); + + $kernel = $this->createMock(HttpKernelInterface::class); + $request = Request::create('https://www.symfony.com/path'); + $request->headers->set('referer', 'https://www.google.com'); + + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + + $listener = new RouterListener($urlMatcher, $this->requestStack); + $listener->onKernelRequest($event); + } + + public function testMethodNotAllowedException() + { + $this->expectException(MethodNotAllowedHttpException::class); + $this->expectExceptionMessage('No route found for "GET https://www.symfony.com/path": Method Not Allowed (Allow: POST)'); + + $context = new RequestContext(); + + $urlMatcher = $this->createMock(UrlMatcherInterface::class); + + $urlMatcher->expects($this->any()) + ->method('getContext') + ->willReturn($context); + + $urlMatcher->expects($this->any()) + ->method('match') + ->willThrowException(new MethodNotAllowedException(['POST'])); + + $kernel = $this->createMock(HttpKernelInterface::class); + $request = Request::create('https://www.symfony.com/path'); + + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + + $listener = new RouterListener($urlMatcher, $this->requestStack); + $listener->onKernelRequest($event); + } } From 89bac04f29e7b0b52f9fa6a4288ca7a8f90a1a05 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 3 Feb 2021 05:51:58 +0100 Subject: [PATCH 078/396] Update VERSION for 5.2.3 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index a83b264db9..18c077b5e2 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.3-DEV'; + public const VERSION = '5.2.3'; public const VERSION_ID = 50203; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; public const RELEASE_VERSION = 3; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 37d558c49fd0553d22c789efad8af18c376eb6f8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 3 Feb 2021 05:56:18 +0100 Subject: [PATCH 079/396] Bump Symfony version to 5.2.4 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 18c077b5e2..02cb1eb945 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.3'; - public const VERSION_ID = 50203; + public const VERSION = '5.2.4-DEV'; + public const VERSION_ID = 50204; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; - public const RELEASE_VERSION = 3; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 4; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 1c4e23bda397f4d69fc676500bc570517d0256b9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 4 Feb 2021 18:25:29 +0100 Subject: [PATCH 080/396] Allow psr/cache v2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 0094dc575f..61325cb0a0 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "symfony/templating": "^3.4|^4.0|^5.0", "symfony/translation": "^4.2|^5.0", "symfony/translation-contracts": "^1.1|^2", - "psr/cache": "~1.0", + "psr/cache": "^1.0|^2.0", "twig/twig": "^1.43|^2.13|^3.0.4" }, "provide": { From cde9ee85487932a1c8064ae685e5d0488c3ae12b Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Fri, 5 Feb 2021 14:33:05 +0100 Subject: [PATCH 081/396] [HttpKernel] [Kernel] Silence deprecations logs writes --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index f2b1966ea5..15a37cf58b 100644 --- a/Kernel.php +++ b/Kernel.php @@ -598,8 +598,8 @@ protected function initializeContainer() if ($collectDeprecations) { restore_error_handler(); - file_put_contents($cacheDir.'/'.$class.'Deprecations.log', serialize(array_values($collectedLogs))); - file_put_contents($cacheDir.'/'.$class.'Compiler.log', null !== $container ? implode("\n", $container->getCompiler()->getLog()) : ''); + @file_put_contents($cacheDir.'/'.$class.'Deprecations.log', serialize(array_values($collectedLogs))); + @file_put_contents($cacheDir.'/'.$class.'Compiler.log', null !== $container ? implode("\n", $container->getCompiler()->getLog()) : ''); } } From ed97eefaf3d3788be639e083c5e2a1713cb02106 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 5 Feb 2021 16:46:45 +0100 Subject: [PATCH 082/396] Allow psr/cache v3 but on symfony/cache --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 61325cb0a0..a2fa2a0eca 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "symfony/templating": "^3.4|^4.0|^5.0", "symfony/translation": "^4.2|^5.0", "symfony/translation-contracts": "^1.1|^2", - "psr/cache": "^1.0|^2.0", + "psr/cache": "^1.0|^2.0|^3.0", "twig/twig": "^1.43|^2.13|^3.0.4" }, "provide": { From c00454822f17aab61237231a953149f6ae3213c5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 10 Feb 2021 18:16:49 +0100 Subject: [PATCH 083/396] [HttpKernel] fix transient test --- Tests/KernelTest.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index 9e48e4274e..63fb4973f6 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -16,6 +16,7 @@ use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -35,8 +36,10 @@ class KernelTest extends TestCase { protected function tearDown(): void { - $fs = new Filesystem(); - $fs->remove(__DIR__.'/Fixtures/var'); + try { + (new Filesystem())->remove(__DIR__.'/Fixtures/var'); + } catch (IOException $e) { + } } public function testConstructor() @@ -586,7 +589,7 @@ public function testProjectDirExtension() public function testKernelReset() { - (new Filesystem())->remove(__DIR__.'/Fixtures/var/cache'); + $this->tearDown(); $kernel = new CustomProjectDirKernel(); $kernel->boot(); From a3050e057bf581a50f5af755b5cb841ff1feb9e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sun, 14 Feb 2021 12:49:34 +0100 Subject: [PATCH 084/396] Fix: Article --- Kernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel.php b/Kernel.php index 15a37cf58b..b335a4f207 100644 --- a/Kernel.php +++ b/Kernel.php @@ -205,7 +205,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ } /** - * Gets a HTTP kernel from the container. + * Gets an HTTP kernel from the container. * * @return HttpKernelInterface */ From 24e1d223627f5cf200321c451374fff8e0a5feed Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 16 Feb 2021 15:43:22 +0100 Subject: [PATCH 085/396] [FrameworkBundle] allow container/routing configurators to vary by env --- Kernel.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Kernel.php b/Kernel.php index 5ecad3b9a9..ad6a7e1ec0 100644 --- a/Kernel.php +++ b/Kernel.php @@ -751,15 +751,16 @@ protected function dumpContainer(ConfigCache $cache, ContainerBuilder $container */ protected function getContainerLoader(ContainerInterface $container) { + $env = $this->getEnvironment(); $locator = new FileLocator($this); $resolver = new LoaderResolver([ - new XmlFileLoader($container, $locator), - new YamlFileLoader($container, $locator), - new IniFileLoader($container, $locator), - new PhpFileLoader($container, $locator), - new GlobFileLoader($container, $locator), - new DirectoryLoader($container, $locator), - new ClosureLoader($container), + new XmlFileLoader($container, $locator, $env), + new YamlFileLoader($container, $locator, $env), + new IniFileLoader($container, $locator, $env), + new PhpFileLoader($container, $locator, $env), + new GlobFileLoader($container, $locator, $env), + new DirectoryLoader($container, $locator, $env), + new ClosureLoader($container, $env), ]); return new DelegatingLoader($resolver); From 64dd49d38f60015e84f97c636f77bc80960718e9 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 21 Feb 2021 20:10:16 +0100 Subject: [PATCH 086/396] Switched to non-null defaults in exception constructors --- Exception/AccessDeniedHttpException.php | 8 ++++---- Exception/BadRequestHttpException.php | 8 ++++---- Exception/ConflictHttpException.php | 8 ++++---- Exception/GoneHttpException.php | 8 ++++---- Exception/HttpException.php | 2 +- Exception/LengthRequiredHttpException.php | 8 ++++---- Exception/MethodNotAllowedHttpException.php | 10 +++++----- Exception/NotAcceptableHttpException.php | 8 ++++---- Exception/NotFoundHttpException.php | 8 ++++---- Exception/PreconditionFailedHttpException.php | 8 ++++---- Exception/PreconditionRequiredHttpException.php | 8 ++++---- Exception/ServiceUnavailableHttpException.php | 10 +++++----- Exception/TooManyRequestsHttpException.php | 10 +++++----- Exception/UnauthorizedHttpException.php | 10 +++++----- Exception/UnprocessableEntityHttpException.php | 8 ++++---- Exception/UnsupportedMediaTypeHttpException.php | 8 ++++---- Tests/Exception/AccessDeniedHttpExceptionTest.php | 3 ++- Tests/Exception/BadRequestHttpExceptionTest.php | 3 ++- Tests/Exception/ConflictHttpExceptionTest.php | 3 ++- Tests/Exception/GoneHttpExceptionTest.php | 3 ++- Tests/Exception/HttpExceptionTest.php | 6 +++--- Tests/Exception/LengthRequiredHttpExceptionTest.php | 3 ++- Tests/Exception/MethodNotAllowedHttpExceptionTest.php | 5 +++-- Tests/Exception/NotAcceptableHttpExceptionTest.php | 3 ++- Tests/Exception/NotFoundHttpExceptionTest.php | 3 ++- .../Exception/PreconditionFailedHttpExceptionTest.php | 3 ++- .../PreconditionRequiredHttpExceptionTest.php | 3 ++- .../Exception/ServiceUnavailableHttpExceptionTest.php | 5 +++-- Tests/Exception/TooManyRequestsHttpExceptionTest.php | 5 +++-- Tests/Exception/UnauthorizedHttpExceptionTest.php | 5 +++-- .../Exception/UnprocessableEntityHttpExceptionTest.php | 3 ++- .../UnsupportedMediaTypeHttpExceptionTest.php | 3 ++- 32 files changed, 102 insertions(+), 87 deletions(-) diff --git a/Exception/AccessDeniedHttpException.php b/Exception/AccessDeniedHttpException.php index 65e5f8c786..f0c81111db 100644 --- a/Exception/AccessDeniedHttpException.php +++ b/Exception/AccessDeniedHttpException.php @@ -18,11 +18,11 @@ class AccessDeniedHttpException extends HttpException { /** - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int $code The internal exception code */ - public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = []) + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct(403, $message, $previous, $headers, $code); } diff --git a/Exception/BadRequestHttpException.php b/Exception/BadRequestHttpException.php index 7de91054b4..8eccce1e16 100644 --- a/Exception/BadRequestHttpException.php +++ b/Exception/BadRequestHttpException.php @@ -17,11 +17,11 @@ class BadRequestHttpException extends HttpException { /** - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int $code The internal exception code */ - public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = []) + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct(400, $message, $previous, $headers, $code); } diff --git a/Exception/ConflictHttpException.php b/Exception/ConflictHttpException.php index ebb86ba6e9..72b8aa1274 100644 --- a/Exception/ConflictHttpException.php +++ b/Exception/ConflictHttpException.php @@ -17,11 +17,11 @@ class ConflictHttpException extends HttpException { /** - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int $code The internal exception code */ - public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = []) + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct(409, $message, $previous, $headers, $code); } diff --git a/Exception/GoneHttpException.php b/Exception/GoneHttpException.php index aea283a961..6bba8159a2 100644 --- a/Exception/GoneHttpException.php +++ b/Exception/GoneHttpException.php @@ -17,11 +17,11 @@ class GoneHttpException extends HttpException { /** - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int $code The internal exception code */ - public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = []) + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct(410, $message, $previous, $headers, $code); } diff --git a/Exception/HttpException.php b/Exception/HttpException.php index d822cd5d49..f3c0c3362f 100644 --- a/Exception/HttpException.php +++ b/Exception/HttpException.php @@ -21,7 +21,7 @@ class HttpException extends \RuntimeException implements HttpExceptionInterface private $statusCode; private $headers; - public function __construct(int $statusCode, string $message = null, \Throwable $previous = null, array $headers = [], ?int $code = 0) + public function __construct(int $statusCode, ?string $message = '', \Throwable $previous = null, array $headers = [], ?int $code = 0) { $this->statusCode = $statusCode; $this->headers = $headers; diff --git a/Exception/LengthRequiredHttpException.php b/Exception/LengthRequiredHttpException.php index 44fb770b60..92f9c74daf 100644 --- a/Exception/LengthRequiredHttpException.php +++ b/Exception/LengthRequiredHttpException.php @@ -17,11 +17,11 @@ class LengthRequiredHttpException extends HttpException { /** - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int $code The internal exception code */ - public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = []) + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct(411, $message, $previous, $headers, $code); } diff --git a/Exception/MethodNotAllowedHttpException.php b/Exception/MethodNotAllowedHttpException.php index c15e46ffc3..665ae355b4 100644 --- a/Exception/MethodNotAllowedHttpException.php +++ b/Exception/MethodNotAllowedHttpException.php @@ -17,12 +17,12 @@ class MethodNotAllowedHttpException extends HttpException { /** - * @param array $allow An array of allowed methods - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string[] $allow An array of allowed methods + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int|null $code The internal exception code */ - public function __construct(array $allow, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + public function __construct(array $allow, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = []) { $headers['Allow'] = strtoupper(implode(', ', $allow)); diff --git a/Exception/NotAcceptableHttpException.php b/Exception/NotAcceptableHttpException.php index c5f5324b1a..a985e86b9b 100644 --- a/Exception/NotAcceptableHttpException.php +++ b/Exception/NotAcceptableHttpException.php @@ -17,11 +17,11 @@ class NotAcceptableHttpException extends HttpException { /** - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int $code The internal exception code */ - public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = []) + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct(406, $message, $previous, $headers, $code); } diff --git a/Exception/NotFoundHttpException.php b/Exception/NotFoundHttpException.php index 146b908a1e..3be305ee9e 100644 --- a/Exception/NotFoundHttpException.php +++ b/Exception/NotFoundHttpException.php @@ -17,11 +17,11 @@ class NotFoundHttpException extends HttpException { /** - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int $code The internal exception code */ - public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = []) + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct(404, $message, $previous, $headers, $code); } diff --git a/Exception/PreconditionFailedHttpException.php b/Exception/PreconditionFailedHttpException.php index e878b10ad3..bdedea143d 100644 --- a/Exception/PreconditionFailedHttpException.php +++ b/Exception/PreconditionFailedHttpException.php @@ -17,11 +17,11 @@ class PreconditionFailedHttpException extends HttpException { /** - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int $code The internal exception code */ - public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = []) + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct(412, $message, $previous, $headers, $code); } diff --git a/Exception/PreconditionRequiredHttpException.php b/Exception/PreconditionRequiredHttpException.php index a6cb2f09a7..bc26804830 100644 --- a/Exception/PreconditionRequiredHttpException.php +++ b/Exception/PreconditionRequiredHttpException.php @@ -19,11 +19,11 @@ class PreconditionRequiredHttpException extends HttpException { /** - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int $code The internal exception code */ - public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = []) + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct(428, $message, $previous, $headers, $code); } diff --git a/Exception/ServiceUnavailableHttpException.php b/Exception/ServiceUnavailableHttpException.php index c786ccf5f7..1fb793dbf0 100644 --- a/Exception/ServiceUnavailableHttpException.php +++ b/Exception/ServiceUnavailableHttpException.php @@ -17,12 +17,12 @@ class ServiceUnavailableHttpException extends HttpException { /** - * @param int|string $retryAfter The number of seconds or HTTP-date after which the request may be retried - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param int|string|null $retryAfter The number of seconds or HTTP-date after which the request may be retried + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int|null $code The internal exception code */ - public function __construct($retryAfter = null, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + public function __construct($retryAfter = null, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = []) { if ($retryAfter) { $headers['Retry-After'] = $retryAfter; diff --git a/Exception/TooManyRequestsHttpException.php b/Exception/TooManyRequestsHttpException.php index b709f1a2f1..e1e47d048b 100644 --- a/Exception/TooManyRequestsHttpException.php +++ b/Exception/TooManyRequestsHttpException.php @@ -19,12 +19,12 @@ class TooManyRequestsHttpException extends HttpException { /** - * @param int|string $retryAfter The number of seconds or HTTP-date after which the request may be retried - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param int|string|null $retryAfter The number of seconds or HTTP-date after which the request may be retried + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int|null $code The internal exception code */ - public function __construct($retryAfter = null, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + public function __construct($retryAfter = null, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = []) { if ($retryAfter) { $headers['Retry-After'] = $retryAfter; diff --git a/Exception/UnauthorizedHttpException.php b/Exception/UnauthorizedHttpException.php index fb86c1ea95..ddb48f116f 100644 --- a/Exception/UnauthorizedHttpException.php +++ b/Exception/UnauthorizedHttpException.php @@ -17,12 +17,12 @@ class UnauthorizedHttpException extends HttpException { /** - * @param string $challenge WWW-Authenticate challenge string - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string $challenge WWW-Authenticate challenge string + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int|null $code The internal exception code */ - public function __construct(string $challenge, string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + public function __construct(string $challenge, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = []) { $headers['WWW-Authenticate'] = $challenge; diff --git a/Exception/UnprocessableEntityHttpException.php b/Exception/UnprocessableEntityHttpException.php index 93d4bcef69..237340a574 100644 --- a/Exception/UnprocessableEntityHttpException.php +++ b/Exception/UnprocessableEntityHttpException.php @@ -17,11 +17,11 @@ class UnprocessableEntityHttpException extends HttpException { /** - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int $code The internal exception code */ - public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = []) + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct(422, $message, $previous, $headers, $code); } diff --git a/Exception/UnsupportedMediaTypeHttpException.php b/Exception/UnsupportedMediaTypeHttpException.php index 7cda3a6202..74ddbfccbc 100644 --- a/Exception/UnsupportedMediaTypeHttpException.php +++ b/Exception/UnsupportedMediaTypeHttpException.php @@ -17,11 +17,11 @@ class UnsupportedMediaTypeHttpException extends HttpException { /** - * @param string $message The internal exception message - * @param \Throwable $previous The previous exception - * @param int $code The internal exception code + * @param string|null $message The internal exception message + * @param \Throwable|null $previous The previous exception + * @param int $code The internal exception code */ - public function __construct(string $message = null, \Throwable $previous = null, int $code = 0, array $headers = []) + public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { parent::__construct(415, $message, $previous, $headers, $code); } diff --git a/Tests/Exception/AccessDeniedHttpExceptionTest.php b/Tests/Exception/AccessDeniedHttpExceptionTest.php index 3a34cc47bc..6fa356e70d 100644 --- a/Tests/Exception/AccessDeniedHttpExceptionTest.php +++ b/Tests/Exception/AccessDeniedHttpExceptionTest.php @@ -3,10 +3,11 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; class AccessDeniedHttpExceptionTest extends HttpExceptionTest { - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new AccessDeniedHttpException($message, $previous, $code, $headers); } diff --git a/Tests/Exception/BadRequestHttpExceptionTest.php b/Tests/Exception/BadRequestHttpExceptionTest.php index 462fd9cb1d..231b406a9d 100644 --- a/Tests/Exception/BadRequestHttpExceptionTest.php +++ b/Tests/Exception/BadRequestHttpExceptionTest.php @@ -3,10 +3,11 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; class BadRequestHttpExceptionTest extends HttpExceptionTest { - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new BadRequestHttpException($message, $previous, $code, $headers); } diff --git a/Tests/Exception/ConflictHttpExceptionTest.php b/Tests/Exception/ConflictHttpExceptionTest.php index 760600a10f..c923df2ce9 100644 --- a/Tests/Exception/ConflictHttpExceptionTest.php +++ b/Tests/Exception/ConflictHttpExceptionTest.php @@ -3,10 +3,11 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; use Symfony\Component\HttpKernel\Exception\ConflictHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; class ConflictHttpExceptionTest extends HttpExceptionTest { - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new ConflictHttpException($message, $previous, $code, $headers); } diff --git a/Tests/Exception/GoneHttpExceptionTest.php b/Tests/Exception/GoneHttpExceptionTest.php index 30dafe4922..dd84acac36 100644 --- a/Tests/Exception/GoneHttpExceptionTest.php +++ b/Tests/Exception/GoneHttpExceptionTest.php @@ -3,10 +3,11 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; use Symfony\Component\HttpKernel\Exception\GoneHttpException; +use Symfony\Component\HttpKernel\Exception\HttpException; class GoneHttpExceptionTest extends HttpExceptionTest { - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new GoneHttpException($message, $previous, $code, $headers); } diff --git a/Tests/Exception/HttpExceptionTest.php b/Tests/Exception/HttpExceptionTest.php index a9431f4b5a..827f0fce3c 100644 --- a/Tests/Exception/HttpExceptionTest.php +++ b/Tests/Exception/HttpExceptionTest.php @@ -32,7 +32,7 @@ public function testHeadersDefault() */ public function testHeadersConstructor($headers) { - $exception = new HttpException(200, null, null, $headers); + $exception = new HttpException(200, '', null, $headers); $this->assertSame($headers, $exception->getHeaders()); } @@ -50,11 +50,11 @@ public function testThrowableIsAllowedForPrevious() { $previous = new class('Error of PHP 7+') extends \Error { }; - $exception = $this->createException(null, $previous); + $exception = $this->createException('', $previous); $this->assertSame($previous, $exception->getPrevious()); } - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new HttpException(200, $message, $previous, $headers, $code); } diff --git a/Tests/Exception/LengthRequiredHttpExceptionTest.php b/Tests/Exception/LengthRequiredHttpExceptionTest.php index 8676d67238..dd74c81aaf 100644 --- a/Tests/Exception/LengthRequiredHttpExceptionTest.php +++ b/Tests/Exception/LengthRequiredHttpExceptionTest.php @@ -2,11 +2,12 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\LengthRequiredHttpException; class LengthRequiredHttpExceptionTest extends HttpExceptionTest { - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new LengthRequiredHttpException($message, $previous, $code, $headers); } diff --git a/Tests/Exception/MethodNotAllowedHttpExceptionTest.php b/Tests/Exception/MethodNotAllowedHttpExceptionTest.php index efb0b50caf..8f657420ea 100644 --- a/Tests/Exception/MethodNotAllowedHttpExceptionTest.php +++ b/Tests/Exception/MethodNotAllowedHttpExceptionTest.php @@ -2,6 +2,7 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException; class MethodNotAllowedHttpExceptionTest extends HttpExceptionTest @@ -18,7 +19,7 @@ public function testWithHeaderConstruct() 'Cache-Control' => 'public, s-maxage=1200', ]; - $exception = new MethodNotAllowedHttpException(['get'], null, null, null, $headers); + $exception = new MethodNotAllowedHttpException(['get'], '', null, 0, $headers); $headers['Allow'] = 'GET'; @@ -35,7 +36,7 @@ public function testHeadersSetter($headers) $this->assertSame($headers, $exception->getHeaders()); } - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new MethodNotAllowedHttpException(['get'], $message, $previous, $code, $headers); } diff --git a/Tests/Exception/NotAcceptableHttpExceptionTest.php b/Tests/Exception/NotAcceptableHttpExceptionTest.php index 021c69e289..6d163faa47 100644 --- a/Tests/Exception/NotAcceptableHttpExceptionTest.php +++ b/Tests/Exception/NotAcceptableHttpExceptionTest.php @@ -2,11 +2,12 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; class NotAcceptableHttpExceptionTest extends HttpExceptionTest { - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new NotAcceptableHttpException($message, $previous, $code, $headers); } diff --git a/Tests/Exception/NotFoundHttpExceptionTest.php b/Tests/Exception/NotFoundHttpExceptionTest.php index 0bf369b1a0..cce9f697dd 100644 --- a/Tests/Exception/NotFoundHttpExceptionTest.php +++ b/Tests/Exception/NotFoundHttpExceptionTest.php @@ -2,11 +2,12 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; class NotFoundHttpExceptionTest extends HttpExceptionTest { - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new NotFoundHttpException($message, $previous, $code, $headers); } diff --git a/Tests/Exception/PreconditionFailedHttpExceptionTest.php b/Tests/Exception/PreconditionFailedHttpExceptionTest.php index 04d79c499d..b75c560d9b 100644 --- a/Tests/Exception/PreconditionFailedHttpExceptionTest.php +++ b/Tests/Exception/PreconditionFailedHttpExceptionTest.php @@ -2,11 +2,12 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\PreconditionFailedHttpException; class PreconditionFailedHttpExceptionTest extends HttpExceptionTest { - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new PreconditionFailedHttpException($message, $previous, $code, $headers); } diff --git a/Tests/Exception/PreconditionRequiredHttpExceptionTest.php b/Tests/Exception/PreconditionRequiredHttpExceptionTest.php index 82076617a8..2b9c6777ba 100644 --- a/Tests/Exception/PreconditionRequiredHttpExceptionTest.php +++ b/Tests/Exception/PreconditionRequiredHttpExceptionTest.php @@ -2,11 +2,12 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\PreconditionRequiredHttpException; class PreconditionRequiredHttpExceptionTest extends HttpExceptionTest { - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new PreconditionRequiredHttpException($message, $previous, $code, $headers); } diff --git a/Tests/Exception/ServiceUnavailableHttpExceptionTest.php b/Tests/Exception/ServiceUnavailableHttpExceptionTest.php index fac197c852..771e9492d0 100644 --- a/Tests/Exception/ServiceUnavailableHttpExceptionTest.php +++ b/Tests/Exception/ServiceUnavailableHttpExceptionTest.php @@ -2,6 +2,7 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; class ServiceUnavailableHttpExceptionTest extends HttpExceptionTest @@ -18,7 +19,7 @@ public function testWithHeaderConstruct() 'Cache-Control' => 'public, s-maxage=1337', ]; - $exception = new ServiceUnavailableHttpException(1337, null, null, null, $headers); + $exception = new ServiceUnavailableHttpException(1337, '', null, 0, $headers); $headers['Retry-After'] = 1337; @@ -35,7 +36,7 @@ public function testHeadersSetter($headers) $this->assertSame($headers, $exception->getHeaders()); } - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new ServiceUnavailableHttpException(null, $message, $previous, $code, $headers); } diff --git a/Tests/Exception/TooManyRequestsHttpExceptionTest.php b/Tests/Exception/TooManyRequestsHttpExceptionTest.php index 8b59e9894a..7c2490b22e 100644 --- a/Tests/Exception/TooManyRequestsHttpExceptionTest.php +++ b/Tests/Exception/TooManyRequestsHttpExceptionTest.php @@ -2,6 +2,7 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException; class TooManyRequestsHttpExceptionTest extends HttpExceptionTest @@ -18,7 +19,7 @@ public function testWithHeaderConstruct() 'Cache-Control' => 'public, s-maxage=69', ]; - $exception = new TooManyRequestsHttpException(69, null, null, null, $headers); + $exception = new TooManyRequestsHttpException(69, '', null, 0, $headers); $headers['Retry-After'] = 69; @@ -35,7 +36,7 @@ public function testHeadersSetter($headers) $this->assertSame($headers, $exception->getHeaders()); } - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new TooManyRequestsHttpException(null, $message, $previous, $code, $headers); } diff --git a/Tests/Exception/UnauthorizedHttpExceptionTest.php b/Tests/Exception/UnauthorizedHttpExceptionTest.php index 92d427b6e4..bd01079798 100644 --- a/Tests/Exception/UnauthorizedHttpExceptionTest.php +++ b/Tests/Exception/UnauthorizedHttpExceptionTest.php @@ -2,6 +2,7 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; class UnauthorizedHttpExceptionTest extends HttpExceptionTest @@ -18,7 +19,7 @@ public function testWithHeaderConstruct() 'Cache-Control' => 'public, s-maxage=1200', ]; - $exception = new UnauthorizedHttpException('Challenge', null, null, null, $headers); + $exception = new UnauthorizedHttpException('Challenge', '', null, 0, $headers); $headers['WWW-Authenticate'] = 'Challenge'; @@ -35,7 +36,7 @@ public function testHeadersSetter($headers) $this->assertSame($headers, $exception->getHeaders()); } - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new UnauthorizedHttpException('Challenge', $message, $previous, $code, $headers); } diff --git a/Tests/Exception/UnprocessableEntityHttpExceptionTest.php b/Tests/Exception/UnprocessableEntityHttpExceptionTest.php index ffa4e177ee..b538a041dd 100644 --- a/Tests/Exception/UnprocessableEntityHttpExceptionTest.php +++ b/Tests/Exception/UnprocessableEntityHttpExceptionTest.php @@ -2,11 +2,12 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; class UnprocessableEntityHttpExceptionTest extends HttpExceptionTest { - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new UnprocessableEntityHttpException($message, $previous, $code, $headers); } diff --git a/Tests/Exception/UnsupportedMediaTypeHttpExceptionTest.php b/Tests/Exception/UnsupportedMediaTypeHttpExceptionTest.php index fa28bbd19b..4eeb3fa144 100644 --- a/Tests/Exception/UnsupportedMediaTypeHttpExceptionTest.php +++ b/Tests/Exception/UnsupportedMediaTypeHttpExceptionTest.php @@ -2,11 +2,12 @@ namespace Symfony\Component\HttpKernel\Tests\Exception; +use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException; class UnsupportedMediaTypeHttpExceptionTest extends HttpExceptionTest { - protected function createException(string $message = null, \Throwable $previous = null, ?int $code = 0, array $headers = []) + protected function createException(string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []): HttpException { return new UnsupportedMediaTypeHttpException($message, $previous, $code, $headers); } From 6e5a390a2a3afd01191826276d7e8e07a033b148 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 24 Feb 2021 01:33:55 +0100 Subject: [PATCH 087/396] Deprecate passing null as $message or $code to exceptions --- Exception/AccessDeniedHttpException.php | 6 ++++++ Exception/BadRequestHttpException.php | 6 ++++++ Exception/ConflictHttpException.php | 6 ++++++ Exception/GoneHttpException.php | 6 ++++++ Exception/HttpException.php | 11 +++++++++++ Exception/LengthRequiredHttpException.php | 6 ++++++ Exception/MethodNotAllowedHttpException.php | 11 +++++++++++ Exception/NotAcceptableHttpException.php | 6 ++++++ Exception/NotFoundHttpException.php | 6 ++++++ Exception/PreconditionFailedHttpException.php | 6 ++++++ Exception/PreconditionRequiredHttpException.php | 6 ++++++ Exception/ServiceUnavailableHttpException.php | 11 +++++++++++ Exception/TooManyRequestsHttpException.php | 11 +++++++++++ Exception/UnauthorizedHttpException.php | 11 +++++++++++ Exception/UnprocessableEntityHttpException.php | 6 ++++++ Exception/UnsupportedMediaTypeHttpException.php | 6 ++++++ 16 files changed, 121 insertions(+) diff --git a/Exception/AccessDeniedHttpException.php b/Exception/AccessDeniedHttpException.php index f0c81111db..58680a3278 100644 --- a/Exception/AccessDeniedHttpException.php +++ b/Exception/AccessDeniedHttpException.php @@ -24,6 +24,12 @@ class AccessDeniedHttpException extends HttpException */ public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + parent::__construct(403, $message, $previous, $headers, $code); } } diff --git a/Exception/BadRequestHttpException.php b/Exception/BadRequestHttpException.php index 8eccce1e16..f530f7db49 100644 --- a/Exception/BadRequestHttpException.php +++ b/Exception/BadRequestHttpException.php @@ -23,6 +23,12 @@ class BadRequestHttpException extends HttpException */ public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + parent::__construct(400, $message, $previous, $headers, $code); } } diff --git a/Exception/ConflictHttpException.php b/Exception/ConflictHttpException.php index 72b8aa1274..79c36041c3 100644 --- a/Exception/ConflictHttpException.php +++ b/Exception/ConflictHttpException.php @@ -23,6 +23,12 @@ class ConflictHttpException extends HttpException */ public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + parent::__construct(409, $message, $previous, $headers, $code); } } diff --git a/Exception/GoneHttpException.php b/Exception/GoneHttpException.php index 6bba8159a2..9ea65057b3 100644 --- a/Exception/GoneHttpException.php +++ b/Exception/GoneHttpException.php @@ -23,6 +23,12 @@ class GoneHttpException extends HttpException */ public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + parent::__construct(410, $message, $previous, $headers, $code); } } diff --git a/Exception/HttpException.php b/Exception/HttpException.php index f3c0c3362f..249fe366d5 100644 --- a/Exception/HttpException.php +++ b/Exception/HttpException.php @@ -23,6 +23,17 @@ class HttpException extends \RuntimeException implements HttpExceptionInterface public function __construct(int $statusCode, ?string $message = '', \Throwable $previous = null, array $headers = [], ?int $code = 0) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + if (null === $code) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $code to "%s()" is deprecated, pass 0 instead.', __METHOD__); + + $code = 0; + } + $this->statusCode = $statusCode; $this->headers = $headers; diff --git a/Exception/LengthRequiredHttpException.php b/Exception/LengthRequiredHttpException.php index 92f9c74daf..fcac137852 100644 --- a/Exception/LengthRequiredHttpException.php +++ b/Exception/LengthRequiredHttpException.php @@ -23,6 +23,12 @@ class LengthRequiredHttpException extends HttpException */ public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + parent::__construct(411, $message, $previous, $headers, $code); } } diff --git a/Exception/MethodNotAllowedHttpException.php b/Exception/MethodNotAllowedHttpException.php index 665ae355b4..37576bcacb 100644 --- a/Exception/MethodNotAllowedHttpException.php +++ b/Exception/MethodNotAllowedHttpException.php @@ -24,6 +24,17 @@ class MethodNotAllowedHttpException extends HttpException */ public function __construct(array $allow, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + if (null === $code) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $code to "%s()" is deprecated, pass 0 instead.', __METHOD__); + + $code = 0; + } + $headers['Allow'] = strtoupper(implode(', ', $allow)); parent::__construct(405, $message, $previous, $headers, $code); diff --git a/Exception/NotAcceptableHttpException.php b/Exception/NotAcceptableHttpException.php index a985e86b9b..5a422406ba 100644 --- a/Exception/NotAcceptableHttpException.php +++ b/Exception/NotAcceptableHttpException.php @@ -23,6 +23,12 @@ class NotAcceptableHttpException extends HttpException */ public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + parent::__construct(406, $message, $previous, $headers, $code); } } diff --git a/Exception/NotFoundHttpException.php b/Exception/NotFoundHttpException.php index 3be305ee9e..a475113c5f 100644 --- a/Exception/NotFoundHttpException.php +++ b/Exception/NotFoundHttpException.php @@ -23,6 +23,12 @@ class NotFoundHttpException extends HttpException */ public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + parent::__construct(404, $message, $previous, $headers, $code); } } diff --git a/Exception/PreconditionFailedHttpException.php b/Exception/PreconditionFailedHttpException.php index bdedea143d..e23740a28d 100644 --- a/Exception/PreconditionFailedHttpException.php +++ b/Exception/PreconditionFailedHttpException.php @@ -23,6 +23,12 @@ class PreconditionFailedHttpException extends HttpException */ public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + parent::__construct(412, $message, $previous, $headers, $code); } } diff --git a/Exception/PreconditionRequiredHttpException.php b/Exception/PreconditionRequiredHttpException.php index bc26804830..5c31fae822 100644 --- a/Exception/PreconditionRequiredHttpException.php +++ b/Exception/PreconditionRequiredHttpException.php @@ -25,6 +25,12 @@ class PreconditionRequiredHttpException extends HttpException */ public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + parent::__construct(428, $message, $previous, $headers, $code); } } diff --git a/Exception/ServiceUnavailableHttpException.php b/Exception/ServiceUnavailableHttpException.php index 1fb793dbf0..d5681bbeb3 100644 --- a/Exception/ServiceUnavailableHttpException.php +++ b/Exception/ServiceUnavailableHttpException.php @@ -24,6 +24,17 @@ class ServiceUnavailableHttpException extends HttpException */ public function __construct($retryAfter = null, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + if (null === $code) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $code to "%s()" is deprecated, pass 0 instead.', __METHOD__); + + $code = 0; + } + if ($retryAfter) { $headers['Retry-After'] = $retryAfter; } diff --git a/Exception/TooManyRequestsHttpException.php b/Exception/TooManyRequestsHttpException.php index e1e47d048b..fd74402b5d 100644 --- a/Exception/TooManyRequestsHttpException.php +++ b/Exception/TooManyRequestsHttpException.php @@ -26,6 +26,17 @@ class TooManyRequestsHttpException extends HttpException */ public function __construct($retryAfter = null, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + if (null === $code) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $code to "%s()" is deprecated, pass 0 instead.', __METHOD__); + + $code = 0; + } + if ($retryAfter) { $headers['Retry-After'] = $retryAfter; } diff --git a/Exception/UnauthorizedHttpException.php b/Exception/UnauthorizedHttpException.php index ddb48f116f..aeb9713a3d 100644 --- a/Exception/UnauthorizedHttpException.php +++ b/Exception/UnauthorizedHttpException.php @@ -24,6 +24,17 @@ class UnauthorizedHttpException extends HttpException */ public function __construct(string $challenge, ?string $message = '', \Throwable $previous = null, ?int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + if (null === $code) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $code to "%s()" is deprecated, pass 0 instead.', __METHOD__); + + $code = 0; + } + $headers['WWW-Authenticate'] = $challenge; parent::__construct(401, $message, $previous, $headers, $code); diff --git a/Exception/UnprocessableEntityHttpException.php b/Exception/UnprocessableEntityHttpException.php index 237340a574..7b828b1d92 100644 --- a/Exception/UnprocessableEntityHttpException.php +++ b/Exception/UnprocessableEntityHttpException.php @@ -23,6 +23,12 @@ class UnprocessableEntityHttpException extends HttpException */ public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + parent::__construct(422, $message, $previous, $headers, $code); } } diff --git a/Exception/UnsupportedMediaTypeHttpException.php b/Exception/UnsupportedMediaTypeHttpException.php index 74ddbfccbc..7908423f42 100644 --- a/Exception/UnsupportedMediaTypeHttpException.php +++ b/Exception/UnsupportedMediaTypeHttpException.php @@ -23,6 +23,12 @@ class UnsupportedMediaTypeHttpException extends HttpException */ public function __construct(?string $message = '', \Throwable $previous = null, int $code = 0, array $headers = []) { + if (null === $message) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Passing null as $message to "%s()" is deprecated, pass an empty string instead.', __METHOD__); + + $message = ''; + } + parent::__construct(415, $message, $previous, $headers, $code); } } From 6dc93436a658ff608ec22cf3e7b3102b12df7403 Mon Sep 17 00:00:00 2001 From: tamcy Date: Fri, 19 Feb 2021 12:13:03 +0800 Subject: [PATCH 088/396] [HttpKernel] Configure `session.cookie_secure` earlier --- EventListener/SessionListener.php | 16 +++++++++++++--- Tests/EventListener/SessionListenerTest.php | 8 ++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/EventListener/SessionListener.php b/EventListener/SessionListener.php index a53ade797c..6cff47b88d 100644 --- a/EventListener/SessionListener.php +++ b/EventListener/SessionListener.php @@ -14,6 +14,7 @@ use Psr\Container\ContainerInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; +use Symfony\Component\HttpKernel\Event\GetResponseEvent; /** * Sets the session in the request. @@ -33,10 +34,12 @@ public function __construct(ContainerInterface $container) $this->container = $container; } - protected function getSession(): ?SessionInterface + public function onKernelRequest(GetResponseEvent $event) { - if (!$this->container->has('session')) { - return null; + parent::onKernelRequest($event); + + if (!$event->isMasterRequest() || !$this->container->has('session')) { + return; } if ($this->container->has('session_storage') @@ -46,6 +49,13 @@ protected function getSession(): ?SessionInterface ) { $storage->setOptions(['cookie_secure' => true]); } + } + + protected function getSession(): ?SessionInterface + { + if (!$this->container->has('session')) { + return null; + } return $this->container->get('session'); } diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index de1069606b..e0dba81683 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -59,7 +59,7 @@ public function testSessionIsSet() $listener = new SessionListener($container); $event = $this->createMock(RequestEvent::class); - $event->expects($this->once())->method('isMasterRequest')->willReturn(true); + $event->expects($this->exactly(2))->method('isMasterRequest')->willReturn(true); $event->expects($this->once())->method('getRequest')->willReturn($request); $listener->onKernelRequest($event); @@ -203,12 +203,16 @@ public function testGetSessionIsCalledOnce() $listener = new SessionListener($container); $listener->onKernelRequest($event); + // storage->setOptions() should have been called already + $container->set('session_storage', null); + $sessionStorage = null; + $subRequest = $masterRequest->duplicate(); // at this point both master and subrequest have a closure to build the session $masterRequest->getSession(); - // calling the factory on the subRequest should not trigger a second call to storage->sesOptions() + // calling the factory on the subRequest should not trigger a second call to storage->setOptions() $subRequest->getSession(); } } From 817b4f7baf05982f64f0ea8af68f9a34eff5c725 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 25 Feb 2021 18:36:22 +0100 Subject: [PATCH 089/396] fix merge --- EventListener/SessionListener.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EventListener/SessionListener.php b/EventListener/SessionListener.php index 93bbb2f117..2635788b1c 100644 --- a/EventListener/SessionListener.php +++ b/EventListener/SessionListener.php @@ -14,7 +14,7 @@ use Psr\Container\ContainerInterface; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; -use Symfony\Component\HttpKernel\Event\GetResponseEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * Sets the session in the request. @@ -34,7 +34,7 @@ public function __construct(ContainerInterface $container, bool $debug = false) parent::__construct($container, $debug); } - public function onKernelRequest(GetResponseEvent $event) + public function onKernelRequest(RequestEvent $event) { parent::onKernelRequest($event); From d162d4514e915a9e0c91d9ec7f4232bd25aaf119 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Thu, 25 Feb 2021 17:07:22 +0100 Subject: [PATCH 090/396] [HttpKernel] Handle multi-attribute controller arguments --- Attribute/ArgumentInterface.php | 4 ++ CHANGELOG.md | 3 ++ ControllerMetadata/ArgumentMetadata.php | 52 +++++++++++++++++-- .../ArgumentMetadataFactory.php | 24 ++------- .../ArgumentMetadataFactoryTest.php | 10 ++-- .../ArgumentMetadataTest.php | 28 ++++++++++ Tests/Fixtures/Attribute/Foo.php | 2 +- .../Controller/AttributeController.php | 2 +- 8 files changed, 93 insertions(+), 32 deletions(-) diff --git a/Attribute/ArgumentInterface.php b/Attribute/ArgumentInterface.php index 8f0c6fb8b0..78769f1ac0 100644 --- a/Attribute/ArgumentInterface.php +++ b/Attribute/ArgumentInterface.php @@ -11,8 +11,12 @@ namespace Symfony\Component\HttpKernel\Attribute; +trigger_deprecation('symfony/http-kernel', '5.3', 'The "%s" interface is deprecated.', ArgumentInterface::class); + /** * Marker interface for controller argument attributes. + * + * @deprecated since Symfony 5.3 */ interface ArgumentInterface { diff --git a/CHANGELOG.md b/CHANGELOG.md index e20b6c881d..e2509ba1bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ CHANGELOG 5.3 --- + * Deprecate `ArgumentInterface` + * Add `ArgumentMetadata::getAttributes()` + * Deprecate `ArgumentMetadata::getAttribute()`, use `getAttributes()` instead * marked the class `Symfony\Component\HttpKernel\EventListener\DebugHandlersListener` as internal 5.2.0 diff --git a/ControllerMetadata/ArgumentMetadata.php b/ControllerMetadata/ArgumentMetadata.php index 3454ff6e49..1a9ebc0c3a 100644 --- a/ControllerMetadata/ArgumentMetadata.php +++ b/ControllerMetadata/ArgumentMetadata.php @@ -20,15 +20,20 @@ */ class ArgumentMetadata { + public const IS_INSTANCEOF = 2; + private $name; private $type; private $isVariadic; private $hasDefaultValue; private $defaultValue; private $isNullable; - private $attribute; + private $attributes; - public function __construct(string $name, ?string $type, bool $isVariadic, bool $hasDefaultValue, $defaultValue, bool $isNullable = false, ?ArgumentInterface $attribute = null) + /** + * @param object[] $attributes + */ + public function __construct(string $name, ?string $type, bool $isVariadic, bool $hasDefaultValue, $defaultValue, bool $isNullable = false, $attributes = []) { $this->name = $name; $this->type = $type; @@ -36,7 +41,13 @@ public function __construct(string $name, ?string $type, bool $isVariadic, bool $this->hasDefaultValue = $hasDefaultValue; $this->defaultValue = $defaultValue; $this->isNullable = $isNullable || null === $type || ($hasDefaultValue && null === $defaultValue); - $this->attribute = $attribute; + + if (null === $attributes || $attributes instanceof ArgumentInterface) { + trigger_deprecation('symfony/http-kernel', '5.3', 'The "%s" constructor expects an array of PHP attributes as last argument, %s given.', __CLASS__, get_debug_type($attributes)); + $attributes = $attributes ? [$attributes] : []; + } + + $this->attributes = $attributes; } /** @@ -114,6 +125,39 @@ public function getDefaultValue() */ public function getAttribute(): ?ArgumentInterface { - return $this->attribute; + trigger_deprecation('symfony/http-kernel', '5.3', 'Method "%s()" is deprecated, use "getAttributes()" instead.', __METHOD__); + + if (!$this->attributes) { + return null; + } + + return $this->attributes[0] instanceof ArgumentInterface ? $this->attributes[0] : null; + } + + /** + * @return object[] + */ + public function getAttributes(string $name = null, int $flags = 0): array + { + if (!$name) { + return $this->attributes; + } + + $attributes = []; + if ($flags & self::IS_INSTANCEOF) { + foreach ($this->attributes as $attribute) { + if ($attribute instanceof $name) { + $attributes[] = $attribute; + } + } + } else { + foreach ($this->attributes as $attribute) { + if (\get_class($attribute) === $name) { + $attributes[] = $attribute; + } + } + } + + return $attributes; } } diff --git a/ControllerMetadata/ArgumentMetadataFactory.php b/ControllerMetadata/ArgumentMetadataFactory.php index f53bf065b9..a2feb05c10 100644 --- a/ControllerMetadata/ArgumentMetadataFactory.php +++ b/ControllerMetadata/ArgumentMetadataFactory.php @@ -11,9 +11,6 @@ namespace Symfony\Component\HttpKernel\ControllerMetadata; -use Symfony\Component\HttpKernel\Attribute\ArgumentInterface; -use Symfony\Component\HttpKernel\Exception\InvalidMetadataException; - /** * Builds {@see ArgumentMetadata} objects based on the given Controller. * @@ -37,28 +34,15 @@ public function createArgumentMetadata($controller): array } foreach ($reflection->getParameters() as $param) { - $attribute = null; if (\PHP_VERSION_ID >= 80000) { - $reflectionAttributes = $param->getAttributes(ArgumentInterface::class, \ReflectionAttribute::IS_INSTANCEOF); - - if (\count($reflectionAttributes) > 1) { - $representative = $controller; - - if (\is_array($representative)) { - $representative = sprintf('%s::%s()', \get_class($representative[0]), $representative[1]); - } elseif (\is_object($representative)) { - $representative = \get_class($representative); + foreach ($param->getAttributes() as $reflectionAttribute) { + if (class_exists($reflectionAttribute->getName())) { + $attributes[] = $reflectionAttribute->newInstance(); } - - throw new InvalidMetadataException(sprintf('Controller "%s" has more than one attribute for "$%s" argument.', $representative, $param->getName())); - } - - if (isset($reflectionAttributes[0])) { - $attribute = $reflectionAttributes[0]->newInstance(); } } - $arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull(), $attribute); + $arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull(), $attributes ?? []); } return $arguments; diff --git a/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php b/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php index 3c57c3161c..d952e424c5 100644 --- a/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php +++ b/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php @@ -15,7 +15,6 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadataFactory; -use Symfony\Component\HttpKernel\Exception\InvalidMetadataException; use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\Foo; use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\AttributeController; use Symfony\Component\HttpKernel\Tests\Fixtures\Controller\BasicTypesController; @@ -128,18 +127,17 @@ public function testAttributeSignature() $arguments = $this->factory->createArgumentMetadata([new AttributeController(), 'action']); $this->assertEquals([ - new ArgumentMetadata('baz', 'string', false, false, null, false, new Foo('bar')), + new ArgumentMetadata('baz', 'string', false, false, null, false, [new Foo('bar')]), ], $arguments); } /** * @requires PHP 8 */ - public function testAttributeSignatureError() + public function testMultipleAttributes() { - $this->expectException(InvalidMetadataException::class); - - $this->factory->createArgumentMetadata([new AttributeController(), 'invalidAction']); + $this->factory->createArgumentMetadata([new AttributeController(), 'multiAttributeArg']); + $this->assertCount(1, $this->factory->createArgumentMetadata([new AttributeController(), 'multiAttributeArg'])[0]->getAttributes()); } private function signature1(self $foo, array $bar, callable $baz) diff --git a/Tests/ControllerMetadata/ArgumentMetadataTest.php b/Tests/ControllerMetadata/ArgumentMetadataTest.php index fef6cd0002..45b15e1744 100644 --- a/Tests/ControllerMetadata/ArgumentMetadataTest.php +++ b/Tests/ControllerMetadata/ArgumentMetadataTest.php @@ -12,10 +12,15 @@ namespace Symfony\Component\HttpKernel\Tests\ControllerMetadata; use PHPUnit\Framework\TestCase; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; +use Symfony\Component\HttpKernel\Attribute\ArgumentInterface; use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata; +use Symfony\Component\HttpKernel\Tests\Fixtures\Attribute\Foo; class ArgumentMetadataTest extends TestCase { + use ExpectDeprecationTrait; + public function testWithBcLayerWithDefault() { $argument = new ArgumentMetadata('foo', 'string', false, true, 'default value'); @@ -41,4 +46,27 @@ public function testDefaultValueUnavailable() $this->assertFalse($argument->hasDefaultValue()); $argument->getDefaultValue(); } + + /** + * @group legacy + */ + public function testLegacyAttribute() + { + $attribute = $this->createMock(ArgumentInterface::class); + + $this->expectDeprecation('Since symfony/http-kernel 5.3: The "Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata" constructor expects an array of PHP attributes as last argument, %s given.'); + $this->expectDeprecation('Since symfony/http-kernel 5.3: Method "Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata::getAttribute()" is deprecated, use "getAttributes()" instead.'); + + $argument = new ArgumentMetadata('foo', 'string', false, true, 'default value', true, $attribute); + $this->assertSame($attribute, $argument->getAttribute()); + } + + /** + * @requires PHP 8 + */ + public function testGetAttributes() + { + $argument = new ArgumentMetadata('foo', 'string', false, true, 'default value', true, [new Foo('bar')]); + $this->assertEquals([new Foo('bar')], $argument->getAttributes()); + } } diff --git a/Tests/Fixtures/Attribute/Foo.php b/Tests/Fixtures/Attribute/Foo.php index 96a03adaad..e01a5a6e8d 100644 --- a/Tests/Fixtures/Attribute/Foo.php +++ b/Tests/Fixtures/Attribute/Foo.php @@ -14,7 +14,7 @@ use Symfony\Component\HttpKernel\Attribute\ArgumentInterface; #[\Attribute(\Attribute::TARGET_PARAMETER)] -class Foo implements ArgumentInterface +class Foo { private $foo; diff --git a/Tests/Fixtures/Controller/AttributeController.php b/Tests/Fixtures/Controller/AttributeController.php index 910f418ae1..d6e0cde58d 100644 --- a/Tests/Fixtures/Controller/AttributeController.php +++ b/Tests/Fixtures/Controller/AttributeController.php @@ -18,6 +18,6 @@ class AttributeController public function action(#[Foo('bar')] string $baz) { } - public function invalidAction(#[Foo('bar'), Foo('bar')] string $baz) { + public function multiAttributeArg(#[Foo('bar'), Undefined('bar')] string $baz) { } } From 4f36548465489f293b05406f1770492f6efb8adb Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 4 Mar 2021 19:00:27 +0100 Subject: [PATCH 091/396] Update VERSION for 4.4.20 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index b335a4f207..18ac83f6a8 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.20-DEV'; + public const VERSION = '4.4.20'; public const VERSION_ID = 40420; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; public const RELEASE_VERSION = 20; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From 03a971b1839bed9df4ede014553396b25289909d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 4 Mar 2021 19:04:32 +0100 Subject: [PATCH 092/396] Bump Symfony version to 4.4.21 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 18ac83f6a8..cd185b1441 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.20'; - public const VERSION_ID = 40420; + public const VERSION = '4.4.21-DEV'; + public const VERSION_ID = 40421; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; - public const RELEASE_VERSION = 20; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 21; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From c452dbe4f385f030c3957821bf921b13815d6140 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 4 Mar 2021 19:05:55 +0100 Subject: [PATCH 093/396] Update VERSION for 5.2.4 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 1ff31b5593..7c8b33d77c 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.4-DEV'; + public const VERSION = '5.2.4'; public const VERSION_ID = 50204; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; public const RELEASE_VERSION = 4; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From d1865b2227c5653d178277aaa47b2ee43099e565 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 4 Mar 2021 19:11:30 +0100 Subject: [PATCH 094/396] Bump Symfony version to 5.2.5 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 7c8b33d77c..6661ed26c1 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.4'; - public const VERSION_ID = 50204; + public const VERSION = '5.2.5-DEV'; + public const VERSION_ID = 50205; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; - public const RELEASE_VERSION = 4; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 5; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From d5ac10abce185d246702a2219be50d486df96c6e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 10 Mar 2021 09:16:48 +0100 Subject: [PATCH 095/396] [HttpKernel] Deprecate returning a `ContainerBuilder` from `KernelInterface::registerContainerConfiguration()` --- CHANGELOG.md | 3 ++- Kernel.php | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e2509ba1bb..83da910aab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ CHANGELOG * Deprecate `ArgumentInterface` * Add `ArgumentMetadata::getAttributes()` * Deprecate `ArgumentMetadata::getAttribute()`, use `getAttributes()` instead - * marked the class `Symfony\Component\HttpKernel\EventListener\DebugHandlersListener` as internal + * Mark the class `Symfony\Component\HttpKernel\EventListener\DebugHandlersListener` as internal + * Deprecate returning a `ContainerBuilder` from `KernelInterface::registerContainerConfiguration()` 5.2.0 ----- diff --git a/Kernel.php b/Kernel.php index ad6a7e1ec0..7fbf8b1891 100644 --- a/Kernel.php +++ b/Kernel.php @@ -642,6 +642,7 @@ protected function buildContainer() $this->prepareContainer($container); if (null !== $cont = $this->registerContainerConfiguration($this->getContainerLoader($container))) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Returning a ContainerBuilder from "%s::registerContainerConfiguration()" is deprecated.', get_debug_type($this)); $container->merge($cont); } From b8c63ef63c2364e174c3b3e0ba0bf83455f97f73 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 10 Mar 2021 18:07:35 +0100 Subject: [PATCH 096/396] Update VERSION for 5.2.5 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 6661ed26c1..24573ec5ab 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.5-DEV'; + public const VERSION = '5.2.5'; public const VERSION_ID = 50205; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; public const RELEASE_VERSION = 5; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 10fdbbc700ae1859a6e07cd264c727592c624986 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 10 Mar 2021 18:11:15 +0100 Subject: [PATCH 097/396] Bump Symfony version to 5.2.6 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 24573ec5ab..6f35643eb3 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.5'; - public const VERSION_ID = 50205; + public const VERSION = '5.2.6-DEV'; + public const VERSION_ID = 50206; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; - public const RELEASE_VERSION = 5; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 6; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 95ba3ddde73a07a28de523b4a475e6713ad42e5b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 15 Mar 2021 12:44:47 +0100 Subject: [PATCH 098/396] Deprecate configuring tag names and service ids in compiler passes --- DependencyInjection/ControllerArgumentValueResolverPass.php | 4 ++++ DependencyInjection/FragmentRendererPass.php | 4 ++++ .../RegisterControllerArgumentLocatorsPass.php | 4 ++++ DependencyInjection/RegisterLocaleAwareServicesPass.php | 4 ++++ .../RemoveEmptyControllerArgumentLocatorsPass.php | 4 ++++ DependencyInjection/ResettableServicePass.php | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/DependencyInjection/ControllerArgumentValueResolverPass.php b/DependencyInjection/ControllerArgumentValueResolverPass.php index 705c88dbfa..d925ed6b0e 100644 --- a/DependencyInjection/ControllerArgumentValueResolverPass.php +++ b/DependencyInjection/ControllerArgumentValueResolverPass.php @@ -34,6 +34,10 @@ class ControllerArgumentValueResolverPass implements CompilerPassInterface public function __construct(string $argumentResolverService = 'argument_resolver', string $argumentValueResolverTag = 'controller.argument_value_resolver', string $traceableResolverStopwatch = 'debug.stopwatch') { + if (0 < \func_num_args()) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); + } + $this->argumentResolverService = $argumentResolverService; $this->argumentValueResolverTag = $argumentValueResolverTag; $this->traceableResolverStopwatch = $traceableResolverStopwatch; diff --git a/DependencyInjection/FragmentRendererPass.php b/DependencyInjection/FragmentRendererPass.php index 432f767202..f26baeca9d 100644 --- a/DependencyInjection/FragmentRendererPass.php +++ b/DependencyInjection/FragmentRendererPass.php @@ -30,6 +30,10 @@ class FragmentRendererPass implements CompilerPassInterface public function __construct(string $handlerService = 'fragment.handler', string $rendererTag = 'kernel.fragment_renderer') { + if (0 < \func_num_args()) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); + } + $this->handlerService = $handlerService; $this->rendererTag = $rendererTag; } diff --git a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php index e24e0e6d64..eba2430b20 100644 --- a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php +++ b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php @@ -39,6 +39,10 @@ class RegisterControllerArgumentLocatorsPass implements CompilerPassInterface public function __construct(string $resolverServiceId = 'argument_resolver.service', string $controllerTag = 'controller.service_arguments', string $controllerLocator = 'argument_resolver.controller_locator', string $notTaggedControllerResolverServiceId = 'argument_resolver.not_tagged_controller') { + if (0 < \func_num_args()) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); + } + $this->resolverServiceId = $resolverServiceId; $this->controllerTag = $controllerTag; $this->controllerLocator = $controllerLocator; diff --git a/DependencyInjection/RegisterLocaleAwareServicesPass.php b/DependencyInjection/RegisterLocaleAwareServicesPass.php index 0efb164b72..f0b801b8d6 100644 --- a/DependencyInjection/RegisterLocaleAwareServicesPass.php +++ b/DependencyInjection/RegisterLocaleAwareServicesPass.php @@ -28,6 +28,10 @@ class RegisterLocaleAwareServicesPass implements CompilerPassInterface public function __construct(string $listenerServiceId = 'locale_aware_listener', string $localeAwareTag = 'kernel.locale_aware') { + if (0 < \func_num_args()) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); + } + $this->listenerServiceId = $listenerServiceId; $this->localeAwareTag = $localeAwareTag; } diff --git a/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php b/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php index 5f54e9c164..2d077a0cb5 100644 --- a/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php +++ b/DependencyInjection/RemoveEmptyControllerArgumentLocatorsPass.php @@ -25,6 +25,10 @@ class RemoveEmptyControllerArgumentLocatorsPass implements CompilerPassInterface public function __construct(string $controllerLocator = 'argument_resolver.controller_locator') { + if (0 < \func_num_args()) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); + } + $this->controllerLocator = $controllerLocator; } diff --git a/DependencyInjection/ResettableServicePass.php b/DependencyInjection/ResettableServicePass.php index b5e46106a7..0cd8e6d7c9 100644 --- a/DependencyInjection/ResettableServicePass.php +++ b/DependencyInjection/ResettableServicePass.php @@ -27,6 +27,10 @@ class ResettableServicePass implements CompilerPassInterface public function __construct(string $tagName = 'kernel.reset') { + if (0 < \func_num_args()) { + trigger_deprecation('symfony/http-kernel', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); + } + $this->tagName = $tagName; } From 835cfc20a6264f24582c285e452f43c6c448bec3 Mon Sep 17 00:00:00 2001 From: Bernd Stellwag Date: Fri, 19 Mar 2021 08:57:35 +0100 Subject: [PATCH 099/396] [HttpKernel] do is_file check before include Trying to include a file that doesn't exist issues a warning. Doing an is_file check beforehand should prevent those warnings. --- Kernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel.php b/Kernel.php index cd185b1441..b8c93dbd8c 100644 --- a/Kernel.php +++ b/Kernel.php @@ -533,7 +533,7 @@ protected function initializeContainer() if (!flock($lock, $wouldBlock ? \LOCK_SH : \LOCK_EX)) { fclose($lock); $lock = null; - } elseif (!\is_object($this->container = include $cachePath)) { + } elseif (!is_file($cachePath) || !\is_object($this->container = include $cachePath)) { $this->container = null; } elseif (!$oldContainer || \get_class($this->container) !== $oldContainer->name) { flock($lock, \LOCK_UN); From d026426847c59fb7ef6e3f5c165e5231c9c059d3 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 22 Mar 2021 00:25:00 +0100 Subject: [PATCH 100/396] Rename master request to main request --- CHANGELOG.md | 2 + DataCollector/DumpDataCollector.php | 2 +- DataCollector/EventDataCollector.php | 2 +- DataCollector/LoggerDataCollector.php | 2 +- DataCollector/RequestDataCollector.php | 4 +- Debug/FileLinkFormatter.php | 2 +- Event/KernelEvent.php | 18 ++- Event/TerminateEvent.php | 6 +- EventListener/AbstractSessionListener.php | 6 +- EventListener/AbstractTestSessionListener.php | 6 +- EventListener/DebugHandlersListener.php | 2 +- EventListener/FragmentListener.php | 2 +- EventListener/ProfilerListener.php | 15 +-- EventListener/ResponseListener.php | 2 +- EventListener/SessionListener.php | 8 +- EventListener/StreamedResponseListener.php | 2 +- EventListener/SurrogateListener.php | 2 +- EventListener/ValidateRequestListener.php | 2 +- Fragment/FragmentHandler.php | 2 +- HttpCache/HttpCache.php | 14 +- HttpCache/ResponseCacheStrategy.php | 2 +- HttpClientKernel.php | 2 +- HttpKernel.php | 8 +- HttpKernelBrowser.php | 2 +- HttpKernelInterface.php | 12 +- Kernel.php | 2 +- .../DataCollector/LoggerDataCollectorTest.php | 12 +- .../RequestDataCollectorTest.php | 4 +- .../DebugHandlersListenerTest.php | 2 +- .../DisallowRobotsIndexingListenerTest.php | 2 +- Tests/EventListener/ErrorListenerTest.php | 16 +-- Tests/EventListener/FragmentListenerTest.php | 2 +- .../EventListener/LocaleAwareListenerTest.php | 4 +- Tests/EventListener/LocaleListenerTest.php | 4 +- Tests/EventListener/ProfilerListenerTest.php | 12 +- Tests/EventListener/ResponseListenerTest.php | 6 +- Tests/EventListener/RouterListenerTest.php | 14 +- Tests/EventListener/SessionListenerTest.php | 52 ++++---- Tests/EventListener/SurrogateListenerTest.php | 4 +- .../EventListener/TestSessionListenerTest.php | 18 +-- .../ValidateRequestListenerTest.php | 4 +- Tests/HttpCache/HttpCacheTest.php | 8 +- Tests/HttpCache/HttpCacheTestCase.php | 2 +- Tests/HttpCache/ResponseCacheStrategyTest.php | 120 +++++++++--------- Tests/HttpCache/SubRequestHandlerTest.php | 10 +- Tests/HttpCache/TestHttpKernel.php | 2 +- Tests/HttpCache/TestMultipleHttpKernel.php | 2 +- Tests/HttpKernelTest.php | 14 +- Tests/KernelTest.php | 6 +- composer.json | 2 +- 50 files changed, 235 insertions(+), 216 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83da910aab..5b11f1cedd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ CHANGELOG * Deprecate `ArgumentMetadata::getAttribute()`, use `getAttributes()` instead * Mark the class `Symfony\Component\HttpKernel\EventListener\DebugHandlersListener` as internal * Deprecate returning a `ContainerBuilder` from `KernelInterface::registerContainerConfiguration()` + * Deprecate `HttpKernelInterface::MASTER_REQUEST` and add `HttpKernelInterface::MAIN_REQUEST` as replacement + * Deprecate `KernelEvent::isMasterRequest()` and add `isMainRequest()` as replacement 5.2.0 ----- diff --git a/DataCollector/DumpDataCollector.php b/DataCollector/DumpDataCollector.php index f8b5d8aa3a..2b008ae852 100644 --- a/DataCollector/DumpDataCollector.php +++ b/DataCollector/DumpDataCollector.php @@ -107,7 +107,7 @@ public function collect(Request $request, Response $response, \Throwable $except } // Sub-requests and programmatic calls stay in the collected profile. - if ($this->dumper || ($this->requestStack && $this->requestStack->getMasterRequest() !== $request) || $request->isXmlHttpRequest() || $request->headers->has('Origin')) { + if ($this->dumper || ($this->requestStack && $this->requestStack->getMainRequest() !== $request) || $request->isXmlHttpRequest() || $request->headers->has('Origin')) { return; } diff --git a/DataCollector/EventDataCollector.php b/DataCollector/EventDataCollector.php index 27930fea09..238970568f 100644 --- a/DataCollector/EventDataCollector.php +++ b/DataCollector/EventDataCollector.php @@ -42,7 +42,7 @@ public function __construct(EventDispatcherInterface $dispatcher = null, Request */ public function collect(Request $request, Response $response, \Throwable $exception = null) { - $this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null; + $this->currentRequest = $this->requestStack && $this->requestStack->getMainRequest() !== $request ? $request : null; $this->data = [ 'called_listeners' => [], 'not_called_listeners' => [], diff --git a/DataCollector/LoggerDataCollector.php b/DataCollector/LoggerDataCollector.php index 877b6b5d76..70d0e216a4 100644 --- a/DataCollector/LoggerDataCollector.php +++ b/DataCollector/LoggerDataCollector.php @@ -46,7 +46,7 @@ public function __construct($logger = null, string $containerPathPrefix = null, */ public function collect(Request $request, Response $response, \Throwable $exception = null) { - $this->currentRequest = $this->requestStack && $this->requestStack->getMasterRequest() !== $request ? $request : null; + $this->currentRequest = $this->requestStack && $this->requestStack->getMainRequest() !== $request ? $request : null; } /** diff --git a/DataCollector/RequestDataCollector.php b/DataCollector/RequestDataCollector.php index ad6fe2efe4..b010562d9d 100644 --- a/DataCollector/RequestDataCollector.php +++ b/DataCollector/RequestDataCollector.php @@ -106,7 +106,7 @@ public function collect(Request $request, Response $response, \Throwable $except 'session_metadata' => $sessionMetadata, 'session_attributes' => $sessionAttributes, 'session_usages' => array_values($this->sessionUsages), - 'stateless_check' => $this->requestStack && $this->requestStack->getMasterRequest()->attributes->get('_stateless', false), + 'stateless_check' => $this->requestStack && $this->requestStack->getMainRequest()->attributes->get('_stateless', false), 'flashes' => $flashes, 'path_info' => $request->getPathInfo(), 'controller' => 'n/a', @@ -374,7 +374,7 @@ public function onKernelController(ControllerEvent $event) public function onKernelResponse(ResponseEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } diff --git a/Debug/FileLinkFormatter.php b/Debug/FileLinkFormatter.php index 87672a9d19..55dcb52521 100644 --- a/Debug/FileLinkFormatter.php +++ b/Debug/FileLinkFormatter.php @@ -91,7 +91,7 @@ private function getFileLinkFormat() } if ($this->requestStack && $this->baseDir && $this->urlFormat) { - $request = $this->requestStack->getMasterRequest(); + $request = $this->requestStack->getMainRequest(); if ($request instanceof Request && (!$this->urlFormat instanceof \Closure || $this->urlFormat = ($this->urlFormat)())) { return [ diff --git a/Event/KernelEvent.php b/Event/KernelEvent.php index 08558d533a..d0793f3624 100644 --- a/Event/KernelEvent.php +++ b/Event/KernelEvent.php @@ -28,7 +28,7 @@ class KernelEvent extends Event /** * @param int $requestType The request type the kernel is currently processing; one of - * HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST + * HttpKernelInterface::MAIN_REQUEST or HttpKernelInterface::SUB_REQUEST */ public function __construct(HttpKernelInterface $kernel, Request $request, ?int $requestType) { @@ -60,7 +60,7 @@ public function getRequest() /** * Returns the request type the kernel is currently processing. * - * @return int One of HttpKernelInterface::MASTER_REQUEST and + * @return int One of HttpKernelInterface::MAIN_REQUEST and * HttpKernelInterface::SUB_REQUEST */ public function getRequestType() @@ -68,13 +68,25 @@ public function getRequestType() return $this->requestType; } + /** + * Checks if this is the main request. + */ + public function isMainRequest(): bool + { + return HttpKernelInterface::MAIN_REQUEST === $this->requestType; + } + /** * Checks if this is a master request. * * @return bool True if the request is a master request + * + * @deprecated since symfony/http-kernel 5.3, use isMainRequest() instead */ public function isMasterRequest() { - return HttpKernelInterface::MASTER_REQUEST === $this->requestType; + trigger_deprecation('symfony/http-kernel', '5.3', '"%s()" is deprecated, use "isMainRequest()" instead.'); + + return $this->isMainRequest(); } } diff --git a/Event/TerminateEvent.php b/Event/TerminateEvent.php index e0002fb56f..014ca535fe 100644 --- a/Event/TerminateEvent.php +++ b/Event/TerminateEvent.php @@ -18,8 +18,8 @@ /** * Allows to execute logic after a response was sent. * - * Since it's only triggered on master requests, the `getRequestType()` method - * will always return the value of `HttpKernelInterface::MASTER_REQUEST`. + * Since it's only triggered on main requests, the `getRequestType()` method + * will always return the value of `HttpKernelInterface::MAIN_REQUEST`. * * @author Jordi Boggiano */ @@ -29,7 +29,7 @@ final class TerminateEvent extends KernelEvent public function __construct(HttpKernelInterface $kernel, Request $request, Response $response) { - parent::__construct($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + parent::__construct($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $this->response = $response; } diff --git a/EventListener/AbstractSessionListener.php b/EventListener/AbstractSessionListener.php index 4244f46014..9b8891f79e 100644 --- a/EventListener/AbstractSessionListener.php +++ b/EventListener/AbstractSessionListener.php @@ -52,7 +52,7 @@ public function __construct(ContainerInterface $container = null, bool $debug = public function onKernelRequest(RequestEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } @@ -69,7 +69,7 @@ public function onKernelRequest(RequestEvent $event) public function onKernelResponse(ResponseEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } @@ -138,7 +138,7 @@ public function onKernelResponse(ResponseEvent $event) public function onFinishRequest(FinishRequestEvent $event) { - if ($event->isMasterRequest()) { + if ($event->isMainRequest()) { array_pop($this->sessionUsageStack); } } diff --git a/EventListener/AbstractTestSessionListener.php b/EventListener/AbstractTestSessionListener.php index 19d13b8c46..0c88187d1e 100644 --- a/EventListener/AbstractTestSessionListener.php +++ b/EventListener/AbstractTestSessionListener.php @@ -41,7 +41,7 @@ public function __construct(array $sessionOptions = []) public function onKernelRequest(RequestEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } @@ -59,12 +59,12 @@ public function onKernelRequest(RequestEvent $event) } /** - * Checks if session was initialized and saves if current request is master + * Checks if session was initialized and saves if current request is the main request * Runs on 'kernel.response' in test environment. */ public function onKernelResponse(ResponseEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } diff --git a/EventListener/DebugHandlersListener.php b/EventListener/DebugHandlersListener.php index df12569bfd..924cbb1fd1 100644 --- a/EventListener/DebugHandlersListener.php +++ b/EventListener/DebugHandlersListener.php @@ -76,7 +76,7 @@ public function configure(object $event = null) if ($event instanceof ConsoleEvent && !\in_array(\PHP_SAPI, ['cli', 'phpdbg'], true)) { return; } - if (!$event instanceof KernelEvent ? !$this->firstCall : !$event->isMasterRequest()) { + if (!$event instanceof KernelEvent ? !$this->firstCall : !$event->isMainRequest()) { return; } $this->firstCall = $this->hasTerminatedWithException = false; diff --git a/EventListener/FragmentListener.php b/EventListener/FragmentListener.php index 14c6aa63d1..c01d9ad491 100644 --- a/EventListener/FragmentListener.php +++ b/EventListener/FragmentListener.php @@ -65,7 +65,7 @@ public function onKernelRequest(RequestEvent $event) return; } - if ($event->isMasterRequest()) { + if ($event->isMainRequest()) { $this->validateRequest($request); } diff --git a/EventListener/ProfilerListener.php b/EventListener/ProfilerListener.php index 3143f2b9a6..a0e55563af 100644 --- a/EventListener/ProfilerListener.php +++ b/EventListener/ProfilerListener.php @@ -32,22 +32,22 @@ class ProfilerListener implements EventSubscriberInterface protected $profiler; protected $matcher; protected $onlyException; - protected $onlyMasterRequests; + protected $onlyMainRequests; protected $exception; protected $profiles; protected $requestStack; protected $parents; /** - * @param bool $onlyException True if the profiler only collects data when an exception occurs, false otherwise - * @param bool $onlyMasterRequests True if the profiler only collects data when the request is a master request, false otherwise + * @param bool $onlyException True if the profiler only collects data when an exception occurs, false otherwise + * @param bool $onlyMainRequests True if the profiler only collects data when the request is the main request, false otherwise */ - public function __construct(Profiler $profiler, RequestStack $requestStack, RequestMatcherInterface $matcher = null, bool $onlyException = false, bool $onlyMasterRequests = false) + public function __construct(Profiler $profiler, RequestStack $requestStack, RequestMatcherInterface $matcher = null, bool $onlyException = false, bool $onlyMainRequests = false) { $this->profiler = $profiler; $this->matcher = $matcher; $this->onlyException = $onlyException; - $this->onlyMasterRequests = $onlyMasterRequests; + $this->onlyMainRequests = $onlyMainRequests; $this->profiles = new \SplObjectStorage(); $this->parents = new \SplObjectStorage(); $this->requestStack = $requestStack; @@ -58,7 +58,7 @@ public function __construct(Profiler $profiler, RequestStack $requestStack, Requ */ public function onKernelException(ExceptionEvent $event) { - if ($this->onlyMasterRequests && !$event->isMasterRequest()) { + if ($this->onlyMainRequests && !$event->isMainRequest()) { return; } @@ -70,8 +70,7 @@ public function onKernelException(ExceptionEvent $event) */ public function onKernelResponse(ResponseEvent $event) { - $master = $event->isMasterRequest(); - if ($this->onlyMasterRequests && !$master) { + if ($this->onlyMainRequests && !$event->isMainRequest()) { return; } diff --git a/EventListener/ResponseListener.php b/EventListener/ResponseListener.php index d8292aec43..75ff2d00eb 100644 --- a/EventListener/ResponseListener.php +++ b/EventListener/ResponseListener.php @@ -36,7 +36,7 @@ public function __construct(string $charset) */ public function onKernelResponse(ResponseEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } diff --git a/EventListener/SessionListener.php b/EventListener/SessionListener.php index 2635788b1c..f2b950cef2 100644 --- a/EventListener/SessionListener.php +++ b/EventListener/SessionListener.php @@ -21,7 +21,7 @@ * * When the passed container contains a "session_storage" entry which * holds a NativeSessionStorage instance, the "cookie_secure" option - * will be set to true whenever the current master request is secure. + * will be set to true whenever the current main request is secure. * * @author Fabien Potencier * @@ -38,14 +38,14 @@ public function onKernelRequest(RequestEvent $event) { parent::onKernelRequest($event); - if (!$event->isMasterRequest() || !$this->container->has('session')) { + if (!$event->isMainRequest() || !$this->container->has('session')) { return; } if ($this->container->has('session_storage') && ($storage = $this->container->get('session_storage')) instanceof NativeSessionStorage - && ($masterRequest = $this->container->get('request_stack')->getMasterRequest()) - && $masterRequest->isSecure() + && ($mainRequest = $this->container->get('request_stack')->getMainRequest()) + && $mainRequest->isSecure() ) { $storage->setOptions(['cookie_secure' => true]); } diff --git a/EventListener/StreamedResponseListener.php b/EventListener/StreamedResponseListener.php index 730ee5453f..b3f7ca40fa 100644 --- a/EventListener/StreamedResponseListener.php +++ b/EventListener/StreamedResponseListener.php @@ -31,7 +31,7 @@ class StreamedResponseListener implements EventSubscriberInterface */ public function onKernelResponse(ResponseEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } diff --git a/EventListener/SurrogateListener.php b/EventListener/SurrogateListener.php index 2ef4af7aa3..9081bff652 100644 --- a/EventListener/SurrogateListener.php +++ b/EventListener/SurrogateListener.php @@ -38,7 +38,7 @@ public function __construct(SurrogateInterface $surrogate = null) */ public function onKernelResponse(ResponseEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } diff --git a/EventListener/ValidateRequestListener.php b/EventListener/ValidateRequestListener.php index 1f0c79822d..caa0f32aab 100644 --- a/EventListener/ValidateRequestListener.php +++ b/EventListener/ValidateRequestListener.php @@ -29,7 +29,7 @@ class ValidateRequestListener implements EventSubscriberInterface */ public function onKernelRequest(RequestEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } $request = $event->getRequest(); diff --git a/Fragment/FragmentHandler.php b/Fragment/FragmentHandler.php index a5544347dc..788fec3e94 100644 --- a/Fragment/FragmentHandler.php +++ b/Fragment/FragmentHandler.php @@ -66,7 +66,7 @@ public function addRenderer(FragmentRendererInterface $renderer) * @return string|null The Response content or null when the Response is streamed * * @throws \InvalidArgumentException when the renderer does not exist - * @throws \LogicException when no master request is being handled + * @throws \LogicException when no main request is being handled */ public function render($uri, string $renderer = 'inline', array $options = []) { diff --git a/HttpCache/HttpCache.php b/HttpCache/HttpCache.php index f8f5a9ad78..18d9565ad4 100644 --- a/HttpCache/HttpCache.php +++ b/HttpCache/HttpCache.php @@ -44,7 +44,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface * will try to carry on and deliver a meaningful response. * * * trace_level May be one of 'none', 'short' and 'full'. For 'short', a concise trace of the - * master request will be added as an HTTP header. 'full' will add traces for all + * main request will be added as an HTTP header. 'full' will add traces for all * requests (including ESI subrequests). (default: 'full' if in debug; 'none' otherwise) * * * trace_header Header name to use for traces. (default: X-Symfony-Cache) @@ -156,7 +156,7 @@ public function getLog() } /** - * Gets the Request instance associated with the master request. + * Gets the Request instance associated with the main request. * * @return Request A Request instance */ @@ -190,10 +190,10 @@ public function getSurrogate() /** * {@inheritdoc} */ - public function handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true) + public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true) { // FIXME: catch exceptions and implement a 500 error page here? -> in Varnish, there is a built-in error page mechanism - if (HttpKernelInterface::MASTER_REQUEST === $type) { + if (HttpKernelInterface::MAIN_REQUEST === $type) { $this->traces = []; // Keep a clone of the original request for surrogates so they can access it. // We must clone here to get a separate instance because the application will modify the request during @@ -224,12 +224,12 @@ public function handle(Request $request, int $type = HttpKernelInterface::MASTER $this->restoreResponseBody($request, $response); - if (HttpKernelInterface::MASTER_REQUEST === $type) { + if (HttpKernelInterface::MAIN_REQUEST === $type) { $this->addTraces($response); } if (null !== $this->surrogate) { - if (HttpKernelInterface::MASTER_REQUEST === $type) { + if (HttpKernelInterface::MAIN_REQUEST === $type) { $this->surrogateCacheStrategy->update($response); } else { $this->surrogateCacheStrategy->add($response); @@ -474,7 +474,7 @@ protected function forward(Request $request, bool $catch = false, Response $entr } // always a "master" request (as the real master request can be in cache) - $response = SubRequestHandler::handle($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $catch); + $response = SubRequestHandler::handle($this->kernel, $request, HttpKernelInterface::MAIN_REQUEST, $catch); /* * Support stale-if-error given on Responses or as a config option. diff --git a/HttpCache/ResponseCacheStrategy.php b/HttpCache/ResponseCacheStrategy.php index 1f09946846..c9983f6114 100644 --- a/HttpCache/ResponseCacheStrategy.php +++ b/HttpCache/ResponseCacheStrategy.php @@ -17,7 +17,7 @@ * ResponseCacheStrategy knows how to compute the Response cache HTTP header * based on the different response cache headers. * - * This implementation changes the master response TTL to the smallest TTL received + * This implementation changes the main response TTL to the smallest TTL received * or force validation if one of the surrogates has validation cache strategy. * * @author Fabien Potencier diff --git a/HttpClientKernel.php b/HttpClientKernel.php index 818082f439..58ca82e5a8 100644 --- a/HttpClientKernel.php +++ b/HttpClientKernel.php @@ -42,7 +42,7 @@ public function __construct(HttpClientInterface $client = null) $this->client = $client ?? HttpClient::create(); } - public function handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true): Response + public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true): Response { $headers = $this->getHeaders($request); $body = ''; diff --git a/HttpKernel.php b/HttpKernel.php index 850331349b..6875b484b5 100644 --- a/HttpKernel.php +++ b/HttpKernel.php @@ -71,7 +71,7 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso /** * {@inheritdoc} */ - public function handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true) + public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true) { $request->headers->set('X-Php-Ob-Level', (string) ob_get_level()); @@ -104,11 +104,11 @@ public function terminate(Request $request, Response $response) */ public function terminateWithException(\Throwable $exception, Request $request = null) { - if (!$request = $request ?: $this->requestStack->getMasterRequest()) { + if (!$request = $request ?: $this->requestStack->getMainRequest()) { throw $exception; } - $response = $this->handleThrowable($exception, $request, self::MASTER_REQUEST); + $response = $this->handleThrowable($exception, $request, self::MAIN_REQUEST); $response->sendHeaders(); $response->sendContent(); @@ -124,7 +124,7 @@ public function terminateWithException(\Throwable $exception, Request $request = * @throws \LogicException If one of the listener does not behave as expected * @throws NotFoundHttpException When controller cannot be found */ - private function handleRaw(Request $request, int $type = self::MASTER_REQUEST): Response + private function handleRaw(Request $request, int $type = self::MAIN_REQUEST): Response { $this->requestStack->push($request); diff --git a/HttpKernelBrowser.php b/HttpKernelBrowser.php index 554585fb9c..6a1b6caaa4 100644 --- a/HttpKernelBrowser.php +++ b/HttpKernelBrowser.php @@ -60,7 +60,7 @@ public function catchExceptions(bool $catchExceptions) */ protected function doRequest($request) { - $response = $this->kernel->handle($request, HttpKernelInterface::MASTER_REQUEST, $this->catchExceptions); + $response = $this->kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, $this->catchExceptions); if ($this->kernel instanceof TerminableInterface) { $this->kernel->terminate($request, $response); diff --git a/HttpKernelInterface.php b/HttpKernelInterface.php index c469a22b81..f9685faf1f 100644 --- a/HttpKernelInterface.php +++ b/HttpKernelInterface.php @@ -21,9 +21,15 @@ */ interface HttpKernelInterface { - public const MASTER_REQUEST = 1; + public const MAIN_REQUEST = 1; public const SUB_REQUEST = 2; + /** + * @deprecated since symfony/http-kernel 5.3, use MAIN_REQUEST instead. + * To ease the migration, this constant won't be removed until Symfony 7.0. + */ + public const MASTER_REQUEST = self::MAIN_REQUEST; + /** * Handles a Request to convert it to a Response. * @@ -31,12 +37,12 @@ interface HttpKernelInterface * and do its best to convert them to a Response instance. * * @param int $type The type of the request - * (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST) + * (one of HttpKernelInterface::MAIN_REQUEST or HttpKernelInterface::SUB_REQUEST) * @param bool $catch Whether to catch exceptions or not * * @return Response A Response instance * * @throws \Exception When an Exception occurs during processing */ - public function handle(Request $request, int $type = self::MASTER_REQUEST, bool $catch = true); + public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true); } diff --git a/Kernel.php b/Kernel.php index f0ce754f20..dbe5a111da 100644 --- a/Kernel.php +++ b/Kernel.php @@ -177,7 +177,7 @@ public function shutdown() /** * {@inheritdoc} */ - public function handle(Request $request, int $type = HttpKernelInterface::MASTER_REQUEST, bool $catch = true) + public function handle(Request $request, int $type = HttpKernelInterface::MAIN_REQUEST, bool $catch = true) { if (!$this->booted) { $container = $this->container ?? $this->preBoot(); diff --git a/Tests/DataCollector/LoggerDataCollectorTest.php b/Tests/DataCollector/LoggerDataCollectorTest.php index 4204b8ef03..864f6f1458 100644 --- a/Tests/DataCollector/LoggerDataCollectorTest.php +++ b/Tests/DataCollector/LoggerDataCollectorTest.php @@ -45,11 +45,11 @@ public function testCollectWithUnexpectedFormat() ], $compilerLogs['Unknown Compiler Pass']); } - public function testWithMasterRequest() + public function testWithMainRequest() { - $masterRequest = new Request(); + $mainRequest = new Request(); $stack = new RequestStack(); - $stack->push($masterRequest); + $stack->push($mainRequest); $logger = $this ->getMockBuilder(DebugLoggerInterface::class) @@ -60,16 +60,16 @@ public function testWithMasterRequest() $c = new LoggerDataCollector($logger, __DIR__.'/', $stack); - $c->collect($masterRequest, new Response()); + $c->collect($mainRequest, new Response()); $c->lateCollect(); } public function testWithSubRequest() { - $masterRequest = new Request(); + $mainRequest = new Request(); $subRequest = new Request(); $stack = new RequestStack(); - $stack->push($masterRequest); + $stack->push($mainRequest); $stack->push($subRequest); $logger = $this diff --git a/Tests/DataCollector/RequestDataCollectorTest.php b/Tests/DataCollector/RequestDataCollectorTest.php index bfc29eb109..2b8b38501e 100644 --- a/Tests/DataCollector/RequestDataCollectorTest.php +++ b/Tests/DataCollector/RequestDataCollectorTest.php @@ -210,7 +210,7 @@ public function testItAddsRedirectedAttributesWhenRequestContainsSpecificCookie( $kernel = $this->createMock(HttpKernelInterface::class); $c = new RequestDataCollector(); - $c->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $this->createResponse())); + $c->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $this->createResponse())); $this->assertTrue($request->attributes->get('_redirected')); } @@ -374,7 +374,7 @@ protected function injectController($collector, $controller, $request) { $resolver = $this->createMock(ControllerResolverInterface::class); $httpKernel = new HttpKernel(new EventDispatcher(), $resolver, null, $this->createMock(ArgumentResolverInterface::class)); - $event = new ControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new ControllerEvent($httpKernel, $controller, $request, HttpKernelInterface::MAIN_REQUEST); $collector->onKernelController($event); } diff --git a/Tests/EventListener/DebugHandlersListenerTest.php b/Tests/EventListener/DebugHandlersListenerTest.php index da07de1ca3..d15820eb54 100644 --- a/Tests/EventListener/DebugHandlersListenerTest.php +++ b/Tests/EventListener/DebugHandlersListenerTest.php @@ -70,7 +70,7 @@ public function testConfigureForHttpKernelWithNoTerminateWithException() $event = new KernelEvent( $this->createMock(HttpKernelInterface::class), Request::create('/'), - HttpKernelInterface::MASTER_REQUEST + HttpKernelInterface::MAIN_REQUEST ); $exception = null; diff --git a/Tests/EventListener/DisallowRobotsIndexingListenerTest.php b/Tests/EventListener/DisallowRobotsIndexingListenerTest.php index 6534ebf4e2..39bdfd6292 100644 --- a/Tests/EventListener/DisallowRobotsIndexingListenerTest.php +++ b/Tests/EventListener/DisallowRobotsIndexingListenerTest.php @@ -29,7 +29,7 @@ public function testInvoke(?string $expected, array $responseArgs) $response = new Response(...$responseArgs); $listener = new DisallowRobotsIndexingListener(); - $event = new ResponseEvent($this->createMock(HttpKernelInterface::class), $this->createMock(Request::class), KernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->createMock(HttpKernelInterface::class), $this->createMock(Request::class), KernelInterface::MAIN_REQUEST, $response); $listener->onResponse($event); diff --git a/Tests/EventListener/ErrorListenerTest.php b/Tests/EventListener/ErrorListenerTest.php index 78f33e0493..bd4b179935 100644 --- a/Tests/EventListener/ErrorListenerTest.php +++ b/Tests/EventListener/ErrorListenerTest.php @@ -105,8 +105,8 @@ public function provider() $request = new Request(); $exception = new \Exception('foo'); - $event = new ExceptionEvent(new TestKernel(), $request, HttpKernelInterface::MASTER_REQUEST, $exception); - $event2 = new ExceptionEvent(new TestKernelThatThrowsException(), $request, HttpKernelInterface::MASTER_REQUEST, $exception); + $event = new ExceptionEvent(new TestKernel(), $request, HttpKernelInterface::MAIN_REQUEST, $exception); + $event2 = new ExceptionEvent(new TestKernelThatThrowsException(), $request, HttpKernelInterface::MAIN_REQUEST, $exception); return [ [$event, $event2], @@ -125,7 +125,7 @@ public function testSubRequestFormat() $request = Request::create('/'); $request->setRequestFormat('xml'); - $event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo')); + $event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, new \Exception('foo')); $listener->onKernelException($event); $response = $event->getResponse(); @@ -145,13 +145,13 @@ public function testCSPHeaderIsRemoved() $dispatcher->addSubscriber($listener); $request = Request::create('/'); - $event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new \Exception('foo')); + $event = new ExceptionEvent($kernel, $request, HttpKernelInterface::MAIN_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 ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response); $dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertFalse($response->headers->has('content-security-policy'), 'CSP header has been removed'); @@ -174,7 +174,7 @@ public function testOnControllerArguments(callable $controller) return $controller(...$event->getArguments()); }); - $event = new ExceptionEvent($kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, new \Exception('foo')); + $event = new ExceptionEvent($kernel, Request::create('/'), HttpKernelInterface::MAIN_REQUEST, new \Exception('foo')); $listener->onKernelException($event); $this->assertSame('OK: foo', $event->getResponse()->getContent()); @@ -208,7 +208,7 @@ public function countErrors(Request $request = null): int class TestKernel implements HttpKernelInterface { - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true): Response + public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = true): Response { return new Response('foo'); } @@ -216,7 +216,7 @@ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = class TestKernelThatThrowsException implements HttpKernelInterface { - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true): Response + public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = true): Response { throw new \RuntimeException('bar'); } diff --git a/Tests/EventListener/FragmentListenerTest.php b/Tests/EventListener/FragmentListenerTest.php index 5720420dbf..77d07a39f3 100644 --- a/Tests/EventListener/FragmentListenerTest.php +++ b/Tests/EventListener/FragmentListenerTest.php @@ -112,7 +112,7 @@ public function testRemovesPathWithControllerNotDefined() $this->assertFalse($request->query->has('_path')); } - private function createRequestEvent(Request $request, $requestType = HttpKernelInterface::MASTER_REQUEST) + private function createRequestEvent(Request $request, int $requestType = HttpKernelInterface::MAIN_REQUEST): RequestEvent { return new RequestEvent($this->createMock(HttpKernelInterface::class), $request, $requestType); } diff --git a/Tests/EventListener/LocaleAwareListenerTest.php b/Tests/EventListener/LocaleAwareListenerTest.php index ab92a79168..3c89cafd04 100644 --- a/Tests/EventListener/LocaleAwareListenerTest.php +++ b/Tests/EventListener/LocaleAwareListenerTest.php @@ -40,7 +40,7 @@ public function testLocaleIsSetInOnKernelRequest() ->method('setLocale') ->with($this->equalTo('fr')); - $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MAIN_REQUEST); $this->listener->onKernelRequest($event); } @@ -57,7 +57,7 @@ public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest() $this->throwException(new \InvalidArgumentException()) ); - $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MAIN_REQUEST); $this->listener->onKernelRequest($event); } diff --git a/Tests/EventListener/LocaleListenerTest.php b/Tests/EventListener/LocaleListenerTest.php index 186ce43b1d..5e4f56f1fc 100644 --- a/Tests/EventListener/LocaleListenerTest.php +++ b/Tests/EventListener/LocaleListenerTest.php @@ -100,7 +100,7 @@ public function testRouterResetWithParentRequestOnKernelFinishRequest() $this->requestStack->expects($this->once())->method('getParentRequest')->willReturn($parentRequest); - $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MASTER_REQUEST); + $event = new FinishRequestEvent($this->createMock(HttpKernelInterface::class), new Request(), HttpKernelInterface::MAIN_REQUEST); $listener = new LocaleListener($this->requestStack, 'fr', $router); $listener->onKernelFinishRequest($event); @@ -119,6 +119,6 @@ public function testRequestLocaleIsNotOverridden() private function getEvent(Request $request): RequestEvent { - return new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST); + return new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST); } } diff --git a/Tests/EventListener/ProfilerListenerTest.php b/Tests/EventListener/ProfilerListenerTest.php index 8f7aca2a00..10733d47e3 100644 --- a/Tests/EventListener/ProfilerListenerTest.php +++ b/Tests/EventListener/ProfilerListenerTest.php @@ -28,7 +28,7 @@ class ProfilerListenerTest extends TestCase { /** - * Test a master and sub request with an exception and `onlyException` profiler option enabled. + * Test a main and sub request with an exception and `onlyException` profiler option enabled. */ public function testKernelTerminate() { @@ -40,23 +40,23 @@ public function testKernelTerminate() ->willReturn($profile); $kernel = $this->createMock(HttpKernelInterface::class); - $masterRequest = $this->createMock(Request::class); + $mainRequest = $this->createMock(Request::class); $subRequest = $this->createMock(Request::class); $response = $this->createMock(Response::class); $requestStack = new RequestStack(); - $requestStack->push($masterRequest); + $requestStack->push($mainRequest); $onlyException = true; $listener = new ProfilerListener($profiler, $requestStack, null, $onlyException); - // master request - $listener->onKernelResponse(new ResponseEvent($kernel, $masterRequest, Kernel::MASTER_REQUEST, $response)); + // main request + $listener->onKernelResponse(new ResponseEvent($kernel, $mainRequest, Kernel::MAIN_REQUEST, $response)); // sub request $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 TerminateEvent($kernel, $masterRequest, $response)); + $listener->onKernelTerminate(new TerminateEvent($kernel, $mainRequest, $response)); } } diff --git a/Tests/EventListener/ResponseListenerTest.php b/Tests/EventListener/ResponseListenerTest.php index 6c5af2a6dd..ee6ff64133 100644 --- a/Tests/EventListener/ResponseListenerTest.php +++ b/Tests/EventListener/ResponseListenerTest.php @@ -58,7 +58,7 @@ public function testFilterSetsNonDefaultCharsetIfNotOverridden() $response = new Response('foo'); - $event = new ResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MAIN_REQUEST, $response); $this->dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('ISO-8859-15', $response->getCharset()); @@ -72,7 +72,7 @@ public function testFilterDoesNothingIfCharsetIsOverridden() $response = new Response('foo'); $response->setCharset('ISO-8859-1'); - $event = new ResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->kernel, Request::create('/'), HttpKernelInterface::MAIN_REQUEST, $response); $this->dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('ISO-8859-1', $response->getCharset()); @@ -87,7 +87,7 @@ public function testFiltersSetsNonDefaultCharsetIfNotOverriddenOnNonTextContentT $request = Request::create('/'); $request->setRequestFormat('application/json'); - $event = new ResponseEvent($this->kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response); $this->dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('ISO-8859-15', $response->getCharset()); diff --git a/Tests/EventListener/RouterListenerTest.php b/Tests/EventListener/RouterListenerTest.php index 453bf5b0e3..7b2ed964af 100644 --- a/Tests/EventListener/RouterListenerTest.php +++ b/Tests/EventListener/RouterListenerTest.php @@ -83,7 +83,7 @@ private function createRequestEventForUri(string $uri): RequestEvent $request = Request::create($uri); $request->attributes->set('_controller', null); // Prevents going in to routing process - return new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + return new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); } public function testInvalidMatcher() @@ -96,7 +96,7 @@ public function testRequestMatcher() { $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://localhost/'); - $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher->expects($this->once()) @@ -112,7 +112,7 @@ public function testSubRequestWithDifferentMethod() { $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://localhost/', 'post'); - $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $requestMatcher = $this->createMock(RequestMatcherInterface::class); $requestMatcher->expects($this->any()) @@ -154,7 +154,7 @@ public function testLoggingParameter($parameter, $log, $parameters) $request = Request::create('http://localhost/'); $listener = new RouterListener($requestMatcher, $this->requestStack, new RequestContext(), $logger); - $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST)); } public function getLoggingParameterData() @@ -214,7 +214,7 @@ public function testRequestWithBadHost() $this->expectException(BadRequestHttpException::class); $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('http://bad host %22/'); - $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $requestMatcher = $this->createMock(RequestMatcherInterface::class); @@ -243,7 +243,7 @@ public function testResourceNotFoundException() $request = Request::create('https://www.symfony.com/path'); $request->headers->set('referer', 'https://www.google.com'); - $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $listener = new RouterListener($urlMatcher, $this->requestStack); $listener->onKernelRequest($event); @@ -269,7 +269,7 @@ public function testMethodNotAllowedException() $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('https://www.symfony.com/path'); - $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $listener = new RouterListener($urlMatcher, $this->requestStack); $listener->onKernelRequest($event); diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index ac6175d98f..336a77c8f6 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -32,11 +32,11 @@ class SessionListenerTest extends TestCase { - public function testOnlyTriggeredOnMasterRequest() + public function testOnlyTriggeredOnMainRequest() { $listener = $this->getMockForAbstractClass(AbstractSessionListener::class); $event = $this->createMock(RequestEvent::class); - $event->expects($this->once())->method('isMasterRequest')->willReturn(false); + $event->expects($this->once())->method('isMainRequest')->willReturn(false); $event->expects($this->never())->method('getRequest'); // sub request @@ -48,7 +48,7 @@ public function testSessionIsSet() $session = $this->createMock(Session::class); $requestStack = $this->createMock(RequestStack::class); - $requestStack->expects($this->once())->method('getMasterRequest')->willReturn(null); + $requestStack->expects($this->once())->method('getMainRequest')->willReturn(null); $sessionStorage = $this->createMock(NativeSessionStorage::class); $sessionStorage->expects($this->never())->method('setOptions')->with(['cookie_secure' => true]); @@ -62,7 +62,7 @@ public function testSessionIsSet() $listener = new SessionListener($container); $event = $this->createMock(RequestEvent::class); - $event->expects($this->exactly(2))->method('isMasterRequest')->willReturn(true); + $event->expects($this->exactly(2))->method('isMainRequest')->willReturn(true); $event->expects($this->once())->method('getRequest')->willReturn($request); $listener->onKernelRequest($event); @@ -83,10 +83,10 @@ public function testResponseIsPrivateIfSessionStarted() $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); - $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST)); $response = new Response(); - $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); + $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, $response)); $this->assertTrue($response->headers->has('Expires')); $this->assertTrue($response->headers->hasCacheControlDirective('private')); @@ -108,12 +108,12 @@ public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent() $kernel = $this->createMock(HttpKernelInterface::class); $request = new Request(); - $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST)); $response = new Response(); $response->setSharedMaxAge(60); $response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true'); - $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); + $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, $response)); $this->assertTrue($response->headers->hasCacheControlDirective('public')); $this->assertFalse($response->headers->has('Expires')); @@ -135,7 +135,7 @@ public function testUninitializedSession() ]); $listener = new SessionListener($container); - $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response)); + $listener->onKernelResponse(new ResponseEvent($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, $response)); $this->assertFalse($response->headers->has('Expires')); $this->assertTrue($response->headers->hasCacheControlDirective('public')); $this->assertFalse($response->headers->hasCacheControlDirective('private')); @@ -144,7 +144,7 @@ public function testUninitializedSession() $this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER)); } - public function testSurrogateMasterRequestIsPublic() + public function testSurrogateMainRequestIsPublic() { $session = $this->createMock(Session::class); $session->expects($this->exactly(4))->method('getUsageIndex')->will($this->onConsecutiveCalls(0, 1, 1, 1)); @@ -159,21 +159,21 @@ public function testSurrogateMasterRequestIsPublic() $request = new Request(); $response = new Response(); $response->setCache(['public' => true, 'max_age' => '30']); - $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST)); $this->assertTrue($request->hasSession()); $subRequest = clone $request; $this->assertSame($request->getSession(), $subRequest->getSession()); - $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)); + $listener->onKernelRequest(new RequestEvent($kernel, $subRequest, HttpKernelInterface::MAIN_REQUEST)); + $listener->onKernelResponse(new ResponseEvent($kernel, $subRequest, HttpKernelInterface::MAIN_REQUEST, $response)); + $listener->onFinishRequest(new FinishRequestEvent($kernel, $subRequest, HttpKernelInterface::MAIN_REQUEST)); $this->assertFalse($response->headers->has('Expires')); $this->assertFalse($response->headers->hasCacheControlDirective('private')); $this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate')); $this->assertSame('30', $response->headers->getCacheControlDirective('max-age')); - $listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response)); + $listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response)); $this->assertTrue($response->headers->hasCacheControlDirective('private')); $this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate')); @@ -194,14 +194,14 @@ public function testGetSessionIsCalledOnce() ->with(['cookie_secure' => true]); $requestStack = new RequestStack(); - $requestStack->push($masterRequest = new Request([], [], [], [], [], ['HTTPS' => 'on'])); + $requestStack->push($mainRequest = new Request([], [], [], [], [], ['HTTPS' => 'on'])); $container = new Container(); $container->set('session_storage', $sessionStorage); $container->set('session', $session); $container->set('request_stack', $requestStack); - $event = new RequestEvent($kernel, $masterRequest, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $mainRequest, HttpKernelInterface::MAIN_REQUEST); $listener = new SessionListener($container); $listener->onKernelRequest($event); @@ -210,10 +210,10 @@ public function testGetSessionIsCalledOnce() $container->set('session_storage', null); $sessionStorage = null; - $subRequest = $masterRequest->duplicate(); - // at this point both master and subrequest have a closure to build the session + $subRequest = $mainRequest->duplicate(); + // at this point both main and subrequest have a closure to build the session - $masterRequest->getSession(); + $mainRequest->getSession(); // calling the factory on the subRequest should not trigger a second call to storage->setOptions() $subRequest->getSession(); @@ -232,10 +232,10 @@ public function testSessionUsageExceptionIfStatelessAndSessionUsed() $request = new Request(); $request->attributes->set('_stateless', true); - $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST)); $this->expectException(UnexpectedSessionUsageException::class); - $listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response())); + $listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, new Response())); } public function testSessionUsageLogIfStatelessAndSessionUsed() @@ -255,9 +255,9 @@ public function testSessionUsageLogIfStatelessAndSessionUsed() $request = new Request(); $request->attributes->set('_stateless', true); - $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST)); - $listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, new Response())); + $listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, new Response())); } public function testSessionIsSavedWhenUnexpectedSessionExceptionThrown() @@ -276,11 +276,11 @@ public function testSessionIsSavedWhenUnexpectedSessionExceptionThrown() $request = new Request(); $request->attributes->set('_stateless', true); - $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST)); + $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST)); $response = new Response(); $this->expectException(UnexpectedSessionUsageException::class); - $listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response)); + $listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response)); } public function testSessionUsageCallbackWhenDebugAndStateless() diff --git a/Tests/EventListener/SurrogateListenerTest.php b/Tests/EventListener/SurrogateListenerTest.php index fc7e4d83ac..88a442a928 100644 --- a/Tests/EventListener/SurrogateListenerTest.php +++ b/Tests/EventListener/SurrogateListenerTest.php @@ -45,7 +45,7 @@ public function testFilterWhenThereIsSomeEsiIncludes() $listener = new SurrogateListener(new Esi()); $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); - $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, $response); $dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('content="ESI/1.0"', $event->getResponse()->headers->get('Surrogate-Control')); @@ -59,7 +59,7 @@ public function testFilterWhenThereIsNoEsiIncludes() $listener = new SurrogateListener(new Esi()); $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'onKernelResponse']); - $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, $response); $dispatcher->dispatch($event, KernelEvents::RESPONSE); $this->assertEquals('', $event->getResponse()->headers->get('Surrogate-Control')); diff --git a/Tests/EventListener/TestSessionListenerTest.php b/Tests/EventListener/TestSessionListenerTest.php index 2ec6581694..45a154a18b 100644 --- a/Tests/EventListener/TestSessionListenerTest.php +++ b/Tests/EventListener/TestSessionListenerTest.php @@ -51,7 +51,7 @@ protected function setUp(): void ->willReturn($this->session); } - public function testShouldSaveMasterRequestSession() + public function testShouldSaveMainRequestSession() { $this->sessionHasBeenStarted(); $this->sessionMustBeSaved(); @@ -72,7 +72,7 @@ public function testDoesNotDeleteCookieIfUsingSessionLifetime() @ini_set('session.cookie_lifetime', 0); - $response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST); + $response = $this->filterResponse(new Request(), HttpKernelInterface::MAIN_REQUEST); $cookies = $response->headers->getCookies(); $this->assertEquals(0, reset($cookies)->getExpiresTime()); @@ -86,7 +86,7 @@ public function testEmptySessionDoesNotSendCookie() $this->sessionHasBeenStarted(); $this->sessionIsEmpty(); - $response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST); + $response = $this->filterResponse(new Request(), HttpKernelInterface::MAIN_REQUEST); $this->assertSame([], $response->headers->getCookies()); } @@ -99,10 +99,10 @@ public function testEmptySessionWithNewSessionIdDoesSendCookie() $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']); - $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $this->listener->onKernelRequest($event); - $response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST); + $response = $this->filterResponse(new Request(), HttpKernelInterface::MAIN_REQUEST); $this->assertNotEmpty($response->headers->getCookies()); } @@ -118,12 +118,12 @@ public function testSessionWithNewSessionIdAndNewCookieDoesNotSendAnotherCookie( $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']); - $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $this->listener->onKernelRequest($event); $response = new Response('', 200, ['Set-Cookie' => $existing]); - $response = $this->filterResponse(new Request(), HttpKernelInterface::MASTER_REQUEST, $response); + $response = $this->filterResponse(new Request(), HttpKernelInterface::MAIN_REQUEST, $response); $this->assertSame($expected, $response->headers->all()['set-cookie']); } @@ -148,14 +148,14 @@ public function testUnstartedSessionIsNotSave() public function testDoesNotThrowIfRequestDoesNotHaveASession() { $kernel = $this->createMock(HttpKernelInterface::class); - $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MASTER_REQUEST, new Response()); + $event = new ResponseEvent($kernel, new Request(), HttpKernelInterface::MAIN_REQUEST, new Response()); $this->listener->onKernelResponse($event); $this->assertTrue(true); } - private function filterResponse(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, Response $response = null) + private function filterResponse(Request $request, $type = HttpKernelInterface::MAIN_REQUEST, Response $response = null) { $request->setSession($this->session); $response = $response ?: new Response(); diff --git a/Tests/EventListener/ValidateRequestListenerTest.php b/Tests/EventListener/ValidateRequestListenerTest.php index d23832d80a..5b02995dc3 100644 --- a/Tests/EventListener/ValidateRequestListenerTest.php +++ b/Tests/EventListener/ValidateRequestListenerTest.php @@ -27,7 +27,7 @@ protected function tearDown(): void Request::setTrustedProxies([], -1); } - public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps() + public function testListenerThrowsWhenMainRequestHasInconsistentClientIps() { $this->expectException(ConflictingHeadersException::class); $dispatcher = new EventDispatcher(); @@ -40,7 +40,7 @@ public function testListenerThrowsWhenMasterRequestHasInconsistentClientIps() $request->headers->set('X_FORWARDED_FOR', '3.3.3.3'); $dispatcher->addListener(KernelEvents::REQUEST, [new ValidateRequestListener(), 'onKernelRequest']); - $event = new RequestEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST); + $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $dispatcher->dispatch($event, KernelEvents::REQUEST); } diff --git a/Tests/HttpCache/HttpCacheTest.php b/Tests/HttpCache/HttpCacheTest.php index 1aead50bf4..3ac93a62d7 100644 --- a/Tests/HttpCache/HttpCacheTest.php +++ b/Tests/HttpCache/HttpCacheTest.php @@ -1209,7 +1209,7 @@ public function testEsiCacheSendsTheLowestTtlForHeadRequests() $responses = [ [ 'status' => 200, - 'body' => 'I am a long-lived master response, but I embed a short-lived resource: ', + 'body' => 'I am a long-lived main response, but I embed a short-lived resource: ', 'headers' => [ 'Cache-Control' => 's-maxage=300', 'Surrogate-Control' => 'content="ESI/1.0"', @@ -1267,7 +1267,7 @@ public function testEsiCacheForceValidationForHeadRequests() $responses = [ [ 'status' => 200, - 'body' => 'I am the master response and use expiration caching, but I embed another resource: ', + 'body' => 'I am the main response and use expiration caching, but I embed another resource: ', 'headers' => [ 'Cache-Control' => 's-maxage=300', 'Surrogate-Control' => 'content="ESI/1.0"', @@ -1511,7 +1511,7 @@ public function testUsesOriginalRequestForSurrogate() $request->server->set('REMOTE_ADDR', '10.0.0.1'); // Main request - $cache->handle($request, HttpKernelInterface::MASTER_REQUEST); + $cache->handle($request, HttpKernelInterface::MAIN_REQUEST); // Main request was now modified by HttpCache // The surrogate will ask for the request using $this->cache->getRequest() @@ -1734,7 +1734,7 @@ public function terminate(Request $request, Response $response) $this->terminateCalled = true; } - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true): Response + public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = true): Response { } } diff --git a/Tests/HttpCache/HttpCacheTestCase.php b/Tests/HttpCache/HttpCacheTestCase.php index a058a15f15..e47631d178 100644 --- a/Tests/HttpCache/HttpCacheTestCase.php +++ b/Tests/HttpCache/HttpCacheTestCase.php @@ -131,7 +131,7 @@ public function request($method, $uri = '/', $server = [], $cookies = [], $esi = $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); + $this->response = $this->cache->handle($this->request, HttpKernelInterface::MAIN_REQUEST, $this->catch); $this->responses[] = $this->response; } diff --git a/Tests/HttpCache/ResponseCacheStrategyTest.php b/Tests/HttpCache/ResponseCacheStrategyTest.php index 62179ba154..3927684eb6 100644 --- a/Tests/HttpCache/ResponseCacheStrategyTest.php +++ b/Tests/HttpCache/ResponseCacheStrategyTest.php @@ -58,7 +58,7 @@ public function testSharedMaxAgeNotSetIfNotSetInAnyEmbeddedRequest() $this->assertFalse($response->headers->hasCacheControlDirective('s-maxage')); } - public function testSharedMaxAgeNotSetIfNotSetInMasterRequest() + public function testSharedMaxAgeNotSetIfNotSetInMainRequest() { $cacheStrategy = new ResponseCacheStrategy(); @@ -76,7 +76,7 @@ public function testSharedMaxAgeNotSetIfNotSetInMasterRequest() $this->assertFalse($response->headers->hasCacheControlDirective('s-maxage')); } - public function testMasterResponseNotCacheableWhenEmbeddedResponseRequiresValidation() + public function testMainResponseNotCacheableWhenEmbeddedResponseRequiresValidation() { $cacheStrategy = new ResponseCacheStrategy(); @@ -84,66 +84,66 @@ public function testMasterResponseNotCacheableWhenEmbeddedResponseRequiresValida $embeddedResponse->setLastModified(new \DateTime()); $cacheStrategy->add($embeddedResponse); - $masterResponse = new Response(); - $masterResponse->setSharedMaxAge(3600); - $cacheStrategy->update($masterResponse); + $mainResponse = new Response(); + $mainResponse->setSharedMaxAge(3600); + $cacheStrategy->update($mainResponse); - $this->assertTrue($masterResponse->headers->hasCacheControlDirective('no-cache')); - $this->assertTrue($masterResponse->headers->hasCacheControlDirective('must-revalidate')); - $this->assertFalse($masterResponse->isFresh()); + $this->assertTrue($mainResponse->headers->hasCacheControlDirective('no-cache')); + $this->assertTrue($mainResponse->headers->hasCacheControlDirective('must-revalidate')); + $this->assertFalse($mainResponse->isFresh()); } - public function testValidationOnMasterResponseIsNotPossibleWhenItContainsEmbeddedResponses() + public function testValidationOnMainResponseIsNotPossibleWhenItContainsEmbeddedResponses() { $cacheStrategy = new ResponseCacheStrategy(); - // This master response uses the "validation" model - $masterResponse = new Response(); - $masterResponse->setLastModified(new \DateTime()); - $masterResponse->setEtag('foo'); + // This main response uses the "validation" model + $mainResponse = new Response(); + $mainResponse->setLastModified(new \DateTime()); + $mainResponse->setEtag('foo'); // Embedded response uses "expiry" model $embeddedResponse = new Response(); - $masterResponse->setSharedMaxAge(3600); + $mainResponse->setSharedMaxAge(3600); $cacheStrategy->add($embeddedResponse); - $cacheStrategy->update($masterResponse); + $cacheStrategy->update($mainResponse); - $this->assertFalse($masterResponse->isValidateable()); - $this->assertFalse($masterResponse->headers->has('Last-Modified')); - $this->assertFalse($masterResponse->headers->has('ETag')); - $this->assertTrue($masterResponse->headers->hasCacheControlDirective('no-cache')); - $this->assertTrue($masterResponse->headers->hasCacheControlDirective('must-revalidate')); + $this->assertFalse($mainResponse->isValidateable()); + $this->assertFalse($mainResponse->headers->has('Last-Modified')); + $this->assertFalse($mainResponse->headers->has('ETag')); + $this->assertTrue($mainResponse->headers->hasCacheControlDirective('no-cache')); + $this->assertTrue($mainResponse->headers->hasCacheControlDirective('must-revalidate')); } - public function testMasterResponseWithValidationIsUnchangedWhenThereIsNoEmbeddedResponse() + public function testMainResponseWithValidationIsUnchangedWhenThereIsNoEmbeddedResponse() { $cacheStrategy = new ResponseCacheStrategy(); - $masterResponse = new Response(); - $masterResponse->setLastModified(new \DateTime()); - $cacheStrategy->update($masterResponse); + $mainResponse = new Response(); + $mainResponse->setLastModified(new \DateTime()); + $cacheStrategy->update($mainResponse); - $this->assertTrue($masterResponse->isValidateable()); + $this->assertTrue($mainResponse->isValidateable()); } - public function testMasterResponseWithExpirationIsUnchangedWhenThereIsNoEmbeddedResponse() + public function testMainResponseWithExpirationIsUnchangedWhenThereIsNoEmbeddedResponse() { $cacheStrategy = new ResponseCacheStrategy(); - $masterResponse = new Response(); - $masterResponse->setSharedMaxAge(3600); - $cacheStrategy->update($masterResponse); + $mainResponse = new Response(); + $mainResponse->setSharedMaxAge(3600); + $cacheStrategy->update($mainResponse); - $this->assertTrue($masterResponse->isFresh()); + $this->assertTrue($mainResponse->isFresh()); } - public function testMasterResponseIsNotCacheableWhenEmbeddedResponseIsNotCacheable() + public function testMainResponseIsNotCacheableWhenEmbeddedResponseIsNotCacheable() { $cacheStrategy = new ResponseCacheStrategy(); - $masterResponse = new Response(); - $masterResponse->setSharedMaxAge(3600); // Public, cacheable + $mainResponse = new Response(); + $mainResponse->setSharedMaxAge(3600); // Public, cacheable /* This response has no validation or expiration information. That makes it uncacheable, it is always stale. @@ -152,19 +152,19 @@ public function testMasterResponseIsNotCacheableWhenEmbeddedResponseIsNotCacheab $this->assertFalse($embeddedResponse->isFresh()); // not fresh, as no lifetime is provided $cacheStrategy->add($embeddedResponse); - $cacheStrategy->update($masterResponse); + $cacheStrategy->update($mainResponse); - $this->assertTrue($masterResponse->headers->hasCacheControlDirective('no-cache')); - $this->assertTrue($masterResponse->headers->hasCacheControlDirective('must-revalidate')); - $this->assertFalse($masterResponse->isFresh()); + $this->assertTrue($mainResponse->headers->hasCacheControlDirective('no-cache')); + $this->assertTrue($mainResponse->headers->hasCacheControlDirective('must-revalidate')); + $this->assertFalse($mainResponse->isFresh()); } public function testEmbeddingPrivateResponseMakesMainResponsePrivate() { $cacheStrategy = new ResponseCacheStrategy(); - $masterResponse = new Response(); - $masterResponse->setSharedMaxAge(3600); // public, cacheable + $mainResponse = new Response(); + $mainResponse->setSharedMaxAge(3600); // public, cacheable // The embedded response might for example contain per-user data that remains valid for 60 seconds $embeddedResponse = new Response(); @@ -172,29 +172,29 @@ public function testEmbeddingPrivateResponseMakesMainResponsePrivate() $embeddedResponse->setMaxAge(60); // this would implicitly set "private" as well, but let's be explicit $cacheStrategy->add($embeddedResponse); - $cacheStrategy->update($masterResponse); + $cacheStrategy->update($mainResponse); - $this->assertTrue($masterResponse->headers->hasCacheControlDirective('private')); - $this->assertFalse($masterResponse->headers->hasCacheControlDirective('public')); + $this->assertTrue($mainResponse->headers->hasCacheControlDirective('private')); + $this->assertFalse($mainResponse->headers->hasCacheControlDirective('public')); } public function testEmbeddingPublicResponseDoesNotMakeMainResponsePublic() { $cacheStrategy = new ResponseCacheStrategy(); - $masterResponse = new Response(); - $masterResponse->setPrivate(); // this is the default, but let's be explicit - $masterResponse->setMaxAge(100); + $mainResponse = new Response(); + $mainResponse->setPrivate(); // this is the default, but let's be explicit + $mainResponse->setMaxAge(100); $embeddedResponse = new Response(); $embeddedResponse->setPublic(); $embeddedResponse->setSharedMaxAge(100); $cacheStrategy->add($embeddedResponse); - $cacheStrategy->update($masterResponse); + $cacheStrategy->update($mainResponse); - $this->assertTrue($masterResponse->headers->hasCacheControlDirective('private')); - $this->assertFalse($masterResponse->headers->hasCacheControlDirective('public')); + $this->assertTrue($mainResponse->headers->hasCacheControlDirective('private')); + $this->assertFalse($mainResponse->headers->hasCacheControlDirective('public')); } public function testResponseIsExiprableWhenEmbeddedResponseCombinesExpiryAndValidation() @@ -206,36 +206,36 @@ public function testResponseIsExiprableWhenEmbeddedResponseCombinesExpiryAndVali */ $cacheStrategy = new ResponseCacheStrategy(); - $masterResponse = new Response(); - $masterResponse->setSharedMaxAge(3600); + $mainResponse = new Response(); + $mainResponse->setSharedMaxAge(3600); $embeddedResponse = new Response(); $embeddedResponse->setSharedMaxAge(60); $embeddedResponse->setEtag('foo'); $cacheStrategy->add($embeddedResponse); - $cacheStrategy->update($masterResponse); + $cacheStrategy->update($mainResponse); - $this->assertEqualsWithDelta(60, (int) $masterResponse->headers->getCacheControlDirective('s-maxage'), 1); + $this->assertEqualsWithDelta(60, (int) $mainResponse->headers->getCacheControlDirective('s-maxage'), 1); } - public function testResponseIsExpirableButNotValidateableWhenMasterResponseCombinesExpirationAndValidation() + public function testResponseIsExpirableButNotValidateableWhenMainResponseCombinesExpirationAndValidation() { $cacheStrategy = new ResponseCacheStrategy(); - $masterResponse = new Response(); - $masterResponse->setSharedMaxAge(3600); - $masterResponse->setEtag('foo'); - $masterResponse->setLastModified(new \DateTime()); + $mainResponse = new Response(); + $mainResponse->setSharedMaxAge(3600); + $mainResponse->setEtag('foo'); + $mainResponse->setLastModified(new \DateTime()); $embeddedResponse = new Response(); $embeddedResponse->setSharedMaxAge(60); $cacheStrategy->add($embeddedResponse); - $cacheStrategy->update($masterResponse); + $cacheStrategy->update($mainResponse); - $this->assertSame('60', $masterResponse->headers->getCacheControlDirective('s-maxage')); - $this->assertFalse($masterResponse->isValidateable()); + $this->assertSame('60', $mainResponse->headers->getCacheControlDirective('s-maxage')); + $this->assertFalse($mainResponse->isValidateable()); } /** diff --git a/Tests/HttpCache/SubRequestHandlerTest.php b/Tests/HttpCache/SubRequestHandlerTest.php index ea2d2b7a12..7ab9b6c45f 100644 --- a/Tests/HttpCache/SubRequestHandlerTest.php +++ b/Tests/HttpCache/SubRequestHandlerTest.php @@ -51,7 +51,7 @@ public function testTrustedHeadersAreKept() $this->assertSame('https', $request->headers->get('X-Forwarded-Proto')); }); - SubRequestHandler::handle($kernel, $request, HttpKernelInterface::MASTER_REQUEST, true); + SubRequestHandler::handle($kernel, $request, HttpKernelInterface::MAIN_REQUEST, true); $this->assertSame($globalState, $this->getGlobalState()); } @@ -75,7 +75,7 @@ public function testUntrustedHeadersAreRemoved() $this->assertSame('for="10.0.0.1";host="localhost";proto=http', $request->headers->get('Forwarded')); }); - SubRequestHandler::handle($kernel, $request, HttpKernelInterface::MASTER_REQUEST, true); + SubRequestHandler::handle($kernel, $request, HttpKernelInterface::MAIN_REQUEST, true); $this->assertSame(self::$globalState, $this->getGlobalState()); } @@ -97,7 +97,7 @@ public function testTrustedForwardedHeader() $this->assertSame(1234, $request->getPort()); }); - SubRequestHandler::handle($kernel, $request, HttpKernelInterface::MASTER_REQUEST, true); + SubRequestHandler::handle($kernel, $request, HttpKernelInterface::MAIN_REQUEST, true); $this->assertSame($globalState, $this->getGlobalState()); } @@ -120,7 +120,7 @@ public function testTrustedXForwardedForHeader() $this->assertSame('https', $request->getScheme()); }); - SubRequestHandler::handle($kernel, $request, HttpKernelInterface::MASTER_REQUEST, true); + SubRequestHandler::handle($kernel, $request, HttpKernelInterface::MAIN_REQUEST, true); $this->assertSame($globalState, $this->getGlobalState()); } @@ -143,7 +143,7 @@ public function __construct(\Closure $assertCallback) $this->assertCallback = $assertCallback; } - public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true): Response + public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = true): Response { $assertCallback = $this->assertCallback; $assertCallback($request, $type, $catch); diff --git a/Tests/HttpCache/TestHttpKernel.php b/Tests/HttpCache/TestHttpKernel.php index 7f05fb8b89..471212f5e3 100644 --- a/Tests/HttpCache/TestHttpKernel.php +++ b/Tests/HttpCache/TestHttpKernel.php @@ -54,7 +54,7 @@ public function assert(\Closure $callback) } } - public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false): Response + public function handle(Request $request, $type = HttpKernelInterface::MAIN_REQUEST, $catch = false): Response { $this->catch = $catch; $this->backendRequest = [Request::getTrustedProxies(), Request::getTrustedHeaderSet(), $request]; diff --git a/Tests/HttpCache/TestMultipleHttpKernel.php b/Tests/HttpCache/TestMultipleHttpKernel.php index cef672e1f8..a8436d4b45 100644 --- a/Tests/HttpCache/TestMultipleHttpKernel.php +++ b/Tests/HttpCache/TestMultipleHttpKernel.php @@ -43,7 +43,7 @@ public function getBackendRequest() return $this->backendRequest; } - public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = false): Response + public function handle(Request $request, $type = HttpKernelInterface::MAIN_REQUEST, $catch = false): Response { $this->backendRequest = $request; diff --git a/Tests/HttpKernelTest.php b/Tests/HttpKernelTest.php index 8ae6a66149..91636ba86c 100644 --- a/Tests/HttpKernelTest.php +++ b/Tests/HttpKernelTest.php @@ -37,7 +37,7 @@ public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue() $this->expectException(\RuntimeException::class); $kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }); - $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true); + $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true); } public function testHandleWhenControllerThrowsAnExceptionAndCatchIsFalseAndNoListenerIsRegistered() @@ -45,7 +45,7 @@ public function testHandleWhenControllerThrowsAnExceptionAndCatchIsFalseAndNoLis $this->expectException(\RuntimeException::class); $kernel = $this->getHttpKernel(new EventDispatcher(), function () { throw new \RuntimeException(); }); - $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, false); + $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, false); } public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrueWithAHandlingListener() @@ -56,7 +56,7 @@ public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrueWithAHand }); $kernel = $this->getHttpKernel($dispatcher, function () { throw new \RuntimeException('foo'); }); - $response = $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true); + $response = $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true); $this->assertEquals('500', $response->getStatusCode()); $this->assertEquals('foo', $response->getContent()); @@ -74,7 +74,7 @@ public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrueWithANonH $kernel = $this->getHttpKernel($dispatcher, function () use ($exception) { throw $exception; }); try { - $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true); + $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true); $this->fail('LogicException expected'); } catch (\RuntimeException $e) { $this->assertSame($exception, $e); @@ -313,10 +313,10 @@ public function testVerifyRequestStackPushPopDuringHandle() $dispatcher = new EventDispatcher(); $kernel = $this->getHttpKernel($dispatcher, null, $stack); - $kernel->handle($request, HttpKernelInterface::MASTER_REQUEST); + $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST); } - public function testInconsistentClientIpsOnMasterRequests() + public function testInconsistentClientIpsOnMainRequests() { $this->expectException(BadRequestHttpException::class); $request = new Request(); @@ -331,7 +331,7 @@ public function testInconsistentClientIpsOnMasterRequests() }); $kernel = $this->getHttpKernel($dispatcher); - $kernel->handle($request, $kernel::MASTER_REQUEST, false); + $kernel->handle($request, $kernel::MAIN_REQUEST, false); Request::setTrustedProxies([], -1); } diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index 50a6a29b96..e4df69e867 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -190,7 +190,7 @@ public function testShutdownGivesNullContainerToAllBundles() public function testHandleCallsHandleOnHttpKernel() { - $type = HttpKernelInterface::MASTER_REQUEST; + $type = HttpKernelInterface::MAIN_REQUEST; $catch = true; $request = new Request(); @@ -212,7 +212,7 @@ public function testHandleCallsHandleOnHttpKernel() public function testHandleBootsTheKernel() { - $type = HttpKernelInterface::MASTER_REQUEST; + $type = HttpKernelInterface::MAIN_REQUEST; $catch = true; $request = new Request(); @@ -678,7 +678,7 @@ public function terminate() $this->terminateCalled = true; } - public function handle(Request $request, int $type = self::MASTER_REQUEST, bool $catch = true): Response + public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response { } diff --git a/composer.json b/composer.json index e58068299f..fb8757ade3 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "symfony/error-handler": "^4.4|^5.0", "symfony/event-dispatcher": "^5.0", "symfony/http-client-contracts": "^1.1|^2", - "symfony/http-foundation": "^4.4|^5.0", + "symfony/http-foundation": "^5.3", "symfony/polyfill-ctype": "^1.8", "symfony/polyfill-php73": "^1.9", "symfony/polyfill-php80": "^1.15", From 021c2199563042e1a510d070131b64b08504e0e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Mon, 22 Mar 2021 20:15:23 +0100 Subject: [PATCH 101/396] Hardening Security - Unserialize DumpDataCollector --- DataCollector/DumpDataCollector.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/DataCollector/DumpDataCollector.php b/DataCollector/DumpDataCollector.php index ae751c4f2e..a3cf2147cb 100644 --- a/DataCollector/DumpDataCollector.php +++ b/DataCollector/DumpDataCollector.php @@ -183,6 +183,11 @@ public function __wakeup() $charset = array_pop($this->data); $fileLinkFormat = array_pop($this->data); $this->dataCount = \count($this->data); + foreach ($this->data as $dump) { + if (!\is_string($dump['name']) || !\is_string($dump['file']) || !\is_int($dump['line'])) { + throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); + } + } self::__construct($this->stopwatch, \is_string($fileLinkFormat) || $fileLinkFormat instanceof FileLinkFormatter ? $fileLinkFormat : null, \is_string($charset) ? $charset : null); } @@ -257,7 +262,7 @@ public function __destruct() } } - private function doDump(DataDumperInterface $dumper, $data, string $name, string $file, int $line) + private function doDump(DataDumperInterface $dumper, Data $data, string $name, string $file, int $line) { if ($dumper instanceof CliDumper) { $contextDumper = function ($name, $file, $line, $fmt) { From 498c4f3b43b596108b3d9d47398457f1c1b009ef Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 23 Mar 2021 18:23:43 +0100 Subject: [PATCH 102/396] [HttpKernel] Add `#[AsController]` attribute for declaring listeners on PHP 8 --- Attribute/AsController.php | 23 +++++++++++++++++++++++ CHANGELOG.md | 1 + 2 files changed, 24 insertions(+) create mode 100644 Attribute/AsController.php diff --git a/Attribute/AsController.php b/Attribute/AsController.php new file mode 100644 index 0000000000..ef37104513 --- /dev/null +++ b/Attribute/AsController.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Attribute; + +/** + * Service tag to autoconfigure controllers. + */ +#[\Attribute(\Attribute::TARGET_CLASS)] +class AsController +{ + public function __construct() + { + } +} diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b11f1cedd..6d310de13e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ CHANGELOG * Deprecate returning a `ContainerBuilder` from `KernelInterface::registerContainerConfiguration()` * Deprecate `HttpKernelInterface::MASTER_REQUEST` and add `HttpKernelInterface::MAIN_REQUEST` as replacement * Deprecate `KernelEvent::isMasterRequest()` and add `isMainRequest()` as replacement + * Add `#[AsController]` attribute for declaring standalone controllers on PHP 8 5.2.0 ----- From 59ea1e00809b6496ac2419fa8424539d755e62c6 Mon Sep 17 00:00:00 2001 From: Roberto Nygaard Date: Sun, 21 Mar 2021 22:12:55 +0000 Subject: [PATCH 103/396] [HttpKernel] ConfigDataCollector to return known data without the need of a Kernel --- DataCollector/ConfigDataCollector.php | 17 +++++---- .../DataCollector/ConfigDataCollectorTest.php | 35 +++++++++++++++++++ 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/DataCollector/ConfigDataCollector.php b/DataCollector/ConfigDataCollector.php index d4b298c594..c32c71b747 100644 --- a/DataCollector/ConfigDataCollector.php +++ b/DataCollector/ConfigDataCollector.php @@ -59,12 +59,19 @@ public function setKernel(KernelInterface $kernel = null) */ public function collect(Request $request, Response $response/*, \Throwable $exception = null*/) { + $eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE); + $eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE); + $this->data = [ 'app_name' => $this->name, 'app_version' => $this->version, 'token' => $response->headers->get('X-Debug-Token'), 'symfony_version' => Kernel::VERSION, - 'symfony_state' => 'unknown', + 'symfony_minor_version' => sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION), + 'symfony_lts' => 4 === Kernel::MINOR_VERSION, + 'symfony_state' => $this->determineSymfonyState(), + 'symfony_eom' => $eom->format('F Y'), + 'symfony_eol' => $eol->format('F Y'), 'env' => isset($this->kernel) ? $this->kernel->getEnvironment() : 'n/a', 'debug' => isset($this->kernel) ? $this->kernel->isDebug() : 'n/a', 'php_version' => \PHP_VERSION, @@ -82,14 +89,6 @@ public function collect(Request $request, Response $response/*, \Throwable $exce foreach ($this->kernel->getBundles() as $name => $bundle) { $this->data['bundles'][$name] = new ClassStub(\get_class($bundle)); } - - $this->data['symfony_state'] = $this->determineSymfonyState(); - $this->data['symfony_minor_version'] = sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION); - $this->data['symfony_lts'] = 4 === Kernel::MINOR_VERSION; - $eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE); - $eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE); - $this->data['symfony_eom'] = $eom->format('F Y'); - $this->data['symfony_eol'] = $eol->format('F Y'); } if (preg_match('~^(\d+(?:\.\d+)*)(.+)?$~', $this->data['php_version'], $matches) && isset($matches[2])) { diff --git a/Tests/DataCollector/ConfigDataCollectorTest.php b/Tests/DataCollector/ConfigDataCollectorTest.php index df6af954f3..86bd394f56 100644 --- a/Tests/DataCollector/ConfigDataCollectorTest.php +++ b/Tests/DataCollector/ConfigDataCollectorTest.php @@ -41,6 +41,13 @@ public function testCollect() $this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug()); $this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache()); $this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN), $c->hasApcu()); + $this->assertSame(sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION), $c->getSymfonyMinorVersion()); + $this->assertContains($c->getSymfonyState(), ['eol', 'eom', 'dev', 'stable']); + + $eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->format('F Y'); + $eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->format('F Y'); + $this->assertSame($eom, $c->getSymfonyEom()); + $this->assertSame($eol, $c->getSymfonyEol()); } /** @@ -58,6 +65,34 @@ public function testLegacy() $this->assertSame('name', $c->getApplicationName()); $this->assertNull($c->getApplicationVersion()); } + + public function testCollectWithoutKernel() + { + $c = new ConfigDataCollector(); + $c->collect(new Request(), new Response()); + + $this->assertSame('n/a', $c->getEnv()); + $this->assertSame('n/a', $c->isDebug()); + $this->assertSame('config', $c->getName()); + $this->assertMatchesRegularExpression('~^'.preg_quote($c->getPhpVersion(), '~').'~', \PHP_VERSION); + $this->assertMatchesRegularExpression('~'.preg_quote((string) $c->getPhpVersionExtra(), '~').'$~', \PHP_VERSION); + $this->assertSame(\PHP_INT_SIZE * 8, $c->getPhpArchitecture()); + $this->assertSame(class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a', $c->getPhpIntlLocale()); + $this->assertSame(date_default_timezone_get(), $c->getPhpTimezone()); + $this->assertSame(Kernel::VERSION, $c->getSymfonyVersion()); + $this->assertSame(4 === Kernel::MINOR_VERSION, $c->isSymfonyLts()); + $this->assertNull($c->getToken()); + $this->assertSame(\extension_loaded('xdebug'), $c->hasXDebug()); + $this->assertSame(\extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN), $c->hasZendOpcache()); + $this->assertSame(\extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN), $c->hasApcu()); + $this->assertSame(sprintf('%s.%s', Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION), $c->getSymfonyMinorVersion()); + $this->assertContains($c->getSymfonyState(), ['eol', 'eom', 'dev', 'stable']); + + $eom = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_MAINTENANCE)->format('F Y'); + $eol = \DateTime::createFromFormat('d/m/Y', '01/'.Kernel::END_OF_LIFE)->format('F Y'); + $this->assertSame($eom, $c->getSymfonyEom()); + $this->assertSame($eol, $c->getSymfonyEol()); + } } class KernelForTest extends Kernel From 38d4a70964ab5815cc945586c724e0c30f408ef5 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 28 Mar 2021 15:54:53 +0200 Subject: [PATCH 104/396] fix docblock --- DataCollector/ConfigDataCollector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataCollector/ConfigDataCollector.php b/DataCollector/ConfigDataCollector.php index 37f8fb73cd..12c38153a2 100644 --- a/DataCollector/ConfigDataCollector.php +++ b/DataCollector/ConfigDataCollector.php @@ -219,7 +219,7 @@ public function getEnv() /** * Returns true if the debug is enabled. * - * @return bool true if debug is enabled, false otherwise + * @return bool|string true if debug is enabled, false otherwise or a string if no kernel was set */ public function isDebug() { From 0248214120d00c5f44f1cd5d9ad65f0b38459333 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 Mar 2021 07:11:04 +0200 Subject: [PATCH 105/396] Update VERSION for 4.4.21 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index b8c93dbd8c..f0ec789e82 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.21-DEV'; + public const VERSION = '4.4.21'; public const VERSION_ID = 40421; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; public const RELEASE_VERSION = 21; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From 39c6e76f7ec8955f98630ba8a3177bee198e0b0e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 Mar 2021 07:15:29 +0200 Subject: [PATCH 106/396] Bump Symfony version to 4.4.22 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index f0ec789e82..447c9936eb 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.21'; - public const VERSION_ID = 40421; + public const VERSION = '4.4.22-DEV'; + public const VERSION_ID = 40422; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; - public const RELEASE_VERSION = 21; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 22; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From f34de4c61ca46df73857f7f36b9a3805bdd7e3b2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 Mar 2021 07:16:58 +0200 Subject: [PATCH 107/396] Update VERSION for 5.2.6 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index f36f4bed4a..7549ae9b21 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.6-DEV'; + public const VERSION = '5.2.6'; public const VERSION_ID = 50206; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; public const RELEASE_VERSION = 6; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 460e914a046440fa50875dd22f5eea659f06db6a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 29 Mar 2021 07:20:15 +0200 Subject: [PATCH 108/396] Bump Symfony version to 5.2.7 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 7549ae9b21..774f1f3a4d 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.6'; - public const VERSION_ID = 50206; + public const VERSION = '5.2.7-DEV'; + public const VERSION_ID = 50207; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; - public const RELEASE_VERSION = 6; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 7; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 0425a7e6c09e26397c3a6dac82ade6451fb75ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Wed, 24 Mar 2021 19:24:50 +0100 Subject: [PATCH 109/396] [FrameworkBundle][HttpKernel][TwigBridge] Add an helper to generate fragments URL --- CHANGELOG.md | 1 + .../AbstractSurrogateFragmentRenderer.php | 9 +- Fragment/FragmentUriGenerator.php | 93 +++++++++++++++++++ Fragment/FragmentUriGeneratorInterface.php | 34 +++++++ Fragment/HIncludeFragmentRenderer.php | 7 +- Fragment/RoutableFragmentRenderer.php | 44 +-------- 6 files changed, 135 insertions(+), 53 deletions(-) create mode 100644 Fragment/FragmentUriGenerator.php create mode 100644 Fragment/FragmentUriGeneratorInterface.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d310de13e..1a5f67ba1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ CHANGELOG * Deprecate `HttpKernelInterface::MASTER_REQUEST` and add `HttpKernelInterface::MAIN_REQUEST` as replacement * Deprecate `KernelEvent::isMasterRequest()` and add `isMainRequest()` as replacement * Add `#[AsController]` attribute for declaring standalone controllers on PHP 8 + * Add `FragmentUriGeneratorInterface` and `FragmentUriGenerator` to generate the URI of a fragment 5.2.0 ----- diff --git a/Fragment/AbstractSurrogateFragmentRenderer.php b/Fragment/AbstractSurrogateFragmentRenderer.php index 06d8c380bd..d051ad8b5f 100644 --- a/Fragment/AbstractSurrogateFragmentRenderer.php +++ b/Fragment/AbstractSurrogateFragmentRenderer.php @@ -83,14 +83,7 @@ public function render($uri, Request $request, array $options = []) private function generateSignedFragmentUri(ControllerReference $uri, Request $request): string { - if (null === $this->signer) { - throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.'); - } - - // we need to sign the absolute URI, but want to return the path only. - $fragmentUri = $this->signer->sign($this->generateFragmentUri($uri, $request, true)); - - return substr($fragmentUri, \strlen($request->getSchemeAndHttpHost())); + return (new FragmentUriGenerator($this->fragmentPath, $this->signer))->generate($uri, $request); } private function containsNonScalars(array $values): bool diff --git a/Fragment/FragmentUriGenerator.php b/Fragment/FragmentUriGenerator.php new file mode 100644 index 0000000000..dabe3048ff --- /dev/null +++ b/Fragment/FragmentUriGenerator.php @@ -0,0 +1,93 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Fragment; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpKernel\Controller\ControllerReference; +use Symfony\Component\HttpKernel\UriSigner; + +/** + * Generates a fragment URI. + * + * @author Kévin Dunglas + * @author Fabien Potencier + */ +final class FragmentUriGenerator implements FragmentUriGeneratorInterface +{ + private $fragmentPath; + private $signer; + private $requestStack; + + public function __construct(string $fragmentPath, UriSigner $signer = null, RequestStack $requestStack = null) + { + $this->fragmentPath = $fragmentPath; + $this->signer = $signer; + $this->requestStack = $requestStack; + } + + /** + * {@inheritDoc} + */ + public function generate(ControllerReference $controller, Request $request = null, bool $absolute = false, bool $strict = true, bool $sign = true): string + { + if (null === $request && (null === $this->requestStack || null === $request = $this->requestStack->getCurrentRequest())) { + throw new \LogicException('Generating a fragment URL can only be done when handling a Request.'); + } + + if ($sign && null === $this->signer) { + throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.'); + } + + if ($strict) { + $this->checkNonScalar($controller->attributes); + } + + // We need to forward the current _format and _locale values as we don't have + // a proper routing pattern to do the job for us. + // This makes things inconsistent if you switch from rendering a controller + // to rendering a route if the route pattern does not contain the special + // _format and _locale placeholders. + if (!isset($controller->attributes['_format'])) { + $controller->attributes['_format'] = $request->getRequestFormat(); + } + if (!isset($controller->attributes['_locale'])) { + $controller->attributes['_locale'] = $request->getLocale(); + } + + $controller->attributes['_controller'] = $controller->controller; + $controller->query['_path'] = http_build_query($controller->attributes, '', '&'); + $path = $this->fragmentPath.'?'.http_build_query($controller->query, '', '&'); + + // we need to sign the absolute URI, but want to return the path only. + $fragmentUri = $sign || $absolute ? $request->getUriForPath($path) : $request->getBaseUrl().$path; + + if (!$sign) { + return $fragmentUri; + } + + $fragmentUri = $this->signer->sign($fragmentUri); + + return $absolute ? $fragmentUri : substr($fragmentUri, \strlen($request->getSchemeAndHttpHost())); + } + + private function checkNonScalar(array $values): void + { + foreach ($values as $key => $value) { + if (\is_array($value)) { + $this->checkNonScalar($value); + } elseif (!is_scalar($value) && null !== $value) { + throw new \LogicException(sprintf('Controller attributes cannot contain non-scalar/non-null values (value for key "%s" is not a scalar or null).', $key)); + } + } + } +} diff --git a/Fragment/FragmentUriGeneratorInterface.php b/Fragment/FragmentUriGeneratorInterface.php new file mode 100644 index 0000000000..d1492fa64a --- /dev/null +++ b/Fragment/FragmentUriGeneratorInterface.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpKernel\Fragment; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Controller\ControllerReference; + +/** + * Interface implemented by rendering strategies able to generate an URL for a fragment. + * + * @author Kévin Dunglas + */ +interface FragmentUriGeneratorInterface +{ + /** + * Generates a fragment URI for a given controller. + * + * @param bool $absolute Whether to generate an absolute URL or not + * @param bool $strict Whether to allow non-scalar attributes or not + * @param bool $sign Whether to sign the URL or not + * + * @return string A fragment URI + */ + public function generate(ControllerReference $controller, Request $request = null, bool $absolute = false, bool $strict = true, bool $sign = true): string; +} diff --git a/Fragment/HIncludeFragmentRenderer.php b/Fragment/HIncludeFragmentRenderer.php index a599a26e14..36106670b8 100644 --- a/Fragment/HIncludeFragmentRenderer.php +++ b/Fragment/HIncludeFragmentRenderer.php @@ -62,12 +62,7 @@ public function hasTemplating() public function render($uri, Request $request, array $options = []) { if ($uri instanceof ControllerReference) { - if (null === $this->signer) { - throw new \LogicException('You must use a proper URI when using the Hinclude rendering strategy or set a URL signer.'); - } - - // we need to sign the absolute URI, but want to return the path only. - $uri = substr($this->signer->sign($this->generateFragmentUri($uri, $request, true)), \strlen($request->getSchemeAndHttpHost())); + $uri = (new FragmentUriGenerator($this->fragmentPath, $this->signer))->generate($uri, $request); } // We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content. diff --git a/Fragment/RoutableFragmentRenderer.php b/Fragment/RoutableFragmentRenderer.php index c9a175758d..615b5fa504 100644 --- a/Fragment/RoutableFragmentRenderer.php +++ b/Fragment/RoutableFragmentRenderer.php @@ -22,7 +22,10 @@ */ abstract class RoutableFragmentRenderer implements FragmentRendererInterface { - private $fragmentPath = '/_fragment'; + /** + * @internal + */ + protected $fragmentPath = '/_fragment'; /** * Sets the fragment path that triggers the fragment listener. @@ -44,43 +47,6 @@ public function setFragmentPath(string $path) */ protected function generateFragmentUri(ControllerReference $reference, Request $request, bool $absolute = false, bool $strict = true) { - if ($strict) { - $this->checkNonScalar($reference->attributes); - } - - // We need to forward the current _format and _locale values as we don't have - // a proper routing pattern to do the job for us. - // This makes things inconsistent if you switch from rendering a controller - // to rendering a route if the route pattern does not contain the special - // _format and _locale placeholders. - if (!isset($reference->attributes['_format'])) { - $reference->attributes['_format'] = $request->getRequestFormat(); - } - if (!isset($reference->attributes['_locale'])) { - $reference->attributes['_locale'] = $request->getLocale(); - } - - $reference->attributes['_controller'] = $reference->controller; - - $reference->query['_path'] = http_build_query($reference->attributes, '', '&'); - - $path = $this->fragmentPath.'?'.http_build_query($reference->query, '', '&'); - - if ($absolute) { - return $request->getUriForPath($path); - } - - return $request->getBaseUrl().$path; - } - - private function checkNonScalar(array $values) - { - foreach ($values as $key => $value) { - if (\is_array($value)) { - $this->checkNonScalar($value); - } elseif (!is_scalar($value) && null !== $value) { - throw new \LogicException(sprintf('Controller attributes cannot contain non-scalar/non-null values (value for key "%s" is not a scalar or null).', $key)); - } - } + return (new FragmentUriGenerator($this->fragmentPath))->generate($reference, $request, $absolute, $strict, false); } } From f70a9aadd38a8f9bf8fbdd907335fefd7490b5d7 Mon Sep 17 00:00:00 2001 From: Roman Martinuk Date: Fri, 2 Apr 2021 16:17:10 +0300 Subject: [PATCH 110/396] remove references to "Silex" --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index abdaf513f9..0136784a72 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,7 @@ HttpKernel Component The HttpKernel component provides a structured process for converting a Request into a Response by making use of the EventDispatcher component. It's flexible -enough to create a full-stack framework (Symfony), a micro-framework (Silex) or -an advanced CMS system (Drupal). +enough to create full-stack frameworks, micro-frameworks or advanced CMS systems like Drupal. Resources --------- From 31f3944239321b24aec193109c3999493e86257b Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Wed, 7 Apr 2021 17:14:41 +0200 Subject: [PATCH 111/396] [CS] Replace easy occurences of ?: with ?? --- Controller/ArgumentResolver.php | 2 +- HttpKernel.php | 2 +- Tests/EventListener/TestSessionListenerTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Controller/ArgumentResolver.php b/Controller/ArgumentResolver.php index 3504ae614f..421d10f120 100644 --- a/Controller/ArgumentResolver.php +++ b/Controller/ArgumentResolver.php @@ -36,7 +36,7 @@ final class ArgumentResolver implements ArgumentResolverInterface public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, iterable $argumentValueResolvers = []) { - $this->argumentMetadataFactory = $argumentMetadataFactory ?: new ArgumentMetadataFactory(); + $this->argumentMetadataFactory = $argumentMetadataFactory ?? new ArgumentMetadataFactory(); $this->argumentValueResolvers = $argumentValueResolvers ?: self::getDefaultArgumentValueResolvers(); } diff --git a/HttpKernel.php b/HttpKernel.php index 681e96321d..0ed82d777b 100644 --- a/HttpKernel.php +++ b/HttpKernel.php @@ -61,7 +61,7 @@ public function __construct(EventDispatcherInterface $dispatcher, ControllerReso { $this->dispatcher = LegacyEventDispatcherProxy::decorate($dispatcher); $this->resolver = $resolver; - $this->requestStack = $requestStack ?: new RequestStack(); + $this->requestStack = $requestStack ?? new RequestStack(); $this->argumentResolver = $argumentResolver; if (null === $this->argumentResolver) { diff --git a/Tests/EventListener/TestSessionListenerTest.php b/Tests/EventListener/TestSessionListenerTest.php index 2ec6581694..70629a8fb8 100644 --- a/Tests/EventListener/TestSessionListenerTest.php +++ b/Tests/EventListener/TestSessionListenerTest.php @@ -158,7 +158,7 @@ public function testDoesNotThrowIfRequestDoesNotHaveASession() private function filterResponse(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, Response $response = null) { $request->setSession($this->session); - $response = $response ?: new Response(); + $response = $response ?? new Response(); $kernel = $this->createMock(HttpKernelInterface::class); $event = new ResponseEvent($kernel, $request, $type, $response); From b99b8ce04a8a43b121fb9b6cf699326509dfe375 Mon Sep 17 00:00:00 2001 From: StefanoCappellini Date: Sat, 10 Apr 2021 16:16:03 +0200 Subject: [PATCH 112/396] Simplified condition and removed unused code from AbstractSessionListener::onKernelRequest --- EventListener/AbstractSessionListener.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/EventListener/AbstractSessionListener.php b/EventListener/AbstractSessionListener.php index 0e99ee55c2..76c2064d18 100644 --- a/EventListener/AbstractSessionListener.php +++ b/EventListener/AbstractSessionListener.php @@ -53,14 +53,13 @@ public function onKernelRequest(GetResponseEvent $event) return; } - $session = null; $request = $event->getRequest(); if (!$request->hasSession()) { $sess = null; $request->setSessionFactory(function () use (&$sess) { return $sess ?? $sess = $this->getSession(); }); } - $session = $session ?? ($this->container && $this->container->has('initialized_session') ? $this->container->get('initialized_session') : null); + $session = $this->container && $this->container->has('initialized_session') ? $this->container->get('initialized_session') : null; $this->sessionUsageStack[] = $session instanceof Session ? $session->getUsageIndex() : 0; } From aa4d9d23491bb37d4c1164ce516768bbd8740d4f Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 12 Apr 2021 09:43:03 +0200 Subject: [PATCH 113/396] [HttpKernel] Minor fixes and tweaks in the Symfony Welcome Page --- Resources/welcome.html.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Resources/welcome.html.php b/Resources/welcome.html.php index b8337dc737..b25f99b3d0 100644 --- a/Resources/welcome.html.php +++ b/Resources/welcome.html.php @@ -19,8 +19,9 @@ .wrapper { text-align: center; width: 100%; } .container { position: relative; background: radial-gradient(ellipse at bottom, 0%, hsl(, 20%, 13%) 100%); background-attachment: fixed; color: ; } .container:after { content: ""; position: absolute; height: 2px; width: 2px; top: -2px; left: 0; background: white; box-shadow: 778px 1019px 0 0 rgba(255, 255, 255, 0.826) , 1075px 1688px 0 0 rgba(255,255,255, 0.275) , 388px 1021px 0 0 rgba(255,255,255, 0.259) , 1238px 626px 0 0 rgba(255,255,255, 0.469) , 997px 904px 0 0 rgba(255,255,255, 0.925) , 921px 1345px 0 0 rgba(255,255,255, 0.698) , 337px 1236px 0 0 rgba(255,255,255, 0.838) , 460px 569px 0 0 rgba(255,255,255, 0.01) , 690px 1488px 0 0 rgba(255,255,255, 0.154) , 859px 926px 0 0 rgba(255,255,255, 0.515) , 1272px 791px 0 0 rgba(255,255,255, 1) , 238px 1256px 0 0 rgba(255,255,255, 0.633) , 1486px 897px 0 0 rgba(255,255,255, 0.88) , 667px 6px 0 0 rgba(255,255,255, 0.508) , 853px 504px 0 0 rgba(255,255,255, 0.248) , 1329px 1778px 0 0 rgba(255,255,255, 0.217) , 768px 1340px 0 0 rgba(255,255,255, 0.792) , 631px 1383px 0 0 rgba(255,255,255, 0.698) , 991px 1603px 0 0 rgba(255,255,255, 0.939) , 1778px 1767px 0 0 rgba(255,255,255, 0.784) , 285px 546px 0 0 rgba(255,255,255, 0.8) , 1224px 1333px 0 0 rgba(255,255,255, 0.676) , 1154px 397px 0 0 rgba(255,255,255, 0.974) , 1210px 1004px 0 0 rgba(255,255,255, 0.894) , 1632px 953px 0 0 rgba(255,255,255, 0.281) , 449px 1144px 0 0 rgba(255,255,255, 0.706) , 1426px 771px 0 0 rgba(255,255,255, 0.737) , 1438px 1634px 0 0 rgba(255,255,255, 0.984) , 806px 168px 0 0 rgba(255,255,255, 0.807) , 731px 1067px 0 0 rgba(255,255,255, 0.734) , 1731px 1785px 0 0 rgba(255,255,255, 0.528) , 23px 975px 0 0 rgba(255,255,255, 0.068) , 575px 1088px 0 0 rgba(255,255,255, 0.876) , 1205px 1668px 0 0 rgba(255,255,255, 0.601) , 18px 1457px 0 0 rgba(255,255,255, 0.176) , 252px 1163px 0 0 rgba(255,255,255, 0.416) , 1752px 1px 0 0 rgba(255,255,255, 0.374) , 382px 767px 0 0 rgba(255,255,255, 0.073) , 133px 1462px 0 0 rgba(255,255,255, 0.706) , 851px 1166px 0 0 rgba(255,255,255, 0.535) , 374px 921px 0 0 rgba(255,255,255, 0.548) , 554px 1598px 0 0 rgba(255,255,255, 0.062) , 314px 685px 0 0 rgba(255,255,255, 0.187) , 1443px 209px 0 0 rgba(255,255,255, 0.097) , 1774px 1625px 0 0 rgba(255,255,255, 0.32) , 58px 278px 0 0 rgba(255,255,255, 0.684) , 986px 338px 0 0 rgba(255,255,255, 0.272) , 718px 1357px 0 0 rgba(255,255,255, 0.317) , 722px 983px 0 0 rgba(255,255,255, 0.568) , 1124px 992px 0 0 rgba(255,255,255, 0.199) , 581px 619px 0 0 rgba(255,255,255, 0.44) , 1120px 285px 0 0 rgba(255,255,255, 0.425) , 702px 138px 0 0 rgba(255,255,255, 0.816) , 262px 767px 0 0 rgba(255,255,255, 0.92) , 1204px 38px 0 0 rgba(255,255,255, 0.197) , 1196px 410px 0 0 rgba(255,255,255, 0.453) , 707px 699px 0 0 rgba(255,255,255, 0.481) , 1590px 1488px 0 0 rgba(255,255,255, 0.559) , 879px 1763px 0 0 rgba(255,255,255, 0.241) , 106px 686px 0 0 rgba(255,255,255, 0.175) , 158px 569px 0 0 rgba(255,255,255, 0.549) , 711px 1219px 0 0 rgba(255,255,255, 0.476) , 1339px 53px 0 0 rgba(255,255,255, 0.275) , 1410px 172px 0 0 rgba(255,255,255, 0.449) , 1601px 1484px 0 0 rgba(255,255,255, 0.988) , 1328px 1752px 0 0 rgba(255,255,255, 0.827) , 1733px 1475px 0 0 rgba(255,255,255, 0.567) , 559px 742px 0 0 rgba(255,255,255, 0.423) , 772px 844px 0 0 rgba(255,255,255, 0.039) , 602px 520px 0 0 rgba(255,255,255, 0.284) , 1158px 1067px 0 0 rgba(255,255,255, 0.066) , 1562px 730px 0 0 rgba(255,255,255, 0.086) , 1792px 615px 0 0 rgba(255,255,255, 0.438) , 1085px 1191px 0 0 rgba(255,255,255, 0.157) , 1402px 1087px 0 0 rgba(255,255,255, 0.797) , 569px 1685px 0 0 rgba(255,255,255, 0.992) , 1608px 52px 0 0 rgba(255,255,255, 0.302) , 1697px 1246px 0 0 rgba(255,255,255, 0.295) , 899px 1490px 0 0 rgba(255,255,255, 0.73) , 993px 901px 0 0 rgba(255,255,255, 0.961) , 1193px 1023px 0 0 rgba(255,255,255, 0.671) , 1224px 176px 0 0 rgba(255,255,255, 0.786) , 721px 1308px 0 0 rgba(255,255,255, 0.691) , 1702px 730px 0 0 rgba(255,255,255, 0.841) , 1480px 1498px 0 0 rgba(255,255,255, 0.655) , 181px 1612px 0 0 rgba(255,255,255, 0.588) , 1776px 679px 0 0 rgba(255,255,255, 0.821) , 892px 706px 0 0 rgba(255,255,255, 0.056) , 859px 267px 0 0 rgba(255,255,255, 0.565) , 784px 1285px 0 0 rgba(255,255,255, 0.029) , 1561px 1198px 0 0 rgba(255,255,255, 0.315) , 205px 421px 0 0 rgba(255,255,255, 0.584) , 236px 406px 0 0 rgba(255,255,255, 0.166) , 1259px 689px 0 0 rgba(255,255,255, 0.321) , 448px 317px 0 0 rgba(255,255,255, 0.495) , 1318px 466px 0 0 rgba(255,255,255, 0.275) , 1053px 297px 0 0 rgba(255,255,255, 0.035) , 716px 538px 0 0 rgba(255,255,255, 0.764) , 381px 207px 0 0 rgba(255,255,255, 0.692) , 871px 1140px 0 0 rgba(255,255,255, 0.342) , 361px 53px 0 0 rgba(255,255,255, 0.984) , 1565px 1593px 0 0 rgba(255,255,255, 0.102) , 145px 277px 0 0 rgba(255,255,255, 0.866) , 220px 1503px 0 0 rgba(255,255,255, 0.936) , 1068px 1475px 0 0 rgba(255,255,255, 0.156) , 1548px 483px 0 0 rgba(255,255,255, 0.768) , 710px 103px 0 0 rgba(255,255,255, 0.809) , 1660px 921px 0 0 rgba(255,255,255, 0.952) , 462px 1252px 0 0 rgba(255,255,255, 0.825) , 1123px 1628px 0 0 rgba(255,255,255, 0.409) , 1274px 729px 0 0 rgba(255,255,255, 0.26) , 1739px 679px 0 0 rgba(255,255,255, 0.83) , 1550px 1518px 0 0 rgba(255,255,255, 0.25) , 1624px 346px 0 0 rgba(255,255,255, 0.557) , 1023px 579px 0 0 rgba(255,255,255, 0.854) , 217px 661px 0 0 rgba(255,255,255, 0.731) , 1504px 549px 0 0 rgba(255,255,255, 0.705) , 939px 5px 0 0 rgba(255,255,255, 0.389) , 284px 735px 0 0 rgba(255,255,255, 0.355) , 13px 1679px 0 0 rgba(255,255,255, 0.712) , 137px 1592px 0 0 rgba(255,255,255, 0.619) , 1113px 505px 0 0 rgba(255,255,255, 0.651) , 1584px 510px 0 0 rgba(255,255,255, 0.41) , 346px 913px 0 0 rgba(255,255,255, 0.09) , 198px 1490px 0 0 rgba(255,255,255, 0.103) , 447px 1128px 0 0 rgba(255,255,255, 0.314) , 1356px 324px 0 0 rgba(255,255,255, 0.324) , 648px 667px 0 0 rgba(255,255,255, 0.155) , 442px 260px 0 0 rgba(255,255,255, 0.22) , 210px 401px 0 0 rgba(255,255,255, 0.682) , 422px 1772px 0 0 rgba(255,255,255, 0.671) , 276px 349px 0 0 rgba(255,255,255, 0.683) , 131px 539px 0 0 rgba(255,255,255, 0.977) , 892px 94px 0 0 rgba(255,255,255, 0.081) , 1295px 222px 0 0 rgba(255,255,255, 0.961) , 5px 1727px 0 0 rgba(255,255,255, 0.311) , 714px 1148px 0 0 rgba(255,255,255, 0.846) , 1455px 1182px 0 0 rgba(255,255,255, 0.313) , 1370px 708px 0 0 rgba(255,255,255, 0.824) , 812px 433px 0 0 rgba(255,255,255, 0.75) , 1110px 558px 0 0 rgba(255,255,255, 0.709) , 1132px 1543px 0 0 rgba(255,255,255, 0.868) , 644px 610px 0 0 rgba(255,255,255, 0.166) , 269px 1481px 0 0 rgba(255,255,255, 0.889) , 1712px 590px 0 0 rgba(255,255,255, 0.139) , 1159px 599px 0 0 rgba(255,255,255, 0.992) , 1551px 209px 0 0 rgba(255,255,255, 0.033) , 1020px 1721px 0 0 rgba(255,255,255, 0.028) , 216px 373px 0 0 rgba(255,255,255, 0.665) , 877px 532px 0 0 rgba(255,255,255, 0.686) , 1326px 885px 0 0 rgba(255,255,255, 0.517) , 972px 1704px 0 0 rgba(255,255,255, 0.499) , 749px 181px 0 0 rgba(255,255,255, 0.712) , 1511px 1650px 0 0 rgba(255,255,255, 0.101) , 1432px 183px 0 0 rgba(255,255,255, 0.545) , 1541px 1338px 0 0 rgba(255,255,255, 0.71) , 513px 1406px 0 0 rgba(255,255,255, 0.17) , 1314px 1197px 0 0 rgba(255,255,255, 0.789) , 824px 1659px 0 0 rgba(255,255,255, 0.597) , 308px 298px 0 0 rgba(255,255,255, 0.917) , 1225px 659px 0 0 rgba(255,255,255, 0.229) , 1253px 257px 0 0 rgba(255,255,255, 0.631) , 1653px 185px 0 0 rgba(255,255,255, 0.113) , 336px 614px 0 0 rgba(255,255,255, 0.045) , 1093px 898px 0 0 rgba(255,255,255, 0.617) , 730px 5px 0 0 rgba(255,255,255, 0.11) , 785px 645px 0 0 rgba(255,255,255, 0.516) , 989px 678px 0 0 rgba(255,255,255, 0.917) , 1511px 1614px 0 0 rgba(255,255,255, 0.938) , 584px 1117px 0 0 rgba(255,255,255, 0.631) , 534px 1012px 0 0 rgba(255,255,255, 0.668) , 1325px 1778px 0 0 rgba(255,255,255, 0.293) , 1632px 754px 0 0 rgba(255,255,255, 0.26) , 78px 1258px 0 0 rgba(255,255,255, 0.52) , 779px 1691px 0 0 rgba(255,255,255, 0.878) , 253px 1706px 0 0 rgba(255,255,255, 0.75) , 1358px 245px 0 0 rgba(255,255,255, 0.027) , 361px 1629px 0 0 rgba(255,255,255, 0.238) , 1134px 232px 0 0 rgba(255,255,255, 0.387) , 1685px 777px 0 0 rgba(255,255,255, 0.156) , 515px 724px 0 0 rgba(255,255,255, 0.863) , 588px 1728px 0 0 rgba(255,255,255, 0.159) , 1132px 47px 0 0 rgba(255,255,255, 0.691) , 315px 1446px 0 0 rgba(255,255,255, 0.782) , 79px 233px 0 0 rgba(255,255,255, 0.317) , 1498px 1050px 0 0 rgba(255,255,255, 0.358) , 30px 1073px 0 0 rgba(255,255,255, 0.939) , 1637px 620px 0 0 rgba(255,255,255, 0.141) , 1736px 1683px 0 0 rgba(255,255,255, 0.682) , 1298px 1505px 0 0 rgba(255,255,255, 0.863) , 972px 85px 0 0 rgba(255,255,255, 0.941) , 349px 1356px 0 0 rgba(255,255,255, 0.672) , 1545px 1429px 0 0 rgba(255,255,255, 0.859) , 1076px 467px 0 0 rgba(255,255,255, 0.024) , 189px 1647px 0 0 rgba(255,255,255, 0.838) , 423px 1722px 0 0 rgba(255,255,255, 0.771) , 1691px 1719px 0 0 rgba(255,255,255, 0.676) , 1747px 658px 0 0 rgba(255,255,255, 0.255) , 149px 1492px 0 0 rgba(255,255,255, 0.911) , 1203px 1138px 0 0 rgba(255,255,255, 0.964) , 781px 1584px 0 0 rgba(255,255,255, 0.465) , 1609px 1595px 0 0 rgba(255,255,255, 0.688) , 447px 1655px 0 0 rgba(255,255,255, 0.166) , 914px 1153px 0 0 rgba(255,255,255, 0.085) , 600px 1058px 0 0 rgba(255,255,255, 0.821) , 804px 505px 0 0 rgba(255,255,255, 0.608) , 1506px 584px 0 0 rgba(255,255,255, 0.618) , 587px 1290px 0 0 rgba(255,255,255, 0.071) , 258px 600px 0 0 rgba(255,255,255, 0.243) , 328px 395px 0 0 rgba(255,255,255, 0.065) , 846px 783px 0 0 rgba(255,255,255, 0.995) , 1138px 1294px 0 0 rgba(255,255,255, 0.703) , 1668px 633px 0 0 rgba(255,255,255, 0.27) , 337px 103px 0 0 rgba(255,255,255, 0.202) , 132px 986px 0 0 rgba(255,255,255, 0.726) , 414px 757px 0 0 rgba(255,255,255, 0.752) , 8px 1311px 0 0 rgba(255,255,255, 0.307) , 1791px 910px 0 0 rgba(255,255,255, 0.346) , 844px 216px 0 0 rgba(255,255,255, 0.156) , 1547px 1723px 0 0 rgba(255,255,255, 0.73) , 1187px 398px 0 0 rgba(255,255,255, 0.698) , 1550px 1520px 0 0 rgba(255,255,255, 0.462) , 1346px 655px 0 0 rgba(255,255,255, 0.58) , 668px 770px 0 0 rgba(255,255,255, 0.422) , 1774px 1435px 0 0 rgba(255,255,255, 0.089) , 693px 1061px 0 0 rgba(255,255,255, 0.893) , 132px 1689px 0 0 rgba(255,255,255, 0.937) , 894px 1561px 0 0 rgba(255,255,255, 0.88) , 906px 1706px 0 0 rgba(255,255,255, 0.567) , 1140px 297px 0 0 rgba(255,255,255, 0.358) , 13px 1288px 0 0 rgba(255,255,255, 0.464) , 1744px 423px 0 0 rgba(255,255,255, 0.845) , 119px 1548px 0 0 rgba(255,255,255, 0.769) , 1249px 1321px 0 0 rgba(255,255,255, 0.29) , 123px 795px 0 0 rgba(255,255,255, 0.597) , 390px 1542px 0 0 rgba(255,255,255, 0.47) , 825px 667px 0 0 rgba(255,255,255, 0.049) , 1071px 875px 0 0 rgba(255,255,255, 0.06) , 1428px 1786px 0 0 rgba(255,255,255, 0.222) , 993px 696px 0 0 rgba(255,255,255, 0.399) , 1585px 247px 0 0 rgba(255,255,255, 0.094) , 1340px 1312px 0 0 rgba(255,255,255, 0.603) , 1640px 725px 0 0 rgba(255,255,255, 0.026) , 1161px 1397px 0 0 rgba(255,255,255, 0.222) , 966px 1132px 0 0 rgba(255,255,255, 0.69) , 1782px 1275px 0 0 rgba(255,255,255, 0.606) , 1117px 1533px 0 0 rgba(255,255,255, 0.248) , 1027px 959px 0 0 rgba(255,255,255, 0.46) , 459px 839px 0 0 rgba(255,255,255, 0.98) , 1192px 265px 0 0 rgba(255,255,255, 0.523) , 175px 501px 0 0 rgba(255,255,255, 0.371) , 626px 19px 0 0 rgba(255,255,255, 0.246) , 46px 1173px 0 0 rgba(255,255,255, 0.124) , 573px 925px 0 0 rgba(255,255,255, 0.621) , 1px 283px 0 0 rgba(255,255,255, 0.943) , 778px 1213px 0 0 rgba(255,255,255, 0.128) , 435px 593px 0 0 rgba(255,255,255, 0.378) , 32px 394px 0 0 rgba(255,255,255, 0.451) , 1019px 1055px 0 0 rgba(255,255,255, 0.685) , 1423px 1233px 0 0 rgba(255,255,255, 0.354) , 494px 841px 0 0 rgba(255,255,255, 0.322) , 667px 194px 0 0 rgba(255,255,255, 0.655) , 1671px 195px 0 0 rgba(255,255,255, 0.502) , 403px 1710px 0 0 rgba(255,255,255, 0.623) , 665px 1597px 0 0 rgba(255,255,255, 0.839) , 61px 1742px 0 0 rgba(255,255,255, 0.566) , 1490px 1654px 0 0 rgba(255,255,255, 0.646) , 1361px 1604px 0 0 rgba(255,255,255, 0.101) , 1191px 1023px 0 0 rgba(255,255,255, 0.881) , 550px 378px 0 0 rgba(255,255,255, 0.573) , 1332px 1234px 0 0 rgba(255,255,255, 0.922) , 760px 1205px 0 0 rgba(255,255,255, 0.992) , 1506px 1328px 0 0 rgba(255,255,255, 0.723) , 1126px 813px 0 0 rgba(255,255,255, 0.549) , 67px 240px 0 0 rgba(255,255,255, 0.901) , 125px 1301px 0 0 rgba(255,255,255, 0.464) , 643px 391px 0 0 rgba(255,255,255, 0.589) , 1114px 1756px 0 0 rgba(255,255,255, 0.321) , 1602px 699px 0 0 rgba(255,255,255, 0.274) , 510px 393px 0 0 rgba(255,255,255, 0.185) , 171px 1217px 0 0 rgba(255,255,255, 0.932) , 1202px 1362px 0 0 rgba(255,255,255, 0.726) , 1160px 1324px 0 0 rgba(255,255,255, 0.867) , 121px 319px 0 0 rgba(255,255,255, 0.992) , 1474px 835px 0 0 rgba(255,255,255, 0.89) , 357px 1213px 0 0 rgba(255,255,255, 0.91) , 783px 976px 0 0 rgba(255,255,255, 0.941) , 750px 1599px 0 0 rgba(255,255,255, 0.515) , 323px 450px 0 0 rgba(255,255,255, 0.966) , 1078px 282px 0 0 rgba(255,255,255, 0.947) , 1164px 46px 0 0 rgba(255,255,255, 0.296) , 1792px 705px 0 0 rgba(255,255,255, 0.485) , 880px 1287px 0 0 rgba(255,255,255, 0.894) , 60px 1402px 0 0 rgba(255,255,255, 0.816) , 752px 894px 0 0 rgba(255,255,255, 0.803) , 285px 1535px 0 0 rgba(255,255,255, 0.93) , 1528px 401px 0 0 rgba(255,255,255, 0.727) , 651px 1767px 0 0 rgba(255,255,255, 0.146) , 1498px 1190px 0 0 rgba(255,255,255, 0.042) , 394px 1786px 0 0 rgba(255,255,255, 0.159) , 1318px 9px 0 0 rgba(255,255,255, 0.575) , 1699px 1675px 0 0 rgba(255,255,255, 0.511) , 82px 986px 0 0 rgba(255,255,255, 0.906) , 940px 970px 0 0 rgba(255,255,255, 0.562) , 1624px 259px 0 0 rgba(255,255,255, 0.537) , 1782px 222px 0 0 rgba(255,255,255, 0.259) , 1572px 1725px 0 0 rgba(255,255,255, 0.716) , 1080px 1557px 0 0 rgba(255,255,255, 0.245) , 1727px 648px 0 0 rgba(255,255,255, 0.471) , 899px 231px 0 0 rgba(255,255,255, 0.445) , 1061px 1074px 0 0 rgba(255,255,255, 0.079) , 556px 478px 0 0 rgba(255,255,255, 0.524) , 343px 359px 0 0 rgba(255,255,255, 0.162) , 711px 1254px 0 0 rgba(255,255,255, 0.323) , 1335px 242px 0 0 rgba(255,255,255, 0.936) , 933px 39px 0 0 rgba(255,255,255, 0.784) , 1629px 908px 0 0 rgba(255,255,255, 0.289) , 1800px 229px 0 0 rgba(255,255,255, 0.399) , 1589px 926px 0 0 rgba(255,255,255, 0.709) , 976px 694px 0 0 rgba(255,255,255, 0.855) , 1163px 1240px 0 0 rgba(255,255,255, 0.754) , 1662px 1784px 0 0 rgba(255,255,255, 0.088) , 656px 1388px 0 0 rgba(255,255,255, 0.688) , 1190px 1100px 0 0 rgba(255,255,255, 0.769) , 33px 392px 0 0 rgba(255,255,255, 0.301) , 56px 1405px 0 0 rgba(255,255,255, 0.969) , 1491px 118px 0 0 rgba(255,255,255, 0.991) , 1216px 997px 0 0 rgba(255,255,255, 0.727) , 1617px 712px 0 0 rgba(255,255,255, 0.45) , 163px 553px 0 0 rgba(255,255,255, 0.977) , 103px 140px 0 0 rgba(255,255,255, 0.916) , 1099px 1404px 0 0 rgba(255,255,255, 0.167) , 1423px 587px 0 0 rgba(255,255,255, 0.792) , 1797px 309px 0 0 rgba(255,255,255, 0.526) , 381px 141px 0 0 rgba(255,255,255, 0.005) , 1214px 802px 0 0 rgba(255,255,255, 0.887) , 211px 829px 0 0 rgba(255,255,255, 0.72) , 1103px 1507px 0 0 rgba(255,255,255, 0.642) , 244px 1231px 0 0 rgba(255,255,255, 0.184) , 118px 1747px 0 0 rgba(255,255,255, 0.475) , 183px 1293px 0 0 rgba(255,255,255, 0.148) , 911px 1362px 0 0 rgba(255,255,255, 0.073) , 817px 457px 0 0 rgba(255,255,255, 0.459) , 756px 18px 0 0 rgba(255,255,255, 0.544) , 481px 1118px 0 0 rgba(255,255,255, 0.878) , 380px 138px 0 0 rgba(255,255,255, 0.132) , 320px 646px 0 0 rgba(255,255,255, 0.04) , 1724px 1716px 0 0 rgba(255,255,255, 0.381) , 978px 1269px 0 0 rgba(255,255,255, 0.431) , 1530px 255px 0 0 rgba(255,255,255, 0.31) , 664px 204px 0 0 rgba(255,255,255, 0.913) , 474px 703px 0 0 rgba(255,255,255, 0.832) , 1722px 1204px 0 0 rgba(255,255,255, 0.356) , 1453px 821px 0 0 rgba(255,255,255, 0.195) , 730px 1468px 0 0 rgba(255,255,255, 0.696) , 928px 1610px 0 0 rgba(255,255,255, 0.894) , 1036px 304px 0 0 rgba(255,255,255, 0.696) , 1590px 172px 0 0 rgba(255,255,255, 0.729) , 249px 1590px 0 0 rgba(255,255,255, 0.277) , 357px 81px 0 0 rgba(255,255,255, 0.526) , 726px 1261px 0 0 rgba(255,255,255, 0.149) , 643px 946px 0 0 rgba(255,255,255, 0.005) , 1263px 995px 0 0 rgba(255,255,255, 0.124) , 1564px 1107px 0 0 rgba(255,255,255, 0.789) , 388px 83px 0 0 rgba(255,255,255, 0.498) , 715px 681px 0 0 rgba(255,255,255, 0.655) , 1618px 1624px 0 0 rgba(255,255,255, 0.63) , 1423px 1576px 0 0 rgba(255,255,255, 0.52) , 564px 1786px 0 0 rgba(255,255,255, 0.482) , 1066px 735px 0 0 rgba(255,255,255, 0.276) , 714px 1179px 0 0 rgba(255,255,255, 0.395) , 967px 1006px 0 0 rgba(255,255,255, 0.923) , 1136px 1790px 0 0 rgba(255,255,255, 0.801) , 215px 1690px 0 0 rgba(255,255,255, 0.957) , 1500px 1338px 0 0 rgba(255,255,255, 0.541) , 1679px 1065px 0 0 rgba(255,255,255, 0.925) , 426px 1489px 0 0 rgba(255,255,255, 0.193) , 1273px 853px 0 0 rgba(255,255,255, 0.317) , 665px 1189px 0 0 rgba(255,255,255, 0.512) , 520px 552px 0 0 rgba(255,255,255, 0.925) , 253px 438px 0 0 rgba(255,255,255, 0.588) , 369px 1354px 0 0 rgba(255,255,255, 0.889) , 749px 205px 0 0 rgba(255,255,255, 0.243) , 820px 145px 0 0 rgba(255,255,255, 0.207) , 1739px 228px 0 0 rgba(255,255,255, 0.267) , 392px 495px 0 0 rgba(255,255,255, 0.504) , 721px 1044px 0 0 rgba(255,255,255, 0.823) , 833px 912px 0 0 rgba(255,255,255, 0.222) , 865px 1499px 0 0 rgba(255,255,255, 0.003) , 313px 756px 0 0 rgba(255,255,255, 0.727) , 439px 1187px 0 0 rgba(255,255,255, 0.572) , 6px 1238px 0 0 rgba(255,255,255, 0.676) , 1567px 11px 0 0 rgba(255,255,255, 0.701) , 1216px 757px 0 0 rgba(255,255,255, 0.87) , 916px 588px 0 0 rgba(255,255,255, 0.565) , 831px 215px 0 0 rgba(255,255,255, 0.597) , 1289px 697px 0 0 rgba(255,255,255, 0.964) , 307px 34px 0 0 rgba(255,255,255, 0.462) , 3px 1685px 0 0 rgba(255,255,255, 0.464) , 1115px 1421px 0 0 rgba(255,255,255, 0.303) , 1451px 473px 0 0 rgba(255,255,255, 0.142) , 1374px 1205px 0 0 rgba(255,255,255, 0.086) , 1564px 317px 0 0 rgba(255,255,255, 0.773) , 304px 1127px 0 0 rgba(255,255,255, 0.653) , 446px 214px 0 0 rgba(255,255,255, 0.135) , 1541px 459px 0 0 rgba(255,255,255, 0.725) , 1387px 880px 0 0 rgba(255,255,255, 0.157) , 1172px 224px 0 0 rgba(255,255,255, 0.088) , 1420px 637px 0 0 rgba(255,255,255, 0.916) , 1385px 932px 0 0 rgba(255,255,255, 0.225) , 174px 1472px 0 0 rgba(255,255,255, 0.649) , 252px 750px 0 0 rgba(255,255,255, 0.277) , 825px 1042px 0 0 rgba(255,255,255, 0.707) , 840px 703px 0 0 rgba(255,255,255, 0.948) , 1478px 1800px 0 0 rgba(255,255,255, 0.151) , 95px 1303px 0 0 rgba(255,255,255, 0.332) , 1198px 740px 0 0 rgba(255,255,255, 0.443) , 141px 312px 0 0 rgba(255,255,255, 0.04) , 291px 729px 0 0 rgba(255,255,255, 0.284) , 1209px 1506px 0 0 rgba(255,255,255, 0.741) , 1188px 307px 0 0 rgba(255,255,255, 0.141) , 958px 41px 0 0 rgba(255,255,255, 0.858) , 1311px 1484px 0 0 rgba(255,255,255, 0.097) , 846px 1153px 0 0 rgba(255,255,255, 0.862) , 1238px 1376px 0 0 rgba(255,255,255, 0.071) , 1499px 342px 0 0 rgba(255,255,255, 0.719) , 640px 833px 0 0 rgba(255,255,255, 0.966) , 712px 545px 0 0 rgba(255,255,255, 0.194) , 1655px 1542px 0 0 rgba(255,255,255, 0.82) , 616px 353px 0 0 rgba(255,255,255, 0.871) , 1591px 1631px 0 0 rgba(255,255,255, 0.61) , 1664px 591px 0 0 rgba(255,255,255, 0.35) , 934px 454px 0 0 rgba(255,255,255, 0.58) , 1175px 477px 0 0 rgba(255,255,255, 0.966) , 299px 914px 0 0 rgba(255,255,255, 0.839) , 534px 243px 0 0 rgba(255,255,255, 0.194) , 773px 1135px 0 0 rgba(255,255,255, 0.42) , 1696px 1472px 0 0 rgba(255,255,255, 0.552) , 125px 523px 0 0 rgba(255,255,255, 0.591) , 1195px 382px 0 0 rgba(255,255,255, 0.904) , 1609px 1374px 0 0 rgba(255,255,255, 0.579) , 843px 82px 0 0 rgba(255,255,255, 0.072) , 1604px 451px 0 0 rgba(255,255,255, 0.545) , 1322px 190px 0 0 rgba(255,255,255, 0.034) , 528px 228px 0 0 rgba(255,255,255, 0.146) , 1470px 1169px 0 0 rgba(255,255,255, 0.912) , 502px 1350px 0 0 rgba(255,255,255, 0.594) , 1031px 298px 0 0 rgba(255,255,255, 0.368) , 1100px 1427px 0 0 rgba(255,255,255, 0.79) , 979px 1105px 0 0 rgba(255,255,255, 0.973) , 643px 1184px 0 0 rgba(255,255,255, 0.813) , 1636px 1701px 0 0 rgba(255,255,255, 0.013) , 1004px 245px 0 0 rgba(255,255,255, 0.412) , 680px 740px 0 0 rgba(255,255,255, 0.967) , 1599px 562px 0 0 rgba(255,255,255, 0.66) , 256px 1617px 0 0 rgba(255,255,255, 0.463) , 314px 1092px 0 0 rgba(255,255,255, 0.734) , 870px 900px 0 0 rgba(255,255,255, 0.512) , 530px 60px 0 0 rgba(255,255,255, 0.198) , 1786px 896px 0 0 rgba(255,255,255, 0.392) , 636px 212px 0 0 rgba(255,255,255, 0.997) , 672px 540px 0 0 rgba(255,255,255, 0.632) , 1118px 1649px 0 0 rgba(255,255,255, 0.377) , 433px 647px 0 0 rgba(255,255,255, 0.902) , 1200px 1737px 0 0 rgba(255,255,255, 0.262) , 1258px 143px 0 0 rgba(255,255,255, 0.729) , 1603px 1364px 0 0 rgba(255,255,255, 0.192) , 66px 1756px 0 0 rgba(255,255,255, 0.681) , 946px 263px 0 0 rgba(255,255,255, 0.105) , 1216px 1082px 0 0 rgba(255,255,255, 0.287) , 6px 1143px 0 0 rgba(255,255,255, 0.017) , 1631px 126px 0 0 rgba(255,255,255, 0.449) , 357px 1565px 0 0 rgba(255,255,255, 0.163) , 1752px 261px 0 0 rgba(255,255,255, 0.423) , 1247px 1631px 0 0 rgba(255,255,255, 0.312) , 320px 671px 0 0 rgba(255,255,255, 0.695) , 1375px 596px 0 0 rgba(255,255,255, 0.856) , 1456px 1340px 0 0 rgba(255,255,255, 0.564) , 447px 1044px 0 0 rgba(255,255,255, 0.623) , 1732px 447px 0 0 rgba(255,255,255, 0.216) , 174px 1509px 0 0 rgba(255,255,255, 0.398) , 16px 861px 0 0 rgba(255,255,255, 0.904) , 878px 1296px 0 0 rgba(255,255,255, 0.205) , 1725px 1483px 0 0 rgba(255,255,255, 0.704) , 255px 48px 0 0 rgba(255,255,255, 0.7) , 610px 1669px 0 0 rgba(255,255,255, 0.865) , 1044px 1251px 0 0 rgba(255,255,255, 0.98) , 884px 862px 0 0 rgba(255,255,255, 0.198) , 986px 545px 0 0 rgba(255,255,255, 0.379) , 1620px 217px 0 0 rgba(255,255,255, 0.159) , 383px 1763px 0 0 rgba(255,255,255, 0.518) , 595px 974px 0 0 rgba(255,255,255, 0.347) , 359px 14px 0 0 rgba(255,255,255, 0.863) , 95px 1385px 0 0 rgba(255,255,255, 0.011) , 411px 1030px 0 0 rgba(255,255,255, 0.038) , 345px 789px 0 0 rgba(255,255,255, 0.771) , 421px 460px 0 0 rgba(255,255,255, 0.133) , 972px 1160px 0 0 rgba(255,255,255, 0.342) , 597px 1061px 0 0 rgba(255,255,255, 0.781) , 1017px 1092px 0 0 rgba(255,255,255, 0.437); } - .warning { background: ; display: flex; align-content: center; padding: 10px; text-align: left; justify-content: center; } - .warning svg { height: 48px; width: 48px; margin-right: 10px; } + .warning { background: ; display: flex; align-items: center; padding: 10px; text-align: left; justify-content: center; } + .warning svg { flex-shrink: 0; height: 32px; width: 32px; margin-right: 10px; } + .warning p { line-height: 1.4; margin: 0; } .container svg.wave { position: absolute; bottom: -2px; left: 0; z-index: 1; } .container .logo { margin-bottom: 1em; } .container .logo svg { fill: hsl(, 20%, 26%); } @@ -45,9 +46,6 @@ @keyframes fade-in { 0% { opacity: 0; } 100% { opacity: 1; } } .sf-toolbar { opacity: 0; -webkit-animation: fade-in 1s .2s forwards; animation: fade-in 1s .2s forwards; z-index: 99999; } - body { font-size: 20px; } - .warning { text-align: center; } - .warning svg { height: 32px; width: 32px; } .resources .row { margin-left: 50px; margin-right: 50px; } .resource { padding: 0 30px; } @@ -59,13 +57,19 @@ .resource h2 { font-size: 22px; } .resource a { font-size: 16px; margin-top: 0; } } + @media (min-width: 992px) { + body { font-size: 20px; } + .warning { text-align: center; } + }
- You're seeing this page because you haven't configured any homepage URL and debug mode is enabled. +

+ You're seeing this page because you haven't configured any homepage URL and debug mode is enabled. +

From 0905c3eef6802b805614126496d7cf03de68df2e Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 13 Apr 2021 13:27:06 +0200 Subject: [PATCH 114/396] Fixed the deprecation message about Master/Main requests --- Event/KernelEvent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Event/KernelEvent.php b/Event/KernelEvent.php index d0793f3624..8ede505c71 100644 --- a/Event/KernelEvent.php +++ b/Event/KernelEvent.php @@ -85,7 +85,7 @@ public function isMainRequest(): bool */ public function isMasterRequest() { - trigger_deprecation('symfony/http-kernel', '5.3', '"%s()" is deprecated, use "isMainRequest()" instead.'); + trigger_deprecation('symfony/http-kernel', '5.3', '"%s()" is deprecated, use "isMainRequest()" instead.', __METHOD__); return $this->isMainRequest(); } From 28aec457860878b396123a6a3e094927399328c0 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Sat, 27 Mar 2021 16:20:02 +0100 Subject: [PATCH 115/396] [Config][DependencyInjection] Add configuration builder for writing PHP config --- Kernel.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Kernel.php b/Kernel.php index dbe5a111da..330ca1ef85 100644 --- a/Kernel.php +++ b/Kernel.php @@ -13,6 +13,7 @@ use Symfony\Bridge\ProxyManager\LazyProxy\Instantiator\RuntimeInstantiator; use Symfony\Bridge\ProxyManager\LazyProxy\PhpDumper\ProxyDumper; +use Symfony\Component\Config\Builder\ConfigBuilderGenerator; use Symfony\Component\Config\ConfigCache; use Symfony\Component\Config\Loader\DelegatingLoader; use Symfony\Component\Config\Loader\LoaderResolver; @@ -758,7 +759,7 @@ protected function getContainerLoader(ContainerInterface $container) new XmlFileLoader($container, $locator, $env), new YamlFileLoader($container, $locator, $env), new IniFileLoader($container, $locator, $env), - new PhpFileLoader($container, $locator, $env), + new PhpFileLoader($container, $locator, $env, class_exists(ConfigBuilderGenerator::class) ? new ConfigBuilderGenerator($this->getBuildDir()) : null), new GlobFileLoader($container, $locator, $env), new DirectoryLoader($container, $locator, $env), new ClosureLoader($container, $env), From 60de1c972839fb3ebee37a9f6b516c127dda4fbd Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 13 Apr 2021 11:30:13 +0200 Subject: [PATCH 116/396] [DependencyInjection] Add `#[Target]` to tell how a dependency is used and hint named autowiring aliases --- ...RegisterControllerArgumentLocatorsPass.php | 3 +- ...sterControllerArgumentLocatorsPassTest.php | 31 +++++++++++++++++++ composer.json | 4 +-- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php index eba2430b20..590257dff3 100644 --- a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php +++ b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php @@ -12,6 +12,7 @@ namespace Symfony\Component\HttpKernel\DependencyInjection; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\DependencyInjection\Attribute\Target; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass; @@ -148,7 +149,7 @@ public function process(ContainerBuilder $container) } elseif ($p->allowsNull() && !$p->isOptional()) { $invalidBehavior = ContainerInterface::NULL_ON_INVALID_REFERENCE; } - } elseif (isset($bindings[$bindingName = $type.' $'.$p->name]) || isset($bindings[$bindingName = '$'.$p->name]) || isset($bindings[$bindingName = $type])) { + } elseif (isset($bindings[$bindingName = $type.' $'.$name = Target::parseName($p)]) || isset($bindings[$bindingName = '$'.$name]) || isset($bindings[$bindingName = $type])) { $binding = $bindings[$bindingName]; [$bindingValue, $bindingId, , $bindingType, $bindingFile] = $binding->getValues(); diff --git a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php index d15e2eab11..22ace783a3 100644 --- a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php +++ b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php @@ -13,6 +13,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; +use Symfony\Component\DependencyInjection\Attribute\Target; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\ContainerAwareInterface; use Symfony\Component\DependencyInjection\ContainerAwareTrait; @@ -397,6 +398,27 @@ public function testAlias() $locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0); $this->assertSame([RegisterTestController::class.'::fooAction', 'foo::fooAction'], array_keys($locator)); } + + /** + * @requires PHP 8 + */ + public function testBindWithTarget() + { + $container = new ContainerBuilder(); + $resolver = $container->register('argument_resolver.service')->addArgument([]); + + $container->register('foo', WithTarget::class) + ->setBindings(['string $someApiKey' => new Reference('the_api_key')]) + ->addTag('controller.service_arguments'); + + (new RegisterControllerArgumentLocatorsPass())->process($container); + + $locator = $container->getDefinition((string) $resolver->getArgument(0))->getArgument(0); + $locator = $container->getDefinition((string) $locator['foo::fooAction']->getValues()[0]); + + $expected = ['apiKey' => new ServiceClosureArgument(new Reference('the_api_key'))]; + $this->assertEquals($expected, $locator->getArgument(0)); + } } class RegisterTestController @@ -458,3 +480,12 @@ public function fooAction(string $someArg) { } } + +class WithTarget +{ + public function fooAction( + #[Target('some.api.key')] + string $apiKey + ) { + } +} diff --git a/composer.json b/composer.json index fb8757ade3..e5dd1db298 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "symfony/config": "^5.0", "symfony/console": "^4.4|^5.0", "symfony/css-selector": "^4.4|^5.0", - "symfony/dependency-injection": "^5.1.8", + "symfony/dependency-injection": "^5.3", "symfony/dom-crawler": "^4.4|^5.0", "symfony/expression-language": "^4.4|^5.0", "symfony/finder": "^4.4|^5.0", @@ -53,7 +53,7 @@ "symfony/config": "<5.0", "symfony/console": "<4.4", "symfony/form": "<5.0", - "symfony/dependency-injection": "<5.1.8", + "symfony/dependency-injection": "<5.3", "symfony/doctrine-bridge": "<5.0", "symfony/http-client": "<5.0", "symfony/mailer": "<5.0", From 2e3f2408a314ec13e5bdac22b37faf47b1747285 Mon Sep 17 00:00:00 2001 From: MatTheCat Date: Fri, 30 Apr 2021 14:55:51 +0200 Subject: [PATCH 117/396] Move IDE file link formats from FrameworkExtension to FileLinkFormatter --- Debug/FileLinkFormatter.php | 12 +++++++++++- Tests/Debug/FileLinkFormatterTest.php | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Debug/FileLinkFormatter.php b/Debug/FileLinkFormatter.php index 55dcb52521..017409f194 100644 --- a/Debug/FileLinkFormatter.php +++ b/Debug/FileLinkFormatter.php @@ -24,6 +24,16 @@ */ class FileLinkFormatter { + private const FORMATS = [ + 'textmate' => 'txmt://open?url=file://%f&line=%l', + 'macvim' => 'mvim://open?url=file://%f&line=%l', + 'emacs' => 'emacs://open?url=file://%f&line=%l', + 'sublime' => 'subl://open?url=file://%f&line=%l', + 'phpstorm' => 'phpstorm://open?file=%f&line=%l', + 'atom' => 'atom://core/open/file?filename=%f&line=%l', + 'vscode' => 'vscode://file/%f:%l', + ]; + private $fileLinkFormat; private $requestStack; private $baseDir; @@ -34,7 +44,7 @@ class FileLinkFormatter */ public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null) { - $fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); + $fileLinkFormat = (self::FORMATS[$fileLinkFormat] ?? $fileLinkFormat) ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); if ($fileLinkFormat && !\is_array($fileLinkFormat)) { $i = strpos($f = $fileLinkFormat, '&', max(strrpos($f, '%f'), strrpos($f, '%l'))) ?: \strlen($f); $fileLinkFormat = [substr($f, 0, $i)] + preg_split('/&([^>]++)>/', substr($f, $i), -1, \PREG_SPLIT_DELIM_CAPTURE); diff --git a/Tests/Debug/FileLinkFormatterTest.php b/Tests/Debug/FileLinkFormatterTest.php index 1f4d298bf3..af84d10eb3 100644 --- a/Tests/Debug/FileLinkFormatterTest.php +++ b/Tests/Debug/FileLinkFormatterTest.php @@ -51,4 +51,13 @@ public function testWhenNoFileLinkFormatAndRequest() $this->assertSame('http://www.example.org/_profiler/open?file=file.php&line=3#line3', $sut->format($file, 3)); } + + public function testIdeFileLinkFormat() + { + $file = __DIR__.\DIRECTORY_SEPARATOR.'file.php'; + + $sut = new FileLinkFormatter('atom'); + + $this->assertSame("atom://core/open/file?filename=$file&line=3", $sut->format($file, 3)); + } } From cd2e325fc34a4a5bbec91eecf69dda8ee8c5ea4f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 1 May 2021 16:38:48 +0200 Subject: [PATCH 118/396] Update VERSION for 4.4.22 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 447c9936eb..947c871e15 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.22-DEV'; + public const VERSION = '4.4.22'; public const VERSION_ID = 40422; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; public const RELEASE_VERSION = 22; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From 62d7cd914463a48541f4209f6d3fa0defb7e0d31 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 1 May 2021 16:48:05 +0200 Subject: [PATCH 119/396] Bump Symfony version to 4.4.23 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 947c871e15..c0d460634d 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.22'; - public const VERSION_ID = 40422; + public const VERSION = '4.4.23-DEV'; + public const VERSION_ID = 40423; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; - public const RELEASE_VERSION = 22; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 23; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From 1e9f6879f070f718e0055fbac232a56f67b8b6bd Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 1 May 2021 16:53:15 +0200 Subject: [PATCH 120/396] Update VERSION for 5.2.7 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 774f1f3a4d..112f9f2bd8 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.7-DEV'; + public const VERSION = '5.2.7'; public const VERSION_ID = 50207; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; public const RELEASE_VERSION = 7; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 0bb78307b5d2f171268635d61df433a16a5f3118 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 1 May 2021 16:56:20 +0200 Subject: [PATCH 121/396] Bump Symfony version to 5.2.8 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 112f9f2bd8..0366897e82 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.7'; - public const VERSION_ID = 50207; + public const VERSION = '5.2.8-DEV'; + public const VERSION_ID = 50208; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; - public const RELEASE_VERSION = 7; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 8; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 0913527e19ad97d8ab06737a7231a81bb5fbc3da Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 1 May 2021 16:58:22 +0200 Subject: [PATCH 122/396] Update VERSION for 5.3.0-BETA2 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 330ca1ef85..480fb5dc3c 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.0-DEV'; + public const VERSION = '5.3.0-BETA2'; public const VERSION_ID = 50300; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = 'BETA2'; public const END_OF_MAINTENANCE = '05/2021'; public const END_OF_LIFE = '01/2022'; From 8597fb40b172c0c4a2759fab78ebc1a41ba52176 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 1 May 2021 17:01:32 +0200 Subject: [PATCH 123/396] Bump Symfony version to 5.3.0 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 480fb5dc3c..330ca1ef85 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.0-BETA2'; + public const VERSION = '5.3.0-DEV'; public const VERSION_ID = 50300; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'BETA2'; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '05/2021'; public const END_OF_LIFE = '01/2022'; From 1d145a9160e0bbbbeec5d891e61e2eef81250437 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 9 May 2021 18:06:21 +0200 Subject: [PATCH 124/396] Update VERSION for 5.3.0-BETA3 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 330ca1ef85..606b06a144 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.0-DEV'; + public const VERSION = '5.3.0-BETA3'; public const VERSION_ID = 50300; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = 'BETA3'; public const END_OF_MAINTENANCE = '05/2021'; public const END_OF_LIFE = '01/2022'; From 119d347067d251984a8268cf51675acaf5f7fee4 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 9 May 2021 18:29:50 +0200 Subject: [PATCH 125/396] Bump Symfony version to 5.3.0 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 606b06a144..330ca1ef85 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.0-BETA3'; + public const VERSION = '5.3.0-DEV'; public const VERSION_ID = 50300; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'BETA3'; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '05/2021'; public const END_OF_LIFE = '01/2022'; From 95bb42312503a212f4467529bac8735f01226ff9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 12 May 2021 15:13:32 +0200 Subject: [PATCH 126/396] Update VERSION for 4.4.23 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index c0d460634d..9793dd39e2 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.23-DEV'; + public const VERSION = '4.4.23'; public const VERSION_ID = 40423; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; public const RELEASE_VERSION = 23; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From 0cc7b69c66f452d717570f9522abe22bd9397ad5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 12 May 2021 15:18:54 +0200 Subject: [PATCH 127/396] Bump Symfony version to 4.4.24 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 9793dd39e2..34bc8d7b4a 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.23'; - public const VERSION_ID = 40423; + public const VERSION = '4.4.24-DEV'; + public const VERSION_ID = 40424; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; - public const RELEASE_VERSION = 23; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 24; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From c3cb71ee7e2d3eae5fe1001f81780d6a49b37937 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 12 May 2021 15:27:53 +0200 Subject: [PATCH 128/396] Update VERSION for 5.2.8 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 0366897e82..5a48ccf9ec 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.8-DEV'; + public const VERSION = '5.2.8'; public const VERSION_ID = 50208; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; public const RELEASE_VERSION = 8; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 78c136fdeaf6e809ddfafa8441e2f63da71a9535 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 12 May 2021 15:34:48 +0200 Subject: [PATCH 129/396] Bump Symfony version to 5.2.9 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 5a48ccf9ec..bd9494d838 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.8'; - public const VERSION_ID = 50208; + public const VERSION = '5.2.9-DEV'; + public const VERSION_ID = 50209; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; - public const RELEASE_VERSION = 8; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 9; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 9d5b86ef0b6ad992e2e8303e9b756d8169203b8a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 12 May 2021 15:44:42 +0200 Subject: [PATCH 130/396] Update VERSION for 5.3.0-BETA4 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 330ca1ef85..e82f0f3d17 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.0-DEV'; + public const VERSION = '5.3.0-BETA4'; public const VERSION_ID = 50300; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = 'BETA4'; public const END_OF_MAINTENANCE = '05/2021'; public const END_OF_LIFE = '01/2022'; From 95038ec7baa55958321942d2a07d04afd1b1188f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 12 May 2021 15:50:25 +0200 Subject: [PATCH 131/396] Bump Symfony version to 5.3.0 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index e82f0f3d17..330ca1ef85 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.0-BETA4'; + public const VERSION = '5.3.0-DEV'; public const VERSION_ID = 50300; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'BETA4'; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '05/2021'; public const END_OF_LIFE = '01/2022'; From 46e66e82a99a8b9ad7b33685b12e8d9465be06e7 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 15 May 2021 19:17:06 +0200 Subject: [PATCH 132/396] Fixed deprecation warnings about passing null as parameter --- .../RegisterControllerArgumentLocatorsPass.php | 2 +- EventListener/RouterListener.php | 2 +- Tests/HttpCache/HttpCacheTest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php index 40c850cf66..cf4ab60284 100644 --- a/DependencyInjection/RegisterControllerArgumentLocatorsPass.php +++ b/DependencyInjection/RegisterControllerArgumentLocatorsPass.php @@ -124,7 +124,7 @@ public function process(ContainerBuilder $container) $args = []; foreach ($parameters as $p) { /** @var \ReflectionParameter $p */ - $type = ltrim($target = ProxyHelper::getTypeHint($r, $p), '\\'); + $type = ltrim($target = (string) ProxyHelper::getTypeHint($r, $p), '\\'); $invalidBehavior = ContainerInterface::IGNORE_ON_INVALID_REFERENCE; if (isset($arguments[$r->name][$p->name])) { diff --git a/EventListener/RouterListener.php b/EventListener/RouterListener.php index 0071979688..47ee87b103 100644 --- a/EventListener/RouterListener.php +++ b/EventListener/RouterListener.php @@ -164,7 +164,7 @@ public static function getSubscribedEvents() private function createWelcomeResponse(): Response { $version = Kernel::VERSION; - $projectDir = realpath($this->projectDir).\DIRECTORY_SEPARATOR; + $projectDir = realpath((string) $this->projectDir).\DIRECTORY_SEPARATOR; $docVersion = substr(Kernel::VERSION, 0, 3); ob_start(); diff --git a/Tests/HttpCache/HttpCacheTest.php b/Tests/HttpCache/HttpCacheTest.php index d9dd572bf1..9bec2f7c94 100644 --- a/Tests/HttpCache/HttpCacheTest.php +++ b/Tests/HttpCache/HttpCacheTest.php @@ -212,8 +212,8 @@ public function testIncrementsMaxAgeWhenNoDateIsSpecifiedEventWhenUsingETag() public function testValidatesPrivateResponsesCachedOnTheClient() { - $this->setNextResponse(200, [], '', function ($request, $response) { - $etags = preg_split('/\s*,\s*/', $request->headers->get('IF_NONE_MATCH')); + $this->setNextResponse(200, [], '', function (Request $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'); $response->setETag('"private tag"'); From 59925ee79f2541b4c6e990843e1a42768e898254 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 19 May 2021 14:12:19 +0200 Subject: [PATCH 133/396] Update VERSION for 4.4.24 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 34bc8d7b4a..3492753cf5 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.24-DEV'; + public const VERSION = '4.4.24'; public const VERSION_ID = 40424; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; public const RELEASE_VERSION = 24; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From f287ea9a4a8bc7d9af813f23c379f1c8538c0aca Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 19 May 2021 14:20:36 +0200 Subject: [PATCH 134/396] Bump Symfony version to 4.4.25 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 3492753cf5..885337bf37 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.24'; - public const VERSION_ID = 40424; + public const VERSION = '4.4.25-DEV'; + public const VERSION_ID = 40425; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; - public const RELEASE_VERSION = 24; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 25; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From eb540ef6870dbf33c92e372cfb869ebf9649e6cb Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 19 May 2021 14:23:45 +0200 Subject: [PATCH 135/396] Update VERSION for 5.2.9 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index bd9494d838..91ce455fea 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.9-DEV'; + public const VERSION = '5.2.9'; public const VERSION_ID = 50209; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; public const RELEASE_VERSION = 9; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From cd9bb08b941b443b4a45a467d2b8070434d3c8b0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 19 May 2021 14:28:17 +0200 Subject: [PATCH 136/396] Bump Symfony version to 5.2.10 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 91ce455fea..d3a79cd61a 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.9'; - public const VERSION_ID = 50209; + public const VERSION = '5.2.10-DEV'; + public const VERSION_ID = 50210; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; - public const RELEASE_VERSION = 9; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 10; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 979fdff931c6f870c1df6285e5f670ac9504637c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 19 May 2021 14:50:01 +0200 Subject: [PATCH 137/396] Update version to 5.4 --- Kernel.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Kernel.php b/Kernel.php index 330ca1ef85..238c1d7686 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,15 +75,15 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.0-DEV'; - public const VERSION_ID = 50300; + public const VERSION = '5.4.0-DEV'; + public const VERSION_ID = 50400; public const MAJOR_VERSION = 5; - public const MINOR_VERSION = 3; + public const MINOR_VERSION = 4; public const RELEASE_VERSION = 0; public const EXTRA_VERSION = 'DEV'; - public const END_OF_MAINTENANCE = '05/2021'; - public const END_OF_LIFE = '01/2022'; + public const END_OF_MAINTENANCE = '11/2024'; + public const END_OF_LIFE = '11/2025'; public function __construct(string $environment, bool $debug) { From 457964be37e9ccfc43a2e329670e5f0453b72af1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 19 May 2021 15:39:15 +0200 Subject: [PATCH 138/396] Update VERSION for 5.3.0-RC1 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 330ca1ef85..b612558dce 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.0-DEV'; + public const VERSION = '5.3.0-RC1'; public const VERSION_ID = 50300; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = 'RC1'; public const END_OF_MAINTENANCE = '05/2021'; public const END_OF_LIFE = '01/2022'; From 6c76bf402227f3a38af31f522c71e21cb6512437 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 19 May 2021 15:41:55 +0200 Subject: [PATCH 139/396] Bump Symfony version to 5.3.0 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index b612558dce..330ca1ef85 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.0-RC1'; + public const VERSION = '5.3.0-DEV'; public const VERSION_ID = 50300; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'RC1'; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '05/2021'; public const END_OF_LIFE = '01/2022'; From 08ec5d06b63b20c17054c959ee8ad89eedca25ad Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 19 May 2021 18:46:45 +0200 Subject: [PATCH 140/396] Allow Symfony 6 --- composer.json | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/composer.json b/composer.json index e5dd1db298..660c98fdfc 100644 --- a/composer.json +++ b/composer.json @@ -18,28 +18,28 @@ "require": { "php": ">=7.2.5", "symfony/deprecation-contracts": "^2.1", - "symfony/error-handler": "^4.4|^5.0", - "symfony/event-dispatcher": "^5.0", + "symfony/error-handler": "^4.4|^5.0|^6.0", + "symfony/event-dispatcher": "^5.0|^6.0", "symfony/http-client-contracts": "^1.1|^2", - "symfony/http-foundation": "^5.3", + "symfony/http-foundation": "^5.3|^6.0", "symfony/polyfill-ctype": "^1.8", "symfony/polyfill-php73": "^1.9", "symfony/polyfill-php80": "^1.15", "psr/log": "~1.0" }, "require-dev": { - "symfony/browser-kit": "^4.4|^5.0", - "symfony/config": "^5.0", - "symfony/console": "^4.4|^5.0", - "symfony/css-selector": "^4.4|^5.0", - "symfony/dependency-injection": "^5.3", - "symfony/dom-crawler": "^4.4|^5.0", - "symfony/expression-language": "^4.4|^5.0", - "symfony/finder": "^4.4|^5.0", - "symfony/process": "^4.4|^5.0", - "symfony/routing": "^4.4|^5.0", - "symfony/stopwatch": "^4.4|^5.0", - "symfony/translation": "^4.4|^5.0", + "symfony/browser-kit": "^4.4|^5.0|^6.0", + "symfony/config": "^5.0|^6.0", + "symfony/console": "^4.4|^5.0|^6.0", + "symfony/css-selector": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^5.3|^6.0", + "symfony/dom-crawler": "^4.4|^5.0|^6.0", + "symfony/expression-language": "^4.4|^5.0|^6.0", + "symfony/finder": "^4.4|^5.0|^6.0", + "symfony/process": "^4.4|^5.0|^6.0", + "symfony/routing": "^4.4|^5.0|^6.0", + "symfony/stopwatch": "^4.4|^5.0|^6.0", + "symfony/translation": "^4.4|^5.0|^6.0", "symfony/translation-contracts": "^1.1|^2", "psr/cache": "^1.0|^2.0|^3.0", "twig/twig": "^2.13|^3.0.4" From 482ba743426f1f3c59f7faa183a8666f0e57e654 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 24 May 2021 19:39:07 +0200 Subject: [PATCH 141/396] [HttpKernel] Throw when HttpKernel is created and the env is empty --- Kernel.php | 5 ++++- Tests/KernelTest.php | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Kernel.php b/Kernel.php index 330ca1ef85..27f30ad38a 100644 --- a/Kernel.php +++ b/Kernel.php @@ -87,7 +87,10 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl public function __construct(string $environment, bool $debug) { - $this->environment = $environment; + if (!$this->environment = $environment) { + throw new \InvalidArgumentException(sprintf('Invalid environment provided to "%s": the environment cannot be empty.', get_debug_type($this))); + } + $this->debug = $debug; } diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index e4df69e867..47a337f006 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -55,6 +55,14 @@ public function testConstructor() $this->assertLessThanOrEqual(microtime(true), $kernel->getStartTime()); } + public function testEmptyEnv() + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage(sprintf('Invalid environment provided to "%s": the environment cannot be empty.', KernelForTest::class)); + + new KernelForTest('', false); + } + public function testClone() { $env = 'test_env'; From 7fb15c1a92d2353515770cb80df2b8e64154afc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Thu, 20 May 2021 20:00:38 +0200 Subject: [PATCH 142/396] Fix compatibility with Symfony6 --- EventListener/AbstractSessionListener.php | 1 + EventListener/SessionListener.php | 10 ++++++--- EventListener/TestSessionListener.php | 10 ++++++--- Tests/EventListener/SessionListenerTest.php | 23 +++++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/EventListener/AbstractSessionListener.php b/EventListener/AbstractSessionListener.php index eae5fb6bab..d76f29b5bc 100644 --- a/EventListener/AbstractSessionListener.php +++ b/EventListener/AbstractSessionListener.php @@ -58,6 +58,7 @@ public function onKernelRequest(RequestEvent $event) $request = $event->getRequest(); if (!$request->hasSession()) { + // This variable prevents calling `$this->getSession()` twice in case the Request (and the below factory) is cloned $sess = null; $request->setSessionFactory(function () use (&$sess) { return $sess ?? $sess = $this->getSession(); }); } diff --git a/EventListener/SessionListener.php b/EventListener/SessionListener.php index f2b950cef2..e396aa5035 100644 --- a/EventListener/SessionListener.php +++ b/EventListener/SessionListener.php @@ -53,10 +53,14 @@ public function onKernelRequest(RequestEvent $event) protected function getSession(): ?SessionInterface { - if (!$this->container->has('session')) { - return null; + if ($this->container->has('session')) { + return $this->container->get('session'); } - return $this->container->get('session'); + if ($this->container->has('session_factory')) { + return $this->container->get('session_factory')->createSession(); + } + + return null; } } diff --git a/EventListener/TestSessionListener.php b/EventListener/TestSessionListener.php index ff8b4aaa61..6d4b36ace3 100644 --- a/EventListener/TestSessionListener.php +++ b/EventListener/TestSessionListener.php @@ -33,10 +33,14 @@ public function __construct(ContainerInterface $container, array $sessionOptions protected function getSession(): ?SessionInterface { - if (!$this->container->has('session')) { - return null; + if ($this->container->has('session')) { + return $this->container->get('session'); } - return $this->container->get('session'); + if ($this->container->has('session_factory')) { + return $this->container->get('session_factory')->createSession(); + } + + return null; } } diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index 336a77c8f6..aa0229a9eb 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -19,6 +19,7 @@ use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Session\Session; +use Symfony\Component\HttpFoundation\Session\SessionFactory; use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage; use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector; use Symfony\Component\HttpKernel\Event\FinishRequestEvent; @@ -71,6 +72,28 @@ public function testSessionIsSet() $this->assertSame($session, $request->getSession()); } + public function testSessionUsesFactory() + { + $session = $this->createMock(Session::class); + $sessionFactory = $this->createMock(SessionFactory::class); + $sessionFactory->expects($this->once())->method('createSession')->willReturn($session); + + $container = new Container(); + $container->set('session_factory', $sessionFactory); + + $request = new Request(); + $listener = new SessionListener($container); + + $event = $this->createMock(RequestEvent::class); + $event->expects($this->exactly(2))->method('isMainRequest')->willReturn(true); + $event->expects($this->once())->method('getRequest')->willReturn($request); + + $listener->onKernelRequest($event); + + $this->assertTrue($request->hasSession()); + $this->assertSame($session, $request->getSession()); + } + public function testResponseIsPrivateIfSessionStarted() { $session = $this->createMock(Session::class); From 3879d23e8166d9df60528460dbcea77e1cff330b Mon Sep 17 00:00:00 2001 From: "Antonin \"0x346e3730\" CLAUZIER" Date: Wed, 26 May 2021 12:28:46 +0200 Subject: [PATCH 143/396] [HttpKernel] Fixes tests for PHP7.4+ --- HttpCache/Store.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HttpCache/Store.php b/HttpCache/Store.php index 3b69289f17..7dfdc491dd 100644 --- a/HttpCache/Store.php +++ b/HttpCache/Store.php @@ -349,7 +349,7 @@ private function load(string $key): ?string { $path = $this->getPath($key); - return file_exists($path) && false !== ($contents = file_get_contents($path)) ? $contents : null; + return file_exists($path) && false !== ($contents = @file_get_contents($path)) ? $contents : null; } /** From a0d8fd719d31477e30e6c849209b8962ade28d51 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 26 May 2021 13:20:16 +0200 Subject: [PATCH 144/396] Fix markdown --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0136784a72..18d15f5ad8 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ enough to create full-stack frameworks, micro-frameworks or advanced CMS systems Resources --------- - * [Documentation](https://symfony.com/doc/current/components/http_kernel.html) - * [Contributing](https://symfony.com/doc/current/contributing/index.html) - * [Report issues](https://github.com/symfony/symfony/issues) and - [send Pull Requests](https://github.com/symfony/symfony/pulls) - in the [main Symfony repository](https://github.com/symfony/symfony) + * [Documentation](https://symfony.com/doc/current/components/http_kernel.html) + * [Contributing](https://symfony.com/doc/current/contributing/index.html) + * [Report issues](https://github.com/symfony/symfony/issues) and + [send Pull Requests](https://github.com/symfony/symfony/pulls) + in the [main Symfony repository](https://github.com/symfony/symfony) From f8e8f5391b6909e2f0ba8c12220ab7af3050eb4f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 31 May 2021 12:44:03 +0200 Subject: [PATCH 145/396] Update VERSION for 5.3.0 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 27f30ad38a..44bdd8d339 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.0-DEV'; + public const VERSION = '5.3.0'; public const VERSION_ID = 50300; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '05/2021'; public const END_OF_LIFE = '01/2022'; From 0996d531074e0fb3f60b2af0a0d758c03fc47396 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 31 May 2021 13:17:20 +0200 Subject: [PATCH 146/396] Bump Symfony version to 5.3.1 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 44bdd8d339..80a446d745 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.0'; - public const VERSION_ID = 50300; + public const VERSION = '5.3.1-DEV'; + public const VERSION_ID = 50301; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; - public const RELEASE_VERSION = 0; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 1; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '05/2021'; public const END_OF_LIFE = '01/2022'; From 1223525cf0b4d47523799b6dbbd978c3e2570e89 Mon Sep 17 00:00:00 2001 From: jmsche Date: Mon, 31 May 2021 13:34:51 +0200 Subject: [PATCH 147/396] Fix Symfony 5.3 end of maintenance date --- Kernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Kernel.php b/Kernel.php index 80a446d745..85842a80df 100644 --- a/Kernel.php +++ b/Kernel.php @@ -82,7 +82,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl public const RELEASE_VERSION = 1; public const EXTRA_VERSION = 'DEV'; - public const END_OF_MAINTENANCE = '05/2021'; + public const END_OF_MAINTENANCE = '01/2022'; public const END_OF_LIFE = '01/2022'; public function __construct(string $environment, bool $debug) From 0580c8270130edccce6e328e741fe0eca10df502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Sat, 29 May 2021 13:17:28 +0200 Subject: [PATCH 148/396] Provide migration path for TestSessionListener --- CHANGELOG.md | 5 +++++ EventListener/AbstractTestSessionListener.php | 8 ++++++-- EventListener/TestSessionListener.php | 9 +++++---- Tests/EventListener/TestSessionListenerTest.php | 3 ++- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a5f67ba1d..ed36ac8cbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +5.4 +--- + + * Deprecate `AbstractTestSessionListener::getSession` inject a session in the request instead + 5.3 --- diff --git a/EventListener/AbstractTestSessionListener.php b/EventListener/AbstractTestSessionListener.php index 0c88187d1e..8fa667ced3 100644 --- a/EventListener/AbstractTestSessionListener.php +++ b/EventListener/AbstractTestSessionListener.php @@ -46,7 +46,9 @@ public function onKernelRequest(RequestEvent $event) } // bootstrap the session - if (!$session = $this->getSession()) { + if ($event->getRequest()->hasSession()) { + $session = $event->getRequest()->getSession(); + } elseif (!$session = $this->getSession()) { return; } @@ -100,7 +102,7 @@ public function onKernelResponse(ResponseEvent $event) public static function getSubscribedEvents(): array { return [ - KernelEvents::REQUEST => ['onKernelRequest', 192], + KernelEvents::REQUEST => ['onKernelRequest', 127], // AFTER SessionListener KernelEvents::RESPONSE => ['onKernelResponse', -128], ]; } @@ -108,6 +110,8 @@ public static function getSubscribedEvents(): array /** * Gets the session object. * + * @deprecated since Symfony 5.4, will be removed in 6.0. + * * @return SessionInterface|null A SessionInterface instance or null if no session is available */ abstract protected function getSession(); diff --git a/EventListener/TestSessionListener.php b/EventListener/TestSessionListener.php index 6d4b36ace3..ceac3dde81 100644 --- a/EventListener/TestSessionListener.php +++ b/EventListener/TestSessionListener.php @@ -31,16 +31,17 @@ public function __construct(ContainerInterface $container, array $sessionOptions parent::__construct($sessionOptions); } + /** + * @deprecated since Symfony 5.4, will be removed in 6.0. + */ protected function getSession(): ?SessionInterface { + trigger_deprecation('symfony/http-kernel', '5.4', '"%s" is deprecated and will be removed in 6.0, inject a session in the request instead.', __METHOD__); + if ($this->container->has('session')) { return $this->container->get('session'); } - if ($this->container->has('session_factory')) { - return $this->container->get('session_factory')->createSession(); - } - return null; } } diff --git a/Tests/EventListener/TestSessionListenerTest.php b/Tests/EventListener/TestSessionListenerTest.php index 016f7901c6..abb13bcb10 100644 --- a/Tests/EventListener/TestSessionListenerTest.php +++ b/Tests/EventListener/TestSessionListenerTest.php @@ -19,7 +19,6 @@ use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\EventListener\AbstractTestSessionListener; -use Symfony\Component\HttpKernel\EventListener\SessionListener; use Symfony\Component\HttpKernel\EventListener\TestSessionListener; use Symfony\Component\HttpKernel\HttpKernelInterface; @@ -99,6 +98,7 @@ public function testEmptySessionWithNewSessionIdDoesSendCookie() $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']); + $request->setSession($this->getSession()); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $this->listener->onKernelRequest($event); @@ -118,6 +118,7 @@ public function testSessionWithNewSessionIdAndNewCookieDoesNotSendAnotherCookie( $kernel = $this->createMock(HttpKernelInterface::class); $request = Request::create('/', 'GET', [], ['MOCKSESSID' => '123']); + $request->setSession($this->getSession()); $event = new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST); $this->listener->onKernelRequest($event); From 3795165596fe81a52296b78c9aae938d434069cc Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 1 Jun 2021 09:12:08 +0200 Subject: [PATCH 149/396] Update VERSION for 4.4.25 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 885337bf37..82ee8b26b9 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.25-DEV'; + public const VERSION = '4.4.25'; public const VERSION_ID = 40425; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; public const RELEASE_VERSION = 25; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From f7a40b1fa20f356cd82920f5810765903075ade8 Mon Sep 17 00:00:00 2001 From: Stefan Gehrig Date: Tue, 1 Jun 2021 10:32:34 +0200 Subject: [PATCH 150/396] fixes issue #41478 by resetting the $attributes array per controller argument also adds test to ensure correct metadata in cases where controller arguments without attributes follow arguments with attributes --- ControllerMetadata/ArgumentMetadataFactory.php | 3 ++- .../ArgumentMetadataFactoryTest.php | 12 ++++++++++++ Tests/Fixtures/Controller/AttributeController.php | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ControllerMetadata/ArgumentMetadataFactory.php b/ControllerMetadata/ArgumentMetadataFactory.php index a2feb05c10..0af1d90715 100644 --- a/ControllerMetadata/ArgumentMetadataFactory.php +++ b/ControllerMetadata/ArgumentMetadataFactory.php @@ -34,6 +34,7 @@ public function createArgumentMetadata($controller): array } foreach ($reflection->getParameters() as $param) { + $attributes = []; if (\PHP_VERSION_ID >= 80000) { foreach ($param->getAttributes() as $reflectionAttribute) { if (class_exists($reflectionAttribute->getName())) { @@ -42,7 +43,7 @@ public function createArgumentMetadata($controller): array } } - $arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull(), $attributes ?? []); + $arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $param->isVariadic(), $param->isDefaultValueAvailable(), $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, $param->allowsNull(), $attributes); } return $arguments; diff --git a/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php b/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php index d952e424c5..a7e8f35750 100644 --- a/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php +++ b/Tests/ControllerMetadata/ArgumentMetadataFactoryTest.php @@ -140,6 +140,18 @@ public function testMultipleAttributes() $this->assertCount(1, $this->factory->createArgumentMetadata([new AttributeController(), 'multiAttributeArg'])[0]->getAttributes()); } + /** + * @requires PHP 8 + */ + public function testIssue41478() + { + $arguments = $this->factory->createArgumentMetadata([new AttributeController(), 'issue41478']); + $this->assertEquals([ + new ArgumentMetadata('baz', 'string', false, false, null, false, [new Foo('bar')]), + new ArgumentMetadata('bat', 'string', false, false, null, false, []), + ], $arguments); + } + private function signature1(self $foo, array $bar, callable $baz) { } diff --git a/Tests/Fixtures/Controller/AttributeController.php b/Tests/Fixtures/Controller/AttributeController.php index d6e0cde58d..915b5e41d4 100644 --- a/Tests/Fixtures/Controller/AttributeController.php +++ b/Tests/Fixtures/Controller/AttributeController.php @@ -20,4 +20,7 @@ public function action(#[Foo('bar')] string $baz) { public function multiAttributeArg(#[Foo('bar'), Undefined('bar')] string $baz) { } + + public function issue41478(#[Foo('bar')] string $baz, string $bat) { + } } From 2eb81b6cd1f71e4a997de7f6d7b8d8d654f14b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Tue, 1 Jun 2021 10:53:00 +0200 Subject: [PATCH 151/396] Fix sessionListener when factory is injected without session --- EventListener/SessionListener.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EventListener/SessionListener.php b/EventListener/SessionListener.php index e396aa5035..f41939bade 100644 --- a/EventListener/SessionListener.php +++ b/EventListener/SessionListener.php @@ -38,7 +38,7 @@ public function onKernelRequest(RequestEvent $event) { parent::onKernelRequest($event); - if (!$event->isMainRequest() || !$this->container->has('session')) { + if (!$event->isMainRequest() || (!$this->container->has('session') && !$this->container->has('session_factory'))) { return; } From a473739508ceda914f51988fd2fce51acbe6a836 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 1 Jun 2021 11:02:47 +0200 Subject: [PATCH 152/396] Bump Symfony version to 4.4.26 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 82ee8b26b9..819c60538f 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.25'; - public const VERSION_ID = 40425; + public const VERSION = '4.4.26-DEV'; + public const VERSION_ID = 40426; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; - public const RELEASE_VERSION = 25; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 26; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From 91aaf791281a3f3f801a9257b27be5f9dfdb3dcf Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 1 Jun 2021 11:28:31 +0200 Subject: [PATCH 153/396] Update VERSION for 5.2.10 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index d3a79cd61a..a9fc016f23 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.10-DEV'; + public const VERSION = '5.2.10'; public const VERSION_ID = 50210; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; public const RELEASE_VERSION = 10; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 3a8d7daa10aa35d0e9ab95e9514ccd11fb850109 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 1 Jun 2021 12:21:53 +0200 Subject: [PATCH 154/396] Bump Symfony version to 5.2.11 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index a9fc016f23..3cc096d7c5 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.10'; - public const VERSION_ID = 50210; + public const VERSION = '5.2.11-DEV'; + public const VERSION_ID = 50211; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; - public const RELEASE_VERSION = 10; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 11; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 74eb022e3bac36b3d3a897951a98759f2b32b864 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 2 Jun 2021 12:07:12 +0200 Subject: [PATCH 155/396] Update VERSION for 5.3.1 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 85842a80df..a50521454f 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.1-DEV'; + public const VERSION = '5.3.1'; public const VERSION_ID = 50301; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 1; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '01/2022'; public const END_OF_LIFE = '01/2022'; From 4d0affc75a92708deb2c34105b6bd6fe38ce9139 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 2 Jun 2021 12:21:08 +0200 Subject: [PATCH 156/396] Bump Symfony version to 5.3.2 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index a50521454f..5cf810d862 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.1'; - public const VERSION_ID = 50301; + public const VERSION = '5.3.2-DEV'; + public const VERSION_ID = 50302; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; - public const RELEASE_VERSION = 1; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 2; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '01/2022'; public const END_OF_LIFE = '01/2022'; From e7021165d9dbfb4051296b8de827e92c8a7b5c87 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 17 Jun 2021 16:18:27 +0200 Subject: [PATCH 157/396] Update VERSION for 5.3.2 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 5cf810d862..1793992a9f 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.2-DEV'; + public const VERSION = '5.3.2'; public const VERSION_ID = 50302; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 2; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '01/2022'; public const END_OF_LIFE = '01/2022'; From c900b06675180fd7f54f31501e649ff69ec572f2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 17 Jun 2021 16:21:12 +0200 Subject: [PATCH 158/396] Bump Symfony version to 5.3.3 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 1793992a9f..5aaee87e04 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.2'; - public const VERSION_ID = 50302; + public const VERSION = '5.3.3-DEV'; + public const VERSION_ID = 50303; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; - public const RELEASE_VERSION = 2; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 3; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '01/2022'; public const END_OF_LIFE = '01/2022'; From d5fb8335ff377b944d2736b355130917fe5e1eaa Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 10 Jun 2021 20:42:23 +0000 Subject: [PATCH 159/396] [HttpKernel] [HttpCache] Keep s-maxage=0 from ESI sub-responses --- HttpCache/ResponseCacheStrategy.php | 6 ++++-- Tests/HttpCache/ResponseCacheStrategyTest.php | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/HttpCache/ResponseCacheStrategy.php b/HttpCache/ResponseCacheStrategy.php index 1f09946846..47bbbb7431 100644 --- a/HttpCache/ResponseCacheStrategy.php +++ b/HttpCache/ResponseCacheStrategy.php @@ -81,8 +81,10 @@ public function add(Response $response) return; } - $this->storeRelativeAgeDirective('max-age', $response->headers->getCacheControlDirective('max-age'), $age); - $this->storeRelativeAgeDirective('s-maxage', $response->headers->getCacheControlDirective('s-maxage') ?: $response->headers->getCacheControlDirective('max-age'), $age); + $maxAge = $response->headers->hasCacheControlDirective('max-age') ? (int) $response->headers->getCacheControlDirective('max-age') : null; + $this->storeRelativeAgeDirective('max-age', $maxAge, $age); + $sharedMaxAge = $response->headers->hasCacheControlDirective('s-maxage') ? (int) $response->headers->getCacheControlDirective('s-maxage') : $maxAge; + $this->storeRelativeAgeDirective('s-maxage', $sharedMaxAge, $age); $expires = $response->getExpires(); $expires = null !== $expires ? (int) $expires->format('U') - (int) $response->getDate()->format('U') : null; diff --git a/Tests/HttpCache/ResponseCacheStrategyTest.php b/Tests/HttpCache/ResponseCacheStrategyTest.php index 62179ba154..4875870eef 100644 --- a/Tests/HttpCache/ResponseCacheStrategyTest.php +++ b/Tests/HttpCache/ResponseCacheStrategyTest.php @@ -377,6 +377,22 @@ public function cacheControlMergingProvider() ], ]; + yield 's-maxage may be set to 0' => [ + ['public' => true, 's-maxage' => '0', 'max-age' => null], + ['public' => true, 's-maxage' => '0'], + [ + ['public' => true, 's-maxage' => '60'], + ], + ]; + + yield 's-maxage may be set to 0, and works independently from maxage' => [ + ['public' => true, 's-maxage' => '0', 'max-age' => '30'], + ['public' => true, 's-maxage' => '0', 'max-age' => '30'], + [ + ['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], From cb810f450f1ffff8819704260dc416dcbc51afae Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Fri, 11 Jun 2021 05:58:59 +0000 Subject: [PATCH 160/396] Public responses without lifetime should not remove lifetime for the resulting response --- HttpCache/ResponseCacheStrategy.php | 29 +++++++++++++++---- Tests/HttpCache/ResponseCacheStrategyTest.php | 26 ++++++++++++++++- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/HttpCache/ResponseCacheStrategy.php b/HttpCache/ResponseCacheStrategy.php index 47bbbb7431..17a7e87fe9 100644 --- a/HttpCache/ResponseCacheStrategy.php +++ b/HttpCache/ResponseCacheStrategy.php @@ -81,14 +81,15 @@ public function add(Response $response) return; } + $isHeuristicallyCacheable = $response->headers->hasCacheControlDirective('public'); $maxAge = $response->headers->hasCacheControlDirective('max-age') ? (int) $response->headers->getCacheControlDirective('max-age') : null; - $this->storeRelativeAgeDirective('max-age', $maxAge, $age); + $this->storeRelativeAgeDirective('max-age', $maxAge, $age, $isHeuristicallyCacheable); $sharedMaxAge = $response->headers->hasCacheControlDirective('s-maxage') ? (int) $response->headers->getCacheControlDirective('s-maxage') : $maxAge; - $this->storeRelativeAgeDirective('s-maxage', $sharedMaxAge, $age); + $this->storeRelativeAgeDirective('s-maxage', $sharedMaxAge, $age, $isHeuristicallyCacheable); $expires = $response->getExpires(); $expires = null !== $expires ? (int) $expires->format('U') - (int) $response->getDate()->format('U') : null; - $this->storeRelativeAgeDirective('expires', $expires >= 0 ? $expires : null, 0); + $this->storeRelativeAgeDirective('expires', $expires >= 0 ? $expires : null, 0, $isHeuristicallyCacheable); } /** @@ -199,11 +200,29 @@ private function willMakeFinalResponseUncacheable(Response $response): bool * we have to subtract the age so that the value is normalized for an age of 0. * * If the value is lower than the currently stored value, we update the value, to keep a rolling - * minimal value of each instruction. If the value is NULL, the directive will not be set on the final response. + * minimal value of each instruction. + * + * If the value is NULL and the isHeuristicallyCacheable parameter is false, the directive will + * not be set on the final response. In this case, not all responses had the directive set and no + * value can be found that satisfies the requirements of all responses. The directive will be dropped + * from the final response. + * + * If the isHeuristicallyCacheable parameter is true, however, the current response has been marked + * as cacheable in a public (shared) cache, but did not provide an explicit lifetime that would serve + * as an upper bound. In this case, we can proceed and possibly keep the directive on the final response. */ - private function storeRelativeAgeDirective(string $directive, ?int $value, int $age) + private function storeRelativeAgeDirective(string $directive, ?int $value, int $age, bool $isHeuristicallyCacheable) { if (null === $value) { + if ($isHeuristicallyCacheable) { + /* + * See https://datatracker.ietf.org/doc/html/rfc7234#section-4.2.2 + * This particular response does not require maximum lifetime; heuristics might be applied. + * Other responses, however, might have more stringent requirements on maximum lifetime. + * So, return early here so that the final response can have the more limiting value set. + */ + return; + } $this->ageDirectives[$directive] = false; } diff --git a/Tests/HttpCache/ResponseCacheStrategyTest.php b/Tests/HttpCache/ResponseCacheStrategyTest.php index 4875870eef..4d56b24285 100644 --- a/Tests/HttpCache/ResponseCacheStrategyTest.php +++ b/Tests/HttpCache/ResponseCacheStrategyTest.php @@ -370,7 +370,7 @@ public function cacheControlMergingProvider() ]; yield 'merge max-age and s-maxage' => [ - ['public' => true, 's-maxage' => '60', 'max-age' => null], + ['public' => true, 'max-age' => '60'], ['public' => true, 's-maxage' => 3600], [ ['public' => true, 'max-age' => 60], @@ -393,6 +393,30 @@ public function cacheControlMergingProvider() ], ]; + yield 'public subresponse without lifetime does not remove lifetime for main response' => [ + ['public' => true, 's-maxage' => '30', 'max-age' => null], + ['public' => true, 's-maxage' => '30'], + [ + ['public' => true], + ], + ]; + + yield 'lifetime for subresponse is kept when main response has no lifetime' => [ + ['public' => true, 'max-age' => '30'], + ['public' => true], + [ + ['public' => true, 'max-age' => '30'], + ], + ]; + + yield 's-maxage on the subresponse implies public, so the result is public as well' => [ + ['public' => true, 'max-age' => '10', 's-maxage' => null], + ['public' => true, 'max-age' => '10'], + [ + ['max-age' => '30', 's-maxage' => '20'], + ], + ]; + yield 'result is private when combining private responses' => [ ['no-cache' => false, 'must-revalidate' => false, 'private' => true], ['s-maxage' => 60, 'private' => true], From e08b2fb8a6eedd81c70522e514bad9b2c1fff881 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 30 Jun 2021 10:18:06 +0200 Subject: [PATCH 161/396] Update VERSION for 4.4.26 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 819c60538f..1275f12e7a 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.26-DEV'; + public const VERSION = '4.4.26'; public const VERSION_ID = 40426; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; public const RELEASE_VERSION = 26; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From 5df8755930ac683aedca27fe3bef25ccc37669af Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 30 Jun 2021 10:22:49 +0200 Subject: [PATCH 162/396] Bump Symfony version to 4.4.27 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 1275f12e7a..1c46d1cbb5 100644 --- a/Kernel.php +++ b/Kernel.php @@ -76,12 +76,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '4.4.26'; - public const VERSION_ID = 40426; + public const VERSION = '4.4.27-DEV'; + public const VERSION_ID = 40427; public const MAJOR_VERSION = 4; public const MINOR_VERSION = 4; - public const RELEASE_VERSION = 26; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 27; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '11/2022'; public const END_OF_LIFE = '11/2023'; From c141ca1c27800ef80ce5d7b8fe6409848d0b77b0 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 30 Jun 2021 10:23:28 +0200 Subject: [PATCH 163/396] Update VERSION for 5.2.11 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 3cc096d7c5..49d16df2c2 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.11-DEV'; + public const VERSION = '5.2.11'; public const VERSION_ID = 50211; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; public const RELEASE_VERSION = 11; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 7e6d17814e6897de4c940d3772a602f2d723754f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 30 Jun 2021 10:27:13 +0200 Subject: [PATCH 164/396] Bump Symfony version to 5.2.12 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 49d16df2c2..45b8c98629 100644 --- a/Kernel.php +++ b/Kernel.php @@ -74,12 +74,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.2.11'; - public const VERSION_ID = 50211; + public const VERSION = '5.2.12-DEV'; + public const VERSION_ID = 50212; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 2; - public const RELEASE_VERSION = 11; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 12; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '07/2021'; public const END_OF_LIFE = '07/2021'; From 90ad9f4b21ddcb8ebe9faadfcca54929ad23f9f8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 30 Jun 2021 10:27:49 +0200 Subject: [PATCH 165/396] Update VERSION for 5.3.3 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 5aaee87e04..d251c23ec2 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.3-DEV'; + public const VERSION = '5.3.3'; public const VERSION_ID = 50303; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; public const RELEASE_VERSION = 3; - public const EXTRA_VERSION = 'DEV'; + public const EXTRA_VERSION = ''; public const END_OF_MAINTENANCE = '01/2022'; public const END_OF_LIFE = '01/2022'; From 8930a399a23d83e3b0cafcdc3e254130d173a44a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 30 Jun 2021 10:36:51 +0200 Subject: [PATCH 166/396] Bump Symfony version to 5.3.4 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index d251c23ec2..236879130e 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl private static $freshCache = []; - public const VERSION = '5.3.3'; - public const VERSION_ID = 50303; + public const VERSION = '5.3.4-DEV'; + public const VERSION_ID = 50304; public const MAJOR_VERSION = 5; public const MINOR_VERSION = 3; - public const RELEASE_VERSION = 3; - public const EXTRA_VERSION = ''; + public const RELEASE_VERSION = 4; + public const EXTRA_VERSION = 'DEV'; public const END_OF_MAINTENANCE = '01/2022'; public const END_OF_LIFE = '01/2022'; From 114066cc261e32d85f13a39619040a94124da1ca Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 30 Jun 2021 15:15:49 +0200 Subject: [PATCH 167/396] CS fix --- ControllerMetadata/ArgumentMetadata.php | 2 +- DataCollector/RequestDataCollector.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ControllerMetadata/ArgumentMetadata.php b/ControllerMetadata/ArgumentMetadata.php index 3454ff6e49..526e1306d8 100644 --- a/ControllerMetadata/ArgumentMetadata.php +++ b/ControllerMetadata/ArgumentMetadata.php @@ -28,7 +28,7 @@ class ArgumentMetadata private $isNullable; private $attribute; - public function __construct(string $name, ?string $type, bool $isVariadic, bool $hasDefaultValue, $defaultValue, bool $isNullable = false, ?ArgumentInterface $attribute = null) + public function __construct(string $name, ?string $type, bool $isVariadic, bool $hasDefaultValue, $defaultValue, bool $isNullable = false, ArgumentInterface $attribute = null) { $this->name = $name; $this->type = $type; diff --git a/DataCollector/RequestDataCollector.php b/DataCollector/RequestDataCollector.php index ad6fe2efe4..81f71214bd 100644 --- a/DataCollector/RequestDataCollector.php +++ b/DataCollector/RequestDataCollector.php @@ -34,7 +34,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter private $sessionUsages = []; private $requestStack; - public function __construct(?RequestStack $requestStack = null) + public function __construct(RequestStack $requestStack = null) { $this->controllers = new \SplObjectStorage(); $this->requestStack = $requestStack; From a8486d0d6defb5270f60c8b47c9c669484665acc Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 30 Jun 2021 18:11:29 +0200 Subject: [PATCH 168/396] cs fix --- HttpKernelBrowser.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/HttpKernelBrowser.php b/HttpKernelBrowser.php index 554585fb9c..95852adc00 100644 --- a/HttpKernelBrowser.php +++ b/HttpKernelBrowser.php @@ -54,7 +54,9 @@ public function catchExceptions(bool $catchExceptions) } /** - * Makes a request. + * {@inheritdoc} + * + * @param Request $request * * @return Response A Response instance */ @@ -70,7 +72,9 @@ protected function doRequest($request) } /** - * Returns the script to execute when the request must be insulated. + * {@inheritdoc} + * + * @param Request $request * * @return string */ @@ -124,7 +128,7 @@ protected function getHandleScript() } /** - * Converts the BrowserKit request to a HttpKernel request. + * {@inheritdoc} * * @return Request A Request instance */ @@ -186,7 +190,9 @@ protected function filterFiles(array $files) } /** - * Converts the HttpKernel response to a BrowserKit response. + * {@inheritdoc} + * + * @param Request $request * * @return DomResponse A DomResponse instance */ From 53a71ecadc729d65ea4375b3880743e6af2cc9d4 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 30 Jun 2021 18:07:05 +0200 Subject: [PATCH 169/396] [HttpKernel][FrameworkBundle] bump browser-kit --- HttpKernelBrowser.php | 6 +++--- composer.json | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/HttpKernelBrowser.php b/HttpKernelBrowser.php index 501581809d..2b1e3ee6d9 100644 --- a/HttpKernelBrowser.php +++ b/HttpKernelBrowser.php @@ -60,7 +60,7 @@ public function catchExceptions(bool $catchExceptions) * * @return Response A Response instance */ - protected function doRequest($request) + protected function doRequest(object $request) { $response = $this->kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, $this->catchExceptions); @@ -78,7 +78,7 @@ protected function doRequest($request) * * @return string */ - protected function getScript($request) + protected function getScript(object $request) { $kernel = var_export(serialize($this->kernel), true); $request = var_export(serialize($request), true); @@ -196,7 +196,7 @@ protected function filterFiles(array $files) * * @return DomResponse A DomResponse instance */ - protected function filterResponse($response) + protected function filterResponse(object $response) { // this is needed to support StreamedResponse ob_start(); diff --git a/composer.json b/composer.json index 660c98fdfc..3d13f723b6 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "psr/log": "~1.0" }, "require-dev": { - "symfony/browser-kit": "^4.4|^5.0|^6.0", + "symfony/browser-kit": "^5.4|^6.0", "symfony/config": "^5.0|^6.0", "symfony/console": "^4.4|^5.0|^6.0", "symfony/css-selector": "^4.4|^5.0|^6.0", @@ -48,7 +48,7 @@ "psr/log-implementation": "1.0" }, "conflict": { - "symfony/browser-kit": "<4.4", + "symfony/browser-kit": "<5.4", "symfony/cache": "<5.0", "symfony/config": "<5.0", "symfony/console": "<4.4", From c59bb664de88a3fbe5bef1fe7bd7f3225498783f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 2 Jul 2021 16:28:33 +0200 Subject: [PATCH 170/396] Backport type fixes --- ControllerMetadata/ArgumentMetadataFactoryInterface.php | 2 +- DataCollector/LoggerDataCollector.php | 2 -- DataCollector/RequestDataCollector.php | 2 +- Debug/FileLinkFormatter.php | 2 +- 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ControllerMetadata/ArgumentMetadataFactoryInterface.php b/ControllerMetadata/ArgumentMetadataFactoryInterface.php index 6ea179d783..a34befc22d 100644 --- a/ControllerMetadata/ArgumentMetadataFactoryInterface.php +++ b/ControllerMetadata/ArgumentMetadataFactoryInterface.php @@ -19,7 +19,7 @@ interface ArgumentMetadataFactoryInterface { /** - * @param mixed $controller The controller to resolve the arguments for + * @param string|object|array $controller The controller to resolve the arguments for * * @return ArgumentMetadata[] */ diff --git a/DataCollector/LoggerDataCollector.php b/DataCollector/LoggerDataCollector.php index 2797a347c8..0e25f8960f 100644 --- a/DataCollector/LoggerDataCollector.php +++ b/DataCollector/LoggerDataCollector.php @@ -18,8 +18,6 @@ use Symfony\Component\HttpKernel\Log\DebugLoggerInterface; /** - * LogDataCollector. - * * @author Fabien Potencier * * @final since Symfony 4.4 diff --git a/DataCollector/RequestDataCollector.php b/DataCollector/RequestDataCollector.php index 0e3c13ba06..f40c2fb9f6 100644 --- a/DataCollector/RequestDataCollector.php +++ b/DataCollector/RequestDataCollector.php @@ -388,7 +388,7 @@ public function getName() /** * Parse a controller. * - * @param mixed $controller The controller to parse + * @param string|object|array|null $controller The controller to parse * * @return array|string An array of controller data or a simple string */ diff --git a/Debug/FileLinkFormatter.php b/Debug/FileLinkFormatter.php index 6d7c1e942e..79755a8ad7 100644 --- a/Debug/FileLinkFormatter.php +++ b/Debug/FileLinkFormatter.php @@ -32,7 +32,7 @@ class FileLinkFormatter /** * @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand */ - public function __construct($fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null) + public function __construct(string $fileLinkFormat = null, RequestStack $requestStack = null, string $baseDir = null, $urlFormat = null) { $fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format'); if ($fileLinkFormat && !\is_array($fileLinkFormat)) { From 09cdfd25624e8b88b59abe61ad602949dab3d8ac Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 2 Jul 2021 15:24:31 +0200 Subject: [PATCH 171/396] Backport type fixes --- DataCollector/DumpDataCollector.php | 2 +- DataCollector/LoggerDataCollector.php | 2 +- DataCollector/RequestDataCollector.php | 4 ++-- Fragment/InlineFragmentRenderer.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/DataCollector/DumpDataCollector.php b/DataCollector/DumpDataCollector.php index d81919919f..ca81714771 100644 --- a/DataCollector/DumpDataCollector.php +++ b/DataCollector/DumpDataCollector.php @@ -192,7 +192,7 @@ public function getDumpsCount(): int return $this->dataCount; } - public function getDumps($format, $maxDepthLimit = -1, $maxItemsPerDepth = -1): array + public function getDumps(string $format, int $maxDepthLimit = -1, int $maxItemsPerDepth = -1): array { $data = fopen('php://memory', 'r+'); diff --git a/DataCollector/LoggerDataCollector.php b/DataCollector/LoggerDataCollector.php index 3d781fa36a..17449b411d 100644 --- a/DataCollector/LoggerDataCollector.php +++ b/DataCollector/LoggerDataCollector.php @@ -29,7 +29,7 @@ class LoggerDataCollector extends DataCollector implements LateDataCollectorInte private $currentRequest; private $requestStack; - public function __construct($logger = null, string $containerPathPrefix = null, RequestStack $requestStack = null) + public function __construct(object $logger = null, string $containerPathPrefix = null, RequestStack $requestStack = null) { if (null !== $logger && $logger instanceof DebugLoggerInterface) { $this->logger = $logger; diff --git a/DataCollector/RequestDataCollector.php b/DataCollector/RequestDataCollector.php index 6f27f379af..425715669e 100644 --- a/DataCollector/RequestDataCollector.php +++ b/DataCollector/RequestDataCollector.php @@ -214,12 +214,12 @@ public function getRequestHeaders() return new ParameterBag($this->data['request_headers']->getValue()); } - public function getRequestServer($raw = false) + public function getRequestServer(bool $raw = false) { return new ParameterBag($this->data['request_server']->getValue($raw)); } - public function getRequestCookies($raw = false) + public function getRequestCookies(bool $raw = false) { return new ParameterBag($this->data['request_cookies']->getValue($raw)); } diff --git a/Fragment/InlineFragmentRenderer.php b/Fragment/InlineFragmentRenderer.php index 3bbdbd3ce8..ea45fdcb3f 100644 --- a/Fragment/InlineFragmentRenderer.php +++ b/Fragment/InlineFragmentRenderer.php @@ -105,7 +105,7 @@ public function render($uri, Request $request, array $options = []) } } - protected function createSubRequest($uri, Request $request) + protected function createSubRequest(string $uri, Request $request) { $cookies = $request->cookies->all(); $server = $request->server->all(); From 09878fd98ab7a5ab85e8ce32f84b46c90723fdcd Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Thu, 8 Jul 2021 13:32:35 +0200 Subject: [PATCH 172/396] recover from failed deserializations --- HttpCache/Store.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HttpCache/Store.php b/HttpCache/Store.php index 7dfdc491dd..eeb7a6ef94 100644 --- a/HttpCache/Store.php +++ b/HttpCache/Store.php @@ -298,7 +298,7 @@ private function getMetadata(string $key): array return []; } - return unserialize($entries); + return unserialize($entries) ?: []; } /** From 6c5b78e56d50a9992bfc9b4a46f42399d5d8d911 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 9 Jul 2021 12:48:54 +0200 Subject: [PATCH 173/396] do not mock event classes --- .../EventListener/AddRequestFormatsListenerTest.php | 13 ++----------- Tests/EventListener/SaveSessionListenerTest.php | 12 ++++++++---- Tests/EventListener/SessionListenerTest.php | 4 +--- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Tests/EventListener/AddRequestFormatsListenerTest.php b/Tests/EventListener/AddRequestFormatsListenerTest.php index fab9a8a38f..9b3c1a2e58 100644 --- a/Tests/EventListener/AddRequestFormatsListenerTest.php +++ b/Tests/EventListener/AddRequestFormatsListenerTest.php @@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\EventListener\AddRequestFormatsListener; +use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; /** @@ -54,7 +55,7 @@ public function testRegisteredEvent() public function testSetAdditionalFormats() { $request = $this->createMock(Request::class); - $event = $this->getRequestEventMock($request); + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST); $request->expects($this->once()) ->method('setFormat') @@ -62,14 +63,4 @@ public function testSetAdditionalFormats() $this->listener->onKernelRequest($event); } - - protected function getRequestEventMock(Request $request) - { - $event = $this->createMock(RequestEvent::class); - $event->expects($this->any()) - ->method('getRequest') - ->willReturn($request); - - return $event; - } } diff --git a/Tests/EventListener/SaveSessionListenerTest.php b/Tests/EventListener/SaveSessionListenerTest.php index f79b73c5fe..bbb76771e0 100644 --- a/Tests/EventListener/SaveSessionListenerTest.php +++ b/Tests/EventListener/SaveSessionListenerTest.php @@ -26,13 +26,17 @@ class SaveSessionListenerTest extends TestCase { public function testOnlyTriggeredOnMasterRequest() { + $session = $this->createMock(SessionInterface::class); + $session->expects($this->never())->method('save'); + $session->expects($this->any())->method('isStarted')->willReturn(true); + + $request = new Request(); + $request->setSession($session); + $listener = new SaveSessionListener(); - $event = $this->createMock(ResponseEvent::class); - $event->expects($this->once())->method('isMasterRequest')->willReturn(false); - $event->expects($this->never())->method('getRequest'); // sub request - $listener->onKernelResponse($event); + $listener->onKernelResponse(new ResponseEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::SUB_REQUEST, new Response())); } public function testSessionSaved() diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index e0dba81683..d6ff42f926 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -58,9 +58,7 @@ public function testSessionIsSet() $request = new Request(); $listener = new SessionListener($container); - $event = $this->createMock(RequestEvent::class); - $event->expects($this->exactly(2))->method('isMasterRequest')->willReturn(true); - $event->expects($this->once())->method('getRequest')->willReturn($request); + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MASTER_REQUEST); $listener->onKernelRequest($event); From 9da2a51858fb685af52e39540b357e07d84a5320 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 9 Jul 2021 16:39:14 +0200 Subject: [PATCH 174/396] do not mock the Request class --- Tests/EventListener/DisallowRobotsIndexingListenerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/EventListener/DisallowRobotsIndexingListenerTest.php b/Tests/EventListener/DisallowRobotsIndexingListenerTest.php index 6534ebf4e2..4a05d65188 100644 --- a/Tests/EventListener/DisallowRobotsIndexingListenerTest.php +++ b/Tests/EventListener/DisallowRobotsIndexingListenerTest.php @@ -29,7 +29,7 @@ public function testInvoke(?string $expected, array $responseArgs) $response = new Response(...$responseArgs); $listener = new DisallowRobotsIndexingListener(); - $event = new ResponseEvent($this->createMock(HttpKernelInterface::class), $this->createMock(Request::class), KernelInterface::MASTER_REQUEST, $response); + $event = new ResponseEvent($this->createMock(HttpKernelInterface::class), new Request(), KernelInterface::MASTER_REQUEST, $response); $listener->onResponse($event); From 462b9693d3e4193cfa7e3d5d8fbc478d85f6a81c Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sat, 10 Jul 2021 11:25:37 +0200 Subject: [PATCH 175/396] do not mock event classes --- Tests/EventListener/SessionListenerTest.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index 0e95196f09..d9c272b0d9 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -82,9 +82,7 @@ public function testSessionUsesFactory() $request = new Request(); $listener = new SessionListener($container); - $event = $this->createMock(RequestEvent::class); - $event->expects($this->exactly(2))->method('isMainRequest')->willReturn(true); - $event->expects($this->once())->method('getRequest')->willReturn($request); + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $request, HttpKernelInterface::MAIN_REQUEST); $listener->onKernelRequest($event); From f96639df6757d7916fc214e9602b9c320f33effb Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 18 Jul 2021 16:04:40 +0200 Subject: [PATCH 176/396] Indicate compatibility with psr/log 2 and 3 Signed-off-by: Alexander M. Turek --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a2fa2a0eca..1563315ee6 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "symfony/polyfill-ctype": "^1.8", "symfony/polyfill-php73": "^1.9", "symfony/polyfill-php80": "^1.15", - "psr/log": "~1.0" + "psr/log": "^1|^2" }, "require-dev": { "symfony/browser-kit": "^4.3|^5.0", @@ -45,7 +45,7 @@ "twig/twig": "^1.43|^2.13|^3.0.4" }, "provide": { - "psr/log-implementation": "1.0" + "psr/log-implementation": "1.0|2.0" }, "conflict": { "symfony/browser-kit": "<4.3", From 0b693cf08befd4d6fbcc22218a1ee699cd0bc796 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sat, 17 Jul 2021 20:11:21 +0200 Subject: [PATCH 177/396] Simplify some code with null coalesce operator --- EventListener/DebugHandlersListener.php | 2 +- Profiler/Profile.php | 6 +----- Tests/KernelTest.php | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/EventListener/DebugHandlersListener.php b/EventListener/DebugHandlersListener.php index cfc277e330..5027bd1169 100644 --- a/EventListener/DebugHandlersListener.php +++ b/EventListener/DebugHandlersListener.php @@ -60,7 +60,7 @@ public function __construct(callable $exceptionHandler = null, LoggerInterface $ $this->exceptionHandler = $exceptionHandler; $this->logger = $logger; - $this->levels = null === $levels ? \E_ALL : $levels; + $this->levels = $levels ?? \E_ALL; $this->throwAt = \is_int($throwAt) ? $throwAt : (null === $throwAt ? null : ($throwAt ? \E_ALL : null)); $this->scream = $scream; $this->fileLinkFormat = $fileLinkFormat; diff --git a/Profiler/Profile.php b/Profiler/Profile.php index ac5b5044c1..88e82b4e2f 100644 --- a/Profiler/Profile.php +++ b/Profiler/Profile.php @@ -156,11 +156,7 @@ public function setUrl($url) */ public function getTime() { - if (null === $this->time) { - return 0; - } - - return $this->time; + return $this->time ?? 0; } /** diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index 63fb4973f6..ec57289dde 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -709,7 +709,7 @@ protected function getBundle($dir = null, $parent = null, $className = null, $bu $bundle ->expects($this->any()) ->method('getName') - ->willReturn(null === $bundleName ? \get_class($bundle) : $bundleName) + ->willReturn($bundleName ?? \get_class($bundle)) ; $bundle From 21336dbfa9f75bd187fc121a2f74f195980dde0a Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Sun, 4 Jul 2021 19:20:55 +0200 Subject: [PATCH 178/396] Leverage str_ends_with added the php80 polyfill to requirements when necessary --- DependencyInjection/AddAnnotatedClassesToCachePass.php | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DependencyInjection/AddAnnotatedClassesToCachePass.php b/DependencyInjection/AddAnnotatedClassesToCachePass.php index 5eb833b51d..17a5f7f02e 100644 --- a/DependencyInjection/AddAnnotatedClassesToCachePass.php +++ b/DependencyInjection/AddAnnotatedClassesToCachePass.php @@ -62,7 +62,7 @@ private function expandClasses(array $patterns, array $classes): array // Explicit classes declared in the patterns are returned directly foreach ($patterns as $key => $pattern) { - if ('\\' !== substr($pattern, -1) && false === strpos($pattern, '*')) { + if (!str_ends_with($pattern, '\\') && false === strpos($pattern, '*')) { unset($patterns[$key]); $expanded[] = ltrim($pattern, '\\'); } diff --git a/composer.json b/composer.json index 1563315ee6..d928c7acea 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "symfony/http-foundation": "^4.4|^5.0", "symfony/polyfill-ctype": "^1.8", "symfony/polyfill-php73": "^1.9", - "symfony/polyfill-php80": "^1.15", + "symfony/polyfill-php80": "^1.16", "psr/log": "^1|^2" }, "require-dev": { From 882946ca24631ae97b2f13148866da19a32e0b4f Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 7 Jun 2021 01:15:42 +0200 Subject: [PATCH 179/396] Leverage str_contains/str_starts_with Signed-off-by: Alexander M. Turek --- Client.php | 2 +- Config/FileLocator.php | 4 ++-- Controller/ControllerResolver.php | 6 +++--- DataCollector/DumpDataCollector.php | 4 ++-- DataCollector/MemoryDataCollector.php | 4 ++-- DataCollector/RequestDataCollector.php | 4 ++-- Debug/FileLinkFormatter.php | 2 +- DependencyInjection/AddAnnotatedClassesToCachePass.php | 6 +++--- EventListener/AbstractTestSessionListener.php | 2 +- Exception/ControllerDoesNotReturnResponseException.php | 2 +- HttpCache/AbstractSurrogate.php | 2 +- HttpCache/Esi.php | 2 +- HttpCache/Ssi.php | 2 +- Kernel.php | 8 ++++---- Log/Logger.php | 2 +- Profiler/FileProfilerStorage.php | 4 ++-- Tests/EventListener/RouterListenerTest.php | 2 +- 17 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Client.php b/Client.php index f0dd66ece8..5c9169ce4b 100644 --- a/Client.php +++ b/Client.php @@ -85,7 +85,7 @@ protected function getScript($request) $requires = ''; foreach (get_declared_classes() as $class) { - if (0 === strpos($class, 'ComposerAutoloaderInit')) { + if (str_starts_with($class, 'ComposerAutoloaderInit')) { $r = new \ReflectionClass($class); $file = \dirname($r->getFileName(), 2).'/autoload.php'; if (file_exists($file)) { diff --git a/Config/FileLocator.php b/Config/FileLocator.php index 5dc82b33dc..a302419701 100644 --- a/Config/FileLocator.php +++ b/Config/FileLocator.php @@ -70,11 +70,11 @@ public function locate($file, $currentPath = null, $first = true) // no need to trigger deprecations when the loaded file is given as absolute path foreach ($this->paths as $deprecatedPath) { foreach ((array) $locations as $location) { - if (null !== $currentPath && 0 === strpos($location, $currentPath)) { + if (null !== $currentPath && str_starts_with($location, $currentPath)) { return $locations; } - if (0 === strpos($location, $deprecatedPath) && (null === $currentPath || false === strpos($location, $currentPath))) { + if (str_starts_with($location, $deprecatedPath) && (null === $currentPath || !str_contains($location, $currentPath))) { $deprecation = sprintf('Loading the file "%s" from the global resource directory "%s" is deprecated since Symfony 4.4 and will be removed in 5.0.', $file, $deprecatedPath); } } diff --git a/Controller/ControllerResolver.php b/Controller/ControllerResolver.php index 9c2fdd9807..c3df8f9571 100644 --- a/Controller/ControllerResolver.php +++ b/Controller/ControllerResolver.php @@ -106,7 +106,7 @@ public function getController(Request $request) */ protected function createController($controller) { - if (false === strpos($controller, '::')) { + if (!str_contains($controller, '::')) { $controller = $this->instantiateController($controller); if (!\is_callable($controller)) { @@ -154,7 +154,7 @@ protected function instantiateController($class) private function getControllerError($callable): string { if (\is_string($callable)) { - if (false !== strpos($callable, '::')) { + if (str_contains($callable, '::')) { $callable = explode('::', $callable, 2); } else { return sprintf('Function "%s" does not exist.', $callable); @@ -195,7 +195,7 @@ private function getControllerError($callable): string foreach ($collection as $item) { $lev = levenshtein($method, $item); - if ($lev <= \strlen($method) / 3 || false !== strpos($item, $method)) { + if ($lev <= \strlen($method) / 3 || str_contains($item, $method)) { $alternatives[] = $item; } } diff --git a/DataCollector/DumpDataCollector.php b/DataCollector/DumpDataCollector.php index a3cf2147cb..a66224b6f4 100644 --- a/DataCollector/DumpDataCollector.php +++ b/DataCollector/DumpDataCollector.php @@ -120,11 +120,11 @@ public function collect(Request $request, Response $response/*, \Throwable $exce if (!$this->requestStack || !$response->headers->has('X-Debug-Token') || $response->isRedirection() - || ($response->headers->has('Content-Type') && false === strpos($response->headers->get('Content-Type'), 'html')) + || ($response->headers->has('Content-Type') && !str_contains($response->headers->get('Content-Type'), 'html')) || 'html' !== $request->getRequestFormat() || false === strripos($response->getContent(), '') ) { - if ($response->headers->has('Content-Type') && false !== strpos($response->headers->get('Content-Type'), 'html')) { + if ($response->headers->has('Content-Type') && str_contains($response->headers->get('Content-Type'), 'html')) { $dumper = new HtmlDumper('php://output', $this->charset); $dumper->setDisplayOptions(['fileLinkFormat' => $this->fileLinkFormat]); } else { diff --git a/DataCollector/MemoryDataCollector.php b/DataCollector/MemoryDataCollector.php index 7ffcdab41d..ff0ccd9fa9 100644 --- a/DataCollector/MemoryDataCollector.php +++ b/DataCollector/MemoryDataCollector.php @@ -104,9 +104,9 @@ private function convertToBytes(string $memoryLimit) $memoryLimit = strtolower($memoryLimit); $max = strtolower(ltrim($memoryLimit, '+')); - if (0 === strpos($max, '0x')) { + if (str_starts_with($max, '0x')) { $max = \intval($max, 16); - } elseif (0 === strpos($max, '0')) { + } elseif (str_starts_with($max, '0')) { $max = \intval($max, 8); } else { $max = (int) $max; diff --git a/DataCollector/RequestDataCollector.php b/DataCollector/RequestDataCollector.php index f40c2fb9f6..2a3f6ce514 100644 --- a/DataCollector/RequestDataCollector.php +++ b/DataCollector/RequestDataCollector.php @@ -394,7 +394,7 @@ public function getName() */ protected function parseController($controller) { - if (\is_string($controller) && false !== strpos($controller, '::')) { + if (\is_string($controller) && str_contains($controller, '::')) { $controller = explode('::', $controller); } @@ -431,7 +431,7 @@ protected function parseController($controller) 'line' => $r->getStartLine(), ]; - if (false !== strpos($r->name, '{closure}')) { + if (str_contains($r->name, '{closure}')) { return $controller; } $controller['method'] = $r->name; diff --git a/Debug/FileLinkFormatter.php b/Debug/FileLinkFormatter.php index 79755a8ad7..27c71708b2 100644 --- a/Debug/FileLinkFormatter.php +++ b/Debug/FileLinkFormatter.php @@ -50,7 +50,7 @@ public function format($file, $line) { if ($fmt = $this->getFileLinkFormat()) { for ($i = 1; isset($fmt[$i]); ++$i) { - if (0 === strpos($file, $k = $fmt[$i++])) { + if (str_starts_with($file, $k = $fmt[$i++])) { $file = substr_replace($file, $fmt[$i], 0, \strlen($k)); break; } diff --git a/DependencyInjection/AddAnnotatedClassesToCachePass.php b/DependencyInjection/AddAnnotatedClassesToCachePass.php index 17a5f7f02e..9825151ab0 100644 --- a/DependencyInjection/AddAnnotatedClassesToCachePass.php +++ b/DependencyInjection/AddAnnotatedClassesToCachePass.php @@ -62,7 +62,7 @@ private function expandClasses(array $patterns, array $classes): array // Explicit classes declared in the patterns are returned directly foreach ($patterns as $key => $pattern) { - if (!str_ends_with($pattern, '\\') && false === strpos($pattern, '*')) { + if (!str_ends_with($pattern, '\\') && !str_contains($pattern, '*')) { unset($patterns[$key]); $expanded[] = ltrim($pattern, '\\'); } @@ -127,10 +127,10 @@ private function patternsToRegexps(array $patterns): array private function matchAnyRegexps(string $class, array $regexps): bool { - $isTest = false !== strpos($class, 'Test'); + $isTest = str_contains($class, 'Test'); foreach ($regexps as $regex) { - if ($isTest && false === strpos($regex, 'Test')) { + if ($isTest && !str_contains($regex, 'Test')) { continue; } diff --git a/EventListener/AbstractTestSessionListener.php b/EventListener/AbstractTestSessionListener.php index 86f179add7..25be3b3907 100644 --- a/EventListener/AbstractTestSessionListener.php +++ b/EventListener/AbstractTestSessionListener.php @@ -81,7 +81,7 @@ public function onKernelResponse(FilterResponseEvent $event) if ($session instanceof Session ? !$session->isEmpty() || (null !== $this->sessionId && $session->getId() !== $this->sessionId) : $wasStarted) { $params = session_get_cookie_params() + ['samesite' => null]; foreach ($this->sessionOptions as $k => $v) { - if (0 === strpos($k, 'cookie_')) { + if (str_starts_with($k, 'cookie_')) { $params[substr($k, 7)] = $v; } } diff --git a/Exception/ControllerDoesNotReturnResponseException.php b/Exception/ControllerDoesNotReturnResponseException.php index 1e87690ff1..54c80be90f 100644 --- a/Exception/ControllerDoesNotReturnResponseException.php +++ b/Exception/ControllerDoesNotReturnResponseException.php @@ -38,7 +38,7 @@ public function __construct(string $message, callable $controller, string $file, private function parseControllerDefinition(callable $controller): ?array { - if (\is_string($controller) && false !== strpos($controller, '::')) { + if (\is_string($controller) && str_contains($controller, '::')) { $controller = explode('::', $controller); } diff --git a/HttpCache/AbstractSurrogate.php b/HttpCache/AbstractSurrogate.php index 472d87e483..3385940243 100644 --- a/HttpCache/AbstractSurrogate.php +++ b/HttpCache/AbstractSurrogate.php @@ -57,7 +57,7 @@ public function hasSurrogateCapability(Request $request) return false; } - return false !== strpos($value, sprintf('%s/1.0', strtoupper($this->getName()))); + return str_contains($value, sprintf('%s/1.0', strtoupper($this->getName()))); } /** diff --git a/HttpCache/Esi.php b/HttpCache/Esi.php index 0bad63e748..829f4ac643 100644 --- a/HttpCache/Esi.php +++ b/HttpCache/Esi.php @@ -37,7 +37,7 @@ public function getName() */ public function addSurrogateControl(Response $response) { - if (false !== strpos($response->getContent(), 'getContent(), 'headers->set('Surrogate-Control', 'content="ESI/1.0"'); } } diff --git a/HttpCache/Ssi.php b/HttpCache/Ssi.php index 6dba4e11df..a2856f2760 100644 --- a/HttpCache/Ssi.php +++ b/HttpCache/Ssi.php @@ -34,7 +34,7 @@ public function getName() */ public function addSurrogateControl(Response $response) { - if (false !== strpos($response->getContent(), '