From 2bb35cdbf048e19c9c6990adbcc4f979df923497 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Sun, 15 Jan 2023 18:57:26 +0100 Subject: [PATCH 01/31] [Tests] New iteration of removing `$this` occurrences in future static data providers --- .../RequestDataCollectorTest.php | 84 +++++++------------ .../DataCollector/DummyController.php | 49 +++++++++++ 2 files changed, 78 insertions(+), 55 deletions(-) create mode 100644 Tests/Fixtures/DataCollector/DummyController.php diff --git a/Tests/DataCollector/RequestDataCollectorTest.php b/Tests/DataCollector/RequestDataCollectorTest.php index d7c8b302b6..9e8c30ebbf 100644 --- a/Tests/DataCollector/RequestDataCollectorTest.php +++ b/Tests/DataCollector/RequestDataCollectorTest.php @@ -31,6 +31,7 @@ use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\HttpKernel; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Symfony\Component\HttpKernel\Tests\Fixtures\DataCollector\DummyController; class RequestDataCollectorTest extends TestCase { @@ -91,22 +92,24 @@ public function testControllerInspection($name, $callable, $expected) $this->assertSame($expected, $c->getController()->getValue(true), sprintf('Testing: %s', $name)); } - public function provideControllerCallables() + public static function provideControllerCallables(): array { // make sure we always match the line number - $r1 = new \ReflectionMethod($this, 'testControllerInspection'); - $r2 = new \ReflectionMethod($this, 'staticControllerMethod'); - $r3 = new \ReflectionClass($this); + $controller = new DummyController(); + + $r1 = new \ReflectionMethod($controller, 'regularCallable'); + $r2 = new \ReflectionMethod($controller, 'staticControllerMethod'); + $r3 = new \ReflectionClass($controller); // test name, callable, expected return [ [ '"Regular" callable', - [$this, 'testControllerInspection'], + [$controller, 'regularCallable'], [ - 'class' => self::class, - 'method' => 'testControllerInspection', - 'file' => __FILE__, + 'class' => DummyController::class, + 'method' => 'regularCallable', + 'file' => $r3->getFileName(), 'line' => $r1->getStartLine(), ], ], @@ -124,42 +127,42 @@ function () { return 'foo'; }, [ 'Static callback as string', - __NAMESPACE__.'\RequestDataCollectorTest::staticControllerMethod', + DummyController::class.'::staticControllerMethod', [ - 'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', + 'class' => DummyController::class, 'method' => 'staticControllerMethod', - 'file' => __FILE__, + 'file' => $r3->getFileName(), 'line' => $r2->getStartLine(), ], ], [ 'Static callable with instance', - [$this, 'staticControllerMethod'], + [$controller, 'staticControllerMethod'], [ - 'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', + 'class' => DummyController::class, 'method' => 'staticControllerMethod', - 'file' => __FILE__, + 'file' => $r3->getFileName(), 'line' => $r2->getStartLine(), ], ], [ 'Static callable with class name', - ['Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'staticControllerMethod'], + [DummyController::class, 'staticControllerMethod'], [ - 'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', + 'class' => DummyController::class, 'method' => 'staticControllerMethod', - 'file' => __FILE__, + 'file' => $r3->getFileName(), 'line' => $r2->getStartLine(), ], ], [ 'Callable with instance depending on __call()', - [$this, 'magicMethod'], + [$controller, 'magicMethod'], [ - 'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', + 'class' => DummyController::class, 'method' => 'magicMethod', 'file' => 'n/a', 'line' => 'n/a', @@ -168,9 +171,9 @@ function () { return 'foo'; }, [ 'Callable with class name depending on __callStatic()', - ['Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', 'magicMethod'], + [DummyController::class, 'magicMethod'], [ - 'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', + 'class' => DummyController::class, 'method' => 'magicMethod', 'file' => 'n/a', 'line' => 'n/a', @@ -179,11 +182,11 @@ function () { return 'foo'; }, [ 'Invokable controller', - $this, + $controller, [ - 'class' => 'Symfony\Component\HttpKernel\Tests\DataCollector\RequestDataCollectorTest', + 'class' => DummyController::class, 'method' => null, - 'file' => __FILE__, + 'file' => $r3->getFileName(), 'line' => $r3->getStartLine(), ], ], @@ -390,35 +393,6 @@ protected function injectController($collector, $controller, $request) $collector->onKernelController($event); } - /** - * Dummy method used as controller callable. - */ - public static function staticControllerMethod() - { - throw new \LogicException('Unexpected method call'); - } - - /** - * Magic method to allow non existing methods to be called and delegated. - */ - public function __call(string $method, array $args) - { - throw new \LogicException('Unexpected method call'); - } - - /** - * Magic method to allow non existing methods to be called and delegated. - */ - public static function __callStatic(string $method, array $args) - { - throw new \LogicException('Unexpected method call'); - } - - public function __invoke() - { - throw new \LogicException('Unexpected method call'); - } - private function getCookieByName(Response $response, $name) { foreach ($response->headers->getCookies() as $cookie) { @@ -445,7 +419,7 @@ public function testIsJson($contentType, $expected) $this->assertSame($expected, $c->isJsonRequest()); } - public function provideJsonContentTypes() + public static function provideJsonContentTypes(): array { return [ ['text/csv', false], @@ -472,7 +446,7 @@ public function testGetPrettyJsonValidity($content, $expected) $this->assertSame($expected, $c->getPrettyJson()); } - public function providePrettyJson() + public static function providePrettyJson(): array { return [ ['null', 'null'], diff --git a/Tests/Fixtures/DataCollector/DummyController.php b/Tests/Fixtures/DataCollector/DummyController.php new file mode 100644 index 0000000000..611c41d3e8 --- /dev/null +++ b/Tests/Fixtures/DataCollector/DummyController.php @@ -0,0 +1,49 @@ + + * + * 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\DataCollector; + +class DummyController +{ + /** + * Dummy method used as controller callable. + */ + public static function staticControllerMethod() + { + throw new \LogicException('Unexpected method call'); + } + + /** + * Magic method to allow non existing methods to be called and delegated. + */ + public function __call(string $method, array $args) + { + throw new \LogicException('Unexpected method call'); + } + + /** + * Magic method to allow non existing methods to be called and delegated. + */ + public static function __callStatic(string $method, array $args) + { + throw new \LogicException('Unexpected method call'); + } + + public function __invoke() + { + throw new \LogicException('Unexpected method call'); + } + + public function regularCallable() + { + throw new \LogicException('Unexpected method call'); + } +} From aba2702537898075f31faae998730eb9258d25d5 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 24 Jan 2023 15:02:24 +0100 Subject: [PATCH 02/31] Update license years (last time) --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 0083704572..0138f8f071 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2004-2023 Fabien Potencier +Copyright (c) 2004-present 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 aaeec341582d3c160cc9ecfa8b2419ba6c69954e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 1 Feb 2023 09:18:48 +0100 Subject: [PATCH 03/31] Update VERSION for 5.4.20 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 3126ebd31a..b2ccc7d95a 100644 --- a/Kernel.php +++ b/Kernel.php @@ -78,12 +78,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static $freshCache = []; - public const VERSION = '5.4.20-DEV'; + public const VERSION = '5.4.20'; public const VERSION_ID = 50420; public const MAJOR_VERSION = 5; 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/2024'; public const END_OF_LIFE = '11/2025'; From fee6112f0e528c1b8b4660e5d813892603650560 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 1 Feb 2023 09:22:17 +0100 Subject: [PATCH 04/31] Bump Symfony version to 5.4.21 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index b2ccc7d95a..a190fe2be9 100644 --- a/Kernel.php +++ b/Kernel.php @@ -78,12 +78,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static $freshCache = []; - public const VERSION = '5.4.20'; - public const VERSION_ID = 50420; + public const VERSION = '5.4.21-DEV'; + public const VERSION_ID = 50421; public const MAJOR_VERSION = 5; 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/2024'; public const END_OF_LIFE = '11/2025'; From 50d92ec6287a275d98d533aa95f13b6426b27a61 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 1 Feb 2023 09:35:57 +0100 Subject: [PATCH 05/31] Bump Symfony version to 6.2.7 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index d8b37df0ce..3735cf0b1b 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.2.6'; - public const VERSION_ID = 60206; + public const VERSION = '6.2.7-DEV'; + public const VERSION_ID = 60207; public const MAJOR_VERSION = 6; 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/2023'; public const END_OF_LIFE = '07/2023'; From f9a983b00232497dd77982ced2ab7ecb6bbb4945 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 2 Feb 2023 09:28:29 +0100 Subject: [PATCH 06/31] [HttpKernel] fix merge --- .../RequestDataCollectorTest.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Tests/DataCollector/RequestDataCollectorTest.php b/Tests/DataCollector/RequestDataCollectorTest.php index 9e8c30ebbf..d5ef76b68b 100644 --- a/Tests/DataCollector/RequestDataCollectorTest.php +++ b/Tests/DataCollector/RequestDataCollectorTest.php @@ -109,7 +109,7 @@ public static function provideControllerCallables(): array [ 'class' => DummyController::class, 'method' => 'regularCallable', - 'file' => $r3->getFileName(), + 'file' => $r1->getFileName(), 'line' => $r1->getStartLine(), ], ], @@ -125,13 +125,24 @@ function () { return 'foo'; }, ], ], + [ + 'First-class callable closure', + $controller->regularCallable(...), + [ + 'class' => DummyController::class, + 'method' => 'regularCallable', + 'file' => $r1->getFileName(), + 'line' => $r1->getStartLine(), + ], + ], + [ 'Static callback as string', DummyController::class.'::staticControllerMethod', [ 'class' => DummyController::class, 'method' => 'staticControllerMethod', - 'file' => $r3->getFileName(), + 'file' => $r2->getFileName(), 'line' => $r2->getStartLine(), ], ], @@ -142,7 +153,7 @@ function () { return 'foo'; }, [ 'class' => DummyController::class, 'method' => 'staticControllerMethod', - 'file' => $r3->getFileName(), + 'file' => $r2->getFileName(), 'line' => $r2->getStartLine(), ], ], @@ -153,7 +164,7 @@ function () { return 'foo'; }, [ 'class' => DummyController::class, 'method' => 'staticControllerMethod', - 'file' => $r3->getFileName(), + 'file' => $r2->getFileName(), 'line' => $r2->getStartLine(), ], ], From 368462838ed6c344759ac5b90af98e5ef5965ba6 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 2 Feb 2023 09:30:50 +0100 Subject: [PATCH 07/31] [HttpKernel] fix merge (bis) --- Tests/DataCollector/RequestDataCollectorTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/DataCollector/RequestDataCollectorTest.php b/Tests/DataCollector/RequestDataCollectorTest.php index d5ef76b68b..becb9b01bf 100644 --- a/Tests/DataCollector/RequestDataCollectorTest.php +++ b/Tests/DataCollector/RequestDataCollectorTest.php @@ -127,7 +127,7 @@ function () { return 'foo'; }, [ 'First-class callable closure', - $controller->regularCallable(...), + \PHP_VERSION_ID >= 80100 ? eval('return $controller->regularCallable(...);') : [$controller, 'regularCallable'], [ 'class' => DummyController::class, 'method' => 'regularCallable', From 820ae32996338459476cd0e845ae9e1e5d023e88 Mon Sep 17 00:00:00 2001 From: pkruithof Date: Thu, 5 Jan 2023 11:56:58 +0100 Subject: [PATCH 08/31] [Response] `getMaxAge()` returns non-negative integer --- HttpCache/HttpCache.php | 6 +++++- Tests/EventListener/SessionListenerTest.php | 24 +++++++++++++++++++++ composer.json | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/HttpCache/HttpCache.php b/HttpCache/HttpCache.php index 28be364c17..5688fc0c13 100644 --- a/HttpCache/HttpCache.php +++ b/HttpCache/HttpCache.php @@ -718,7 +718,11 @@ private function mayServeStaleWhileRevalidate(Response $entry): bool $timeout = $this->options['stale_while_revalidate']; } - return abs($entry->getTtl() ?? 0) < $timeout; + $age = $entry->getAge(); + $maxAge = $entry->getMaxAge() ?? 0; + $ttl = $maxAge - $age; + + return abs($ttl) < $timeout; } /** diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index 96f66354ba..365afd6dff 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -590,6 +590,30 @@ public function testResponseHeadersMaxAgeAndExpiresDefaultValuesIfSessionStarted $this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER)); } + public function testPrivateResponseMaxAgeIsRespectedIfSessionStarted() + { + $kernel = $this->createMock(HttpKernelInterface::class); + + $session = $this->createMock(Session::class); + $session->expects($this->once())->method('getUsageIndex')->willReturn(1); + $request = new Request([], [], [], [], [], ['SERVER_PROTOCOL' => 'HTTP/1.0']); + $request->setSession($session); + + $response = new Response(); + $response->headers->set('Cache-Control', 'no-cache'); + $response->prepare($request); + + $listener = new SessionListener(new Container()); + $listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response)); + + $this->assertSame(0, $response->getMaxAge()); + $this->assertFalse($response->headers->hasCacheControlDirective('public')); + $this->assertTrue($response->headers->hasCacheControlDirective('private')); + $this->assertTrue($response->headers->hasCacheControlDirective('must-revalidate')); + $this->assertLessThanOrEqual(new \DateTimeImmutable('now', new \DateTimeZone('UTC')), new \DateTimeImmutable($response->headers->get('Expires'))); + $this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER)); + } + public function testSurrogateMainRequestIsPublic() { $session = $this->createMock(Session::class); diff --git a/composer.json b/composer.json index 09682db49d..180a79b336 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "symfony/deprecation-contracts": "^2.1|^3", "symfony/error-handler": "^4.4|^5.0|^6.0", "symfony/event-dispatcher": "^5.0|^6.0", - "symfony/http-foundation": "^5.3.7|^6.0", + "symfony/http-foundation": "^5.4.21|^6.2.7", "symfony/polyfill-ctype": "^1.8", "symfony/polyfill-php73": "^1.9", "symfony/polyfill-php80": "^1.16", From 559c6246c52f727e3ed89dc4e0ea6a0e890b4a28 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Sun, 5 Feb 2023 10:12:16 +0100 Subject: [PATCH 09/31] [Tests] Migrate data providers to static ones --- Tests/Controller/ContainerControllerResolverTest.php | 2 +- Tests/Controller/ControllerResolverTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Controller/ContainerControllerResolverTest.php b/Tests/Controller/ContainerControllerResolverTest.php index 9ce7ec467c..5f3b3a941a 100644 --- a/Tests/Controller/ContainerControllerResolverTest.php +++ b/Tests/Controller/ContainerControllerResolverTest.php @@ -204,7 +204,7 @@ public function testExceptionWhenUsingRemovedControllerService() $resolver->getController($request); } - public function getUndefinedControllers() + public static function getUndefinedControllers(): array { $tests = parent::getUndefinedControllers(); $tests[0] = ['foo', \InvalidArgumentException::class, 'Controller "foo" does neither exist as service nor as class']; diff --git a/Tests/Controller/ControllerResolverTest.php b/Tests/Controller/ControllerResolverTest.php index 2afcfe4b4e..f78599b82e 100644 --- a/Tests/Controller/ControllerResolverTest.php +++ b/Tests/Controller/ControllerResolverTest.php @@ -165,7 +165,7 @@ public function testGetControllerWithUndefinedController($controller, $exception $resolver->getController($request); } - public function getUndefinedControllers() + public static function getUndefinedControllers() { $controller = new ControllerTest(); From 2626c827518dec1b75b95546a8a00c1537f5747d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 6 Feb 2023 16:05:58 +0100 Subject: [PATCH 10/31] [HttpKernel] Fix setting the session on the main request when it's started by a subrequest --- EventListener/AbstractSessionListener.php | 1 + Tests/EventListener/SessionListenerTest.php | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/EventListener/AbstractSessionListener.php b/EventListener/AbstractSessionListener.php index 27749b24b2..cb994cd77d 100644 --- a/EventListener/AbstractSessionListener.php +++ b/EventListener/AbstractSessionListener.php @@ -72,6 +72,7 @@ public function onKernelRequest(RequestEvent $event) $request->setSessionFactory(function () use (&$sess, $request) { if (!$sess) { $sess = $this->getSession(); + $request->setSession($sess); /* * For supporting sessions in php runtime with runners like roadrunner or swoole, the session diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index 365afd6dff..7503eabb28 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -691,6 +691,27 @@ public function testGetSessionIsCalledOnce() $subRequest->getSession(); } + public function testGetSessionSetsSessionOnMainRequest() + { + $mainRequest = new Request(); + $listener = $this->createListener($mainRequest, new NativeSessionStorageFactory()); + + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $mainRequest, HttpKernelInterface::MAIN_REQUEST); + $listener->onKernelRequest($event); + + $this->assertFalse($mainRequest->hasSession(true)); + + $subRequest = $mainRequest->duplicate(); + + $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $subRequest, HttpKernelInterface::SUB_REQUEST); + $listener->onKernelRequest($event); + + $session = $subRequest->getSession(); + + $this->assertTrue($mainRequest->hasSession(true)); + $this->assertSame($session, $mainRequest->getSession()); + } + public function testSessionUsageExceptionIfStatelessAndSessionUsed() { $session = $this->createMock(Session::class); From 934dd9f1886b49b7480b250ddb4f067d4d3ed4c4 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 14 Dec 2022 15:42:16 +0100 Subject: [PATCH 11/31] Migrate to `static` data providers using `rector/rector` --- Tests/Controller/ContainerControllerResolverTest.php | 2 +- Tests/Controller/ControllerResolverTest.php | 2 +- Tests/Controller/ErrorControllerTest.php | 2 +- Tests/DataCollector/LoggerDataCollectorTest.php | 2 +- Tests/DataCollector/MemoryDataCollectorTest.php | 2 +- .../RegisterControllerArgumentLocatorsPassTest.php | 4 ++-- Tests/EventListener/DebugHandlersListenerTest.php | 2 +- .../EventListener/DisallowRobotsIndexingListenerTest.php | 2 +- Tests/EventListener/ErrorListenerTest.php | 4 ++-- Tests/EventListener/ProfilerListenerTest.php | 2 +- Tests/EventListener/RouterListenerTest.php | 4 ++-- Tests/EventListener/SessionListenerTest.php | 2 +- Tests/EventListener/TestSessionListenerTest.php | 2 +- Tests/Exception/HttpExceptionTest.php | 2 +- Tests/Fragment/RoutableFragmentRendererTest.php | 4 ++-- Tests/HttpCache/HttpCacheTest.php | 8 ++++---- Tests/HttpCache/ResponseCacheStrategyTest.php | 2 +- Tests/HttpKernelTest.php | 2 +- Tests/KernelTest.php | 2 +- Tests/Log/LoggerTest.php | 2 +- 20 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Tests/Controller/ContainerControllerResolverTest.php b/Tests/Controller/ContainerControllerResolverTest.php index 5f3b3a941a..9d127436cf 100644 --- a/Tests/Controller/ContainerControllerResolverTest.php +++ b/Tests/Controller/ContainerControllerResolverTest.php @@ -149,7 +149,7 @@ public function testInstantiateControllerWhenControllerStartsWithABackslash($con $this->assertSame('action', $controller[1]); } - public function getControllers() + public static function getControllers() { return [ ['\\'.ControllerTestService::class.'::action'], diff --git a/Tests/Controller/ControllerResolverTest.php b/Tests/Controller/ControllerResolverTest.php index f78599b82e..621d948197 100644 --- a/Tests/Controller/ControllerResolverTest.php +++ b/Tests/Controller/ControllerResolverTest.php @@ -141,7 +141,7 @@ public function testGetControllerWithStaticController($staticController, $return $this->assertSame($returnValue, $controller()); } - public function getStaticControllers() + public static function getStaticControllers() { return [ [TestAbstractController::class.'::staticAction', 'foo'], diff --git a/Tests/Controller/ErrorControllerTest.php b/Tests/Controller/ErrorControllerTest.php index 1b3a833578..12b84aaf9f 100644 --- a/Tests/Controller/ErrorControllerTest.php +++ b/Tests/Controller/ErrorControllerTest.php @@ -36,7 +36,7 @@ public function testInvokeController(Request $request, \Exception $exception, in self::assertStringContainsString($content, strtr($response->getContent(), ["\n" => '', ' ' => ''])); } - public function getInvokeControllerDataProvider() + public static function getInvokeControllerDataProvider() { yield 'default status code and HTML format' => [ new Request(), diff --git a/Tests/DataCollector/LoggerDataCollectorTest.php b/Tests/DataCollector/LoggerDataCollectorTest.php index bf3fb65522..44b740c98b 100644 --- a/Tests/DataCollector/LoggerDataCollectorTest.php +++ b/Tests/DataCollector/LoggerDataCollectorTest.php @@ -179,7 +179,7 @@ public function testReset() $c->reset(); } - public function getCollectTestData() + public static function getCollectTestData() { yield 'simple log' => [ 1, diff --git a/Tests/DataCollector/MemoryDataCollectorTest.php b/Tests/DataCollector/MemoryDataCollectorTest.php index 63dd62ce70..240f29a88f 100644 --- a/Tests/DataCollector/MemoryDataCollectorTest.php +++ b/Tests/DataCollector/MemoryDataCollectorTest.php @@ -37,7 +37,7 @@ public function testBytesConversion($limit, $bytes) $this->assertEquals($bytes, $method->invoke($collector, $limit)); } - public function getBytesConversionTestData() + public static function getBytesConversionTestData() { return [ ['2k', 2048], diff --git a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php index a8fdd7975b..69e1cc8cd6 100644 --- a/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php +++ b/Tests/DependencyInjection/RegisterControllerArgumentLocatorsPassTest.php @@ -308,7 +308,7 @@ public function testBindings($bindingName) $this->assertEquals($expected, $locator->getArgument(0)); } - public function provideBindings() + public static function provideBindings() { return [ [ControllerDummy::class.'$bar'], @@ -343,7 +343,7 @@ public function testBindScalarValueToControllerArgument($bindingKey) $this->assertSame('foo_val', $locator->get('foo::fooAction')->get('someArg')); } - public function provideBindScalarValueToControllerArgument() + public static function provideBindScalarValueToControllerArgument() { yield ['$someArg']; yield ['string $someArg']; diff --git a/Tests/EventListener/DebugHandlersListenerTest.php b/Tests/EventListener/DebugHandlersListenerTest.php index c8581927a8..81a84e92f1 100644 --- a/Tests/EventListener/DebugHandlersListenerTest.php +++ b/Tests/EventListener/DebugHandlersListenerTest.php @@ -157,7 +157,7 @@ public function testReplaceExistingExceptionHandler() $this->assertSame($userHandler, $eHandler->setExceptionHandler('var_dump')); } - public function provideLevelsAssignedToLoggers(): array + public static function provideLevelsAssignedToLoggers(): array { return [ [false, false, '0', null, null], diff --git a/Tests/EventListener/DisallowRobotsIndexingListenerTest.php b/Tests/EventListener/DisallowRobotsIndexingListenerTest.php index 8ceb910b5b..b0263f8f29 100644 --- a/Tests/EventListener/DisallowRobotsIndexingListenerTest.php +++ b/Tests/EventListener/DisallowRobotsIndexingListenerTest.php @@ -36,7 +36,7 @@ public function testInvoke(?string $expected, array $responseArgs) $this->assertSame($expected, $response->headers->get('X-Robots-Tag'), 'Header doesn\'t match expectations'); } - public function provideResponses(): iterable + public static function provideResponses(): iterable { yield 'No header' => ['noindex', []]; diff --git a/Tests/EventListener/ErrorListenerTest.php b/Tests/EventListener/ErrorListenerTest.php index 73cc19afc8..b97737218c 100644 --- a/Tests/EventListener/ErrorListenerTest.php +++ b/Tests/EventListener/ErrorListenerTest.php @@ -119,7 +119,7 @@ public function testHandleWithLoggerAndCustomConfiguration() $this->assertCount(1, $logger->getLogs('warning')); } - public function provider() + public static function provider() { if (!class_exists(Request::class)) { return [[null, null]]; @@ -202,7 +202,7 @@ public function testOnControllerArguments(callable $controller) $this->assertSame('OK: foo', $event->getResponse()->getContent()); } - public function controllerProvider() + public static function controllerProvider() { yield [function (FlattenException $exception) { return new Response('OK: '.$exception->getMessage()); diff --git a/Tests/EventListener/ProfilerListenerTest.php b/Tests/EventListener/ProfilerListenerTest.php index 45272ceb02..57f8f53b1e 100644 --- a/Tests/EventListener/ProfilerListenerTest.php +++ b/Tests/EventListener/ProfilerListenerTest.php @@ -87,7 +87,7 @@ public function testCollectParameter(Request $request, ?bool $enable) $listener->onKernelResponse(new ResponseEvent($kernel, $request, Kernel::MAIN_REQUEST, $response)); } - public function collectRequestProvider(): iterable + public static function collectRequestProvider(): iterable { yield [Request::create('/'), null]; yield [Request::create('/', 'GET', ['profile' => '1']), true]; diff --git a/Tests/EventListener/RouterListenerTest.php b/Tests/EventListener/RouterListenerTest.php index e61414bd04..886fe497f3 100644 --- a/Tests/EventListener/RouterListenerTest.php +++ b/Tests/EventListener/RouterListenerTest.php @@ -67,7 +67,7 @@ public function testPort($defaultHttpPort, $defaultHttpsPort, $uri, $expectedHtt $this->assertEquals(str_starts_with($uri, 'https') ? 'https' : 'http', $context->getScheme()); } - public function getPortData() + public static function getPortData() { return [ [80, 443, 'http://localhost/', 80, 443], @@ -157,7 +157,7 @@ public function testLoggingParameter($parameter, $log, $parameters) $listener->onKernelRequest(new RequestEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST)); } - public function getLoggingParameterData() + public static function getLoggingParameterData() { return [ [['_route' => 'foo'], 'Matched route "{route}".', ['route' => 'foo', 'route_parameters' => ['_route' => 'foo'], 'request_uri' => 'http://localhost/', 'method' => 'GET']], diff --git a/Tests/EventListener/SessionListenerTest.php b/Tests/EventListener/SessionListenerTest.php index 7503eabb28..f3265823a5 100644 --- a/Tests/EventListener/SessionListenerTest.php +++ b/Tests/EventListener/SessionListenerTest.php @@ -82,7 +82,7 @@ public function testSessionCookieOptions(array $phpSessionOptions, array $sessio } } - public function provideSessionOptions(): \Generator + public static function provideSessionOptions(): \Generator { if (\PHP_VERSION_ID > 70300) { yield 'set_samesite_by_php' => [ diff --git a/Tests/EventListener/TestSessionListenerTest.php b/Tests/EventListener/TestSessionListenerTest.php index 3bb7697062..9bce97b854 100644 --- a/Tests/EventListener/TestSessionListenerTest.php +++ b/Tests/EventListener/TestSessionListenerTest.php @@ -130,7 +130,7 @@ public function testSessionWithNewSessionIdAndNewCookieDoesNotSendAnotherCookie( $this->assertSame($expected, $response->headers->all()['set-cookie']); } - public function anotherCookieProvider() + public static function anotherCookieProvider() { return [ 'same' => ['MOCKSESSID=789; path=/', ['MOCKSESSID=789; path=/']], diff --git a/Tests/Exception/HttpExceptionTest.php b/Tests/Exception/HttpExceptionTest.php index feaec807fd..fad9e796f4 100644 --- a/Tests/Exception/HttpExceptionTest.php +++ b/Tests/Exception/HttpExceptionTest.php @@ -16,7 +16,7 @@ class HttpExceptionTest extends TestCase { - public function headerDataProvider() + public static function headerDataProvider() { return [ [['X-Test' => 'Test']], diff --git a/Tests/Fragment/RoutableFragmentRendererTest.php b/Tests/Fragment/RoutableFragmentRendererTest.php index d17643c186..937c23d869 100644 --- a/Tests/Fragment/RoutableFragmentRendererTest.php +++ b/Tests/Fragment/RoutableFragmentRendererTest.php @@ -34,7 +34,7 @@ public function testGenerateAbsoluteFragmentUri($uri, $controller) $this->assertEquals('http://localhost'.$uri, $this->callGenerateFragmentUriMethod($controller, Request::create('/'), true)); } - public function getGenerateFragmentUriData() + public static function getGenerateFragmentUriData() { return [ ['/_fragment?_path=_format%3Dhtml%26_locale%3Den%26_controller%3Dcontroller', new ControllerReference('controller', [], [])], @@ -65,7 +65,7 @@ public function testGenerateFragmentUriWithNonScalar($controller) $this->callGenerateFragmentUriMethod($controller, Request::create('/')); } - public function getGenerateFragmentUriDataWithNonScalar() + public static function getGenerateFragmentUriDataWithNonScalar() { return [ [new ControllerReference('controller', ['foo' => new Foo(), 'bar' => 'bar'], [])], diff --git a/Tests/HttpCache/HttpCacheTest.php b/Tests/HttpCache/HttpCacheTest.php index 7d8ef79187..22cf88daa2 100644 --- a/Tests/HttpCache/HttpCacheTest.php +++ b/Tests/HttpCache/HttpCacheTest.php @@ -1378,7 +1378,7 @@ public function testHttpCacheIsSetAsATrustedProxy(array $existing) Request::setTrustedProxies([], -1); } - public function getTrustedProxyData() + public static function getTrustedProxyData() { return [ [[]], @@ -1407,7 +1407,7 @@ public function testForwarderHeaderForForwardedRequests($forwarded, $expected) Request::setTrustedProxies([], -1); } - public function getForwardedData() + public static function getForwardedData() { return [ [null, 'for="10.0.0.1";host="localhost";proto=http'], @@ -1599,7 +1599,7 @@ public function testResponsesThatMayBeUsedStaleIfError($responseHeaders, $sleepB $this->assertTraceContains('stale-if-error'); } - public function getResponseDataThatMayBeServedStaleIfError() + public static function getResponseDataThatMayBeServedStaleIfError() { // All data sets assume that a 10s stale-if-error grace period has been configured yield 'public, max-age expired' => [['Cache-Control' => 'public, max-age=60'], 65]; @@ -1641,7 +1641,7 @@ public function testResponsesThatMustNotBeUsedStaleIfError($responseHeaders, $sl $this->assertEquals(500, $this->response->getStatusCode()); } - public function getResponseDataThatMustNotBeServedStaleIfError() + public static function getResponseDataThatMustNotBeServedStaleIfError() { // All data sets assume that a 10s stale-if-error grace period has been configured yield 'public, no TTL but beyond grace period' => [['Cache-Control' => 'public'], 15]; diff --git a/Tests/HttpCache/ResponseCacheStrategyTest.php b/Tests/HttpCache/ResponseCacheStrategyTest.php index fa0ad5d311..4e6fe680b9 100644 --- a/Tests/HttpCache/ResponseCacheStrategyTest.php +++ b/Tests/HttpCache/ResponseCacheStrategyTest.php @@ -309,7 +309,7 @@ public function testCacheControlMerging(array $expects, array $master, array $su } } - public function cacheControlMergingProvider() + public static function cacheControlMergingProvider() { yield 'result is public if all responses are public' => [ ['private' => false, 'public' => true], diff --git a/Tests/HttpKernelTest.php b/Tests/HttpKernelTest.php index 38a09ef2d2..0a1dc60e4a 100644 --- a/Tests/HttpKernelTest.php +++ b/Tests/HttpKernelTest.php @@ -175,7 +175,7 @@ public function testHandleWhenAnExceptionIsHandledWithASpecificStatusCode($expec $this->assertEquals($expectedStatusCode, $response->getStatusCode()); } - public function getSpecificStatusCodes() + public static function getSpecificStatusCodes() { return [ [200], diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index 2dab2ec01d..fa2074694e 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -256,7 +256,7 @@ public function testStripComments(string $source, string $expected) $this->assertEquals($expected, $output); } - public function getStripCommentsCodes(): array + public static function getStripCommentsCodes(): array { return [ ['assertLogsMatch($expected, $this->getLogs()); } - public function provideLevelsAndMessages() + public static function provideLevelsAndMessages() { return [ LogLevel::EMERGENCY => [LogLevel::EMERGENCY, 'message of level emergency with context: {user}'], From 88bb0c230d23fb1453529d50f7d4a74802245e4f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 16 Feb 2023 10:33:00 +0100 Subject: [PATCH 12/31] CS fix --- ControllerMetadata/ArgumentMetadata.php | 4 ++-- DataCollector/MemoryDataCollector.php | 6 +++--- Debug/FileLinkFormatter.php | 2 +- HttpCache/Store.php | 2 +- Kernel.php | 4 ++-- Tests/EventListener/TestSessionListenerTest.php | 1 + Tests/HttpCache/ResponseCacheStrategyTest.php | 1 + Tests/HttpCache/SsiTest.php | 2 +- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ControllerMetadata/ArgumentMetadata.php b/ControllerMetadata/ArgumentMetadata.php index 1a9ebc0c3a..0c5b1da36d 100644 --- a/ControllerMetadata/ArgumentMetadata.php +++ b/ControllerMetadata/ArgumentMetadata.php @@ -107,9 +107,9 @@ public function isNullable() /** * Returns the default value of the argument. * - * @throws \LogicException if no default value is present; {@see self::hasDefaultValue()} - * * @return mixed + * + * @throws \LogicException if no default value is present; {@see self::hasDefaultValue()} */ public function getDefaultValue() { diff --git a/DataCollector/MemoryDataCollector.php b/DataCollector/MemoryDataCollector.php index 53a1f9e448..3affae298c 100644 --- a/DataCollector/MemoryDataCollector.php +++ b/DataCollector/MemoryDataCollector.php @@ -100,11 +100,11 @@ private function convertToBytes(string $memoryLimit) switch (substr($memoryLimit, -1)) { case 't': $max *= 1024; - // no break + // no break case 'g': $max *= 1024; - // no break + // no break case 'm': $max *= 1024; - // no break + // no break case 'k': $max *= 1024; } diff --git a/Debug/FileLinkFormatter.php b/Debug/FileLinkFormatter.php index 9ac688cc56..39d4d3b501 100644 --- a/Debug/FileLinkFormatter.php +++ b/Debug/FileLinkFormatter.php @@ -41,7 +41,7 @@ class FileLinkFormatter /** * @param string|array|null $fileLinkFormat - * @param string|\Closure $urlFormat the URL format, or a closure that returns it on-demand + * @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) { diff --git a/HttpCache/Store.php b/HttpCache/Store.php index 8087e0cb18..5db94f73d6 100644 --- a/HttpCache/Store.php +++ b/HttpCache/Store.php @@ -197,7 +197,7 @@ public function write(Request $request, Response $response) if ($this->getPath($digest) !== $response->headers->get('X-Body-File')) { throw new \RuntimeException('X-Body-File and X-Content-Digest do not match.'); } - // Everything seems ok, omit writing content to disk + // Everything seems ok, omit writing content to disk } else { $digest = $this->generateContentDigest($response); $response->headers->set('X-Content-Digest', $digest); diff --git a/Kernel.php b/Kernel.php index a190fe2be9..5a95e77848 100644 --- a/Kernel.php +++ b/Kernel.php @@ -404,9 +404,9 @@ protected function build(ContainerBuilder $container) /** * Gets the container class. * - * @throws \InvalidArgumentException If the generated classname is invalid - * * @return string + * + * @throws \InvalidArgumentException If the generated classname is invalid */ protected function getContainerClass() { diff --git a/Tests/EventListener/TestSessionListenerTest.php b/Tests/EventListener/TestSessionListenerTest.php index 9bce97b854..bb989b3302 100644 --- a/Tests/EventListener/TestSessionListenerTest.php +++ b/Tests/EventListener/TestSessionListenerTest.php @@ -28,6 +28,7 @@ * Tests SessionListener. * * @author Bulat Shakirzyanov + * * @group legacy */ class TestSessionListenerTest extends TestCase diff --git a/Tests/HttpCache/ResponseCacheStrategyTest.php b/Tests/HttpCache/ResponseCacheStrategyTest.php index 4e6fe680b9..c5c510f858 100644 --- a/Tests/HttpCache/ResponseCacheStrategyTest.php +++ b/Tests/HttpCache/ResponseCacheStrategyTest.php @@ -240,6 +240,7 @@ public function testResponseIsExpirableButNotValidateableWhenMainResponseCombine /** * @group time-sensitive + * * @dataProvider cacheControlMergingProvider */ public function testCacheControlMerging(array $expects, array $master, array $surrogates) diff --git a/Tests/HttpCache/SsiTest.php b/Tests/HttpCache/SsiTest.php index 157c4d7455..8dfc472d23 100644 --- a/Tests/HttpCache/SsiTest.php +++ b/Tests/HttpCache/SsiTest.php @@ -107,7 +107,7 @@ public function testProcess() $response = new Response('foo '); $ssi->process($request, $response); - $this->assertEquals("foo surrogate->handle(\$this, 'foo\\'', '', false) ?>"."\n", $response->getContent()); + $this->assertEquals("foo surrogate->handle(\$this, 'foo\\'', '', false) ?>\n", $response->getContent()); } public function testProcessEscapesPhpTags() From e3a2793ae0e1a6b0ad4c78b7c8935fb24e4a7946 Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Fri, 17 Feb 2023 21:51:27 +0100 Subject: [PATCH 13/31] Fix phpdocs in HttpClient, HttpFoundation, HttpKernel, Intl components --- Fragment/HIncludeFragmentRenderer.php | 2 +- HttpCache/SurrogateInterface.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Fragment/HIncludeFragmentRenderer.php b/Fragment/HIncludeFragmentRenderer.php index 446ce2d9df..bd3eb5cd54 100644 --- a/Fragment/HIncludeFragmentRenderer.php +++ b/Fragment/HIncludeFragmentRenderer.php @@ -30,7 +30,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer private $charset; /** - * @param string $globalDefaultTemplate The global default content (it can be a template name or the content) + * @param string|null $globalDefaultTemplate The global default content (it can be a template name or the content) */ public function __construct(Environment $twig = null, UriSigner $signer = null, string $globalDefaultTemplate = null, string $charset = 'utf-8') { diff --git a/HttpCache/SurrogateInterface.php b/HttpCache/SurrogateInterface.php index 3f3c74a97a..557f4e959e 100644 --- a/HttpCache/SurrogateInterface.php +++ b/HttpCache/SurrogateInterface.php @@ -59,8 +59,8 @@ public function needsParsing(Response $response); /** * Renders a Surrogate tag. * - * @param string $alt An alternate URI - * @param string $comment A comment to add as an esi:include tag + * @param string|null $alt An alternate URI + * @param string $comment A comment to add as an esi:include tag * * @return string */ From 09c19fc7e4218fbcf73fe0330eea38d66064b775 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 28 Feb 2023 14:19:09 +0100 Subject: [PATCH 14/31] Update VERSION for 5.4.21 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 5a95e77848..5f79ffbfbf 100644 --- a/Kernel.php +++ b/Kernel.php @@ -78,12 +78,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static $freshCache = []; - public const VERSION = '5.4.21-DEV'; + public const VERSION = '5.4.21'; public const VERSION_ID = 50421; public const MAJOR_VERSION = 5; 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/2024'; public const END_OF_LIFE = '11/2025'; From 4f82d8d4f3ecf4001b109c99301dabfcef2cf134 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 28 Feb 2023 14:26:05 +0100 Subject: [PATCH 15/31] Bump Symfony version to 5.4.22 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 5f79ffbfbf..7e69e9c746 100644 --- a/Kernel.php +++ b/Kernel.php @@ -78,12 +78,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static $freshCache = []; - public const VERSION = '5.4.21'; - public const VERSION_ID = 50421; + public const VERSION = '5.4.22-DEV'; + public const VERSION_ID = 50422; public const MAJOR_VERSION = 5; 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/2024'; public const END_OF_LIFE = '11/2025'; From ca0680ad1e2d678536cc20e0ae33f9e4e5d2becd Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 28 Feb 2023 14:26:41 +0100 Subject: [PATCH 16/31] Update VERSION for 6.2.7 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 3735cf0b1b..d84a700807 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.2.7-DEV'; + public const VERSION = '6.2.7'; public const VERSION_ID = 60207; public const MAJOR_VERSION = 6; 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/2023'; public const END_OF_LIFE = '07/2023'; From 92f1333e1906d436ddd44820acd4c44d9e20fae6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 28 Feb 2023 15:19:25 +0100 Subject: [PATCH 17/31] Bump Symfony version to 6.2.8 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index d84a700807..20031c5d11 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.2.7'; - public const VERSION_ID = 60207; + public const VERSION = '6.2.8-DEV'; + public const VERSION_ID = 60208; public const MAJOR_VERSION = 6; 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/2023'; public const END_OF_LIFE = '07/2023'; From 1bac251ae4cd8105a8354f578e442f0213ce4f19 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 6 Mar 2023 21:48:01 +0100 Subject: [PATCH 18/31] [Tests] Replace `setMethods()` by `onlyMethods()` and `addMethods()` --- .../DataCollector/LoggerDataCollectorTest.php | 12 ++++++------ Tests/Debug/TraceableEventDispatcherTest.php | 4 ++-- Tests/EventListener/LocaleListenerTest.php | 4 ++-- Tests/HttpCache/EsiTest.php | 2 +- Tests/HttpCache/HttpCacheTest.php | 2 +- Tests/HttpCache/SsiTest.php | 2 +- Tests/HttpKernelBrowserTest.php | 3 ++- Tests/HttpKernelTest.php | 2 +- Tests/KernelTest.php | 19 ++++++++++++------- Tests/Profiler/ProfilerTest.php | 2 +- 10 files changed, 29 insertions(+), 23 deletions(-) diff --git a/Tests/DataCollector/LoggerDataCollectorTest.php b/Tests/DataCollector/LoggerDataCollectorTest.php index 44b740c98b..7dee889110 100644 --- a/Tests/DataCollector/LoggerDataCollectorTest.php +++ b/Tests/DataCollector/LoggerDataCollectorTest.php @@ -26,7 +26,7 @@ public function testCollectWithUnexpectedFormat() { $logger = $this ->getMockBuilder(DebugLoggerInterface::class) - ->setMethods(['countErrors', 'getLogs', 'clear']) + ->onlyMethods(['countErrors', 'getLogs', 'clear']) ->getMock(); $logger->expects($this->once())->method('countErrors')->willReturn(123); $logger->expects($this->exactly(2))->method('getLogs')->willReturn([]); @@ -66,7 +66,7 @@ public function testCollectFromDeprecationsLog() $logger = $this ->getMockBuilder(DebugLoggerInterface::class) - ->setMethods(['countErrors', 'getLogs', 'clear']) + ->onlyMethods(['countErrors', 'getLogs', 'clear']) ->getMock(); $logger->expects($this->once())->method('countErrors')->willReturn(0); @@ -100,7 +100,7 @@ public function testWithMainRequest() $logger = $this ->getMockBuilder(DebugLoggerInterface::class) - ->setMethods(['countErrors', 'getLogs', 'clear']) + ->onlyMethods(['countErrors', 'getLogs', 'clear']) ->getMock(); $logger->expects($this->once())->method('countErrors')->with(null); $logger->expects($this->exactly(2))->method('getLogs')->with(null)->willReturn([]); @@ -121,7 +121,7 @@ public function testWithSubRequest() $logger = $this ->getMockBuilder(DebugLoggerInterface::class) - ->setMethods(['countErrors', 'getLogs', 'clear']) + ->onlyMethods(['countErrors', 'getLogs', 'clear']) ->getMock(); $logger->expects($this->once())->method('countErrors')->with($subRequest); $logger->expects($this->exactly(2))->method('getLogs')->with($subRequest)->willReturn([]); @@ -139,7 +139,7 @@ public function testCollect($nb, $logs, $expectedLogs, $expectedDeprecationCount { $logger = $this ->getMockBuilder(DebugLoggerInterface::class) - ->setMethods(['countErrors', 'getLogs', 'clear']) + ->onlyMethods(['countErrors', 'getLogs', 'clear']) ->getMock(); $logger->expects($this->once())->method('countErrors')->willReturn($nb); $logger->expects($this->exactly(2))->method('getLogs')->willReturn($logs); @@ -171,7 +171,7 @@ public function testReset() { $logger = $this ->getMockBuilder(DebugLoggerInterface::class) - ->setMethods(['countErrors', 'getLogs', 'clear']) + ->onlyMethods(['countErrors', 'getLogs', 'clear']) ->getMock(); $logger->expects($this->once())->method('clear'); diff --git a/Tests/Debug/TraceableEventDispatcherTest.php b/Tests/Debug/TraceableEventDispatcherTest.php index a307bbff55..f37d0f4149 100644 --- a/Tests/Debug/TraceableEventDispatcherTest.php +++ b/Tests/Debug/TraceableEventDispatcherTest.php @@ -48,7 +48,7 @@ public function testStopwatchSections() public function testStopwatchCheckControllerOnRequestEvent() { $stopwatch = $this->getMockBuilder(Stopwatch::class) - ->setMethods(['isStarted']) + ->onlyMethods(['isStarted']) ->getMock(); $stopwatch->expects($this->once()) ->method('isStarted') @@ -64,7 +64,7 @@ public function testStopwatchCheckControllerOnRequestEvent() public function testStopwatchStopControllerOnRequestEvent() { $stopwatch = $this->getMockBuilder(Stopwatch::class) - ->setMethods(['isStarted', 'stop']) + ->onlyMethods(['isStarted', 'stop']) ->getMock(); $stopwatch->expects($this->once()) ->method('isStarted') diff --git a/Tests/EventListener/LocaleListenerTest.php b/Tests/EventListener/LocaleListenerTest.php index 824d906340..04d9517474 100644 --- a/Tests/EventListener/LocaleListenerTest.php +++ b/Tests/EventListener/LocaleListenerTest.php @@ -76,7 +76,7 @@ public function testLocaleSetForRoutingContext() $context = $this->createMock(RequestContext::class); $context->expects($this->once())->method('setParameter')->with('_locale', 'es'); - $router = $this->getMockBuilder(Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); + $router = $this->getMockBuilder(Router::class)->onlyMethods(['getContext'])->disableOriginalConstructor()->getMock(); $router->expects($this->once())->method('getContext')->willReturn($context); $request = Request::create('/'); @@ -92,7 +92,7 @@ public function testRouterResetWithParentRequestOnKernelFinishRequest() $context = $this->createMock(RequestContext::class); $context->expects($this->once())->method('setParameter')->with('_locale', 'es'); - $router = $this->getMockBuilder(Router::class)->setMethods(['getContext'])->disableOriginalConstructor()->getMock(); + $router = $this->getMockBuilder(Router::class)->onlyMethods(['getContext'])->disableOriginalConstructor()->getMock(); $router->expects($this->once())->method('getContext')->willReturn($context); $parentRequest = Request::create('/'); diff --git a/Tests/HttpCache/EsiTest.php b/Tests/HttpCache/EsiTest.php index 32bd3ac7b5..290bd94bdc 100644 --- a/Tests/HttpCache/EsiTest.php +++ b/Tests/HttpCache/EsiTest.php @@ -232,7 +232,7 @@ public function testHandleWhenResponseIsNotModified() protected function getCache($request, $response) { - $cache = $this->getMockBuilder(HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); + $cache = $this->getMockBuilder(HttpCache::class)->onlyMethods(['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 22cf88daa2..2a9f48463c 100644 --- a/Tests/HttpCache/HttpCacheTest.php +++ b/Tests/HttpCache/HttpCacheTest.php @@ -41,7 +41,7 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface() // implements TerminableInterface $kernelMock = $this->getMockBuilder(Kernel::class) ->disableOriginalConstructor() - ->setMethods(['terminate', 'registerBundles', 'registerContainerConfiguration']) + ->onlyMethods(['terminate', 'registerBundles', 'registerContainerConfiguration']) ->getMock(); $kernelMock->expects($this->once()) diff --git a/Tests/HttpCache/SsiTest.php b/Tests/HttpCache/SsiTest.php index 8dfc472d23..a1f1f1593d 100644 --- a/Tests/HttpCache/SsiTest.php +++ b/Tests/HttpCache/SsiTest.php @@ -190,7 +190,7 @@ public function testHandleWhenResponseIsNot200AndAltIsPresent() protected function getCache($request, $response) { - $cache = $this->getMockBuilder(HttpCache::class)->setMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); + $cache = $this->getMockBuilder(HttpCache::class)->onlyMethods(['getRequest', 'handle'])->disableOriginalConstructor()->getMock(); $cache->expects($this->any()) ->method('getRequest') ->willReturn($request) diff --git a/Tests/HttpKernelBrowserTest.php b/Tests/HttpKernelBrowserTest.php index b6e391625c..55963a16c3 100644 --- a/Tests/HttpKernelBrowserTest.php +++ b/Tests/HttpKernelBrowserTest.php @@ -155,7 +155,8 @@ public function testUploadedFileWhenSizeExceedsUploadMaxFileSize() $file = $this ->getMockBuilder(UploadedFile::class) ->setConstructorArgs([$source, 'original', 'mime/original', \UPLOAD_ERR_OK, true]) - ->setMethods(['getSize', 'getClientSize']) + ->onlyMethods(['getSize']) + ->addMethods(['getClientSize']) ->getMock() ; /* should be modified when the getClientSize will be removed */ diff --git a/Tests/HttpKernelTest.php b/Tests/HttpKernelTest.php index 0a1dc60e4a..09e7b9a524 100644 --- a/Tests/HttpKernelTest.php +++ b/Tests/HttpKernelTest.php @@ -361,7 +361,7 @@ public function testVerifyRequestStackPushPopDuringHandle() { $request = new Request(); - $stack = $this->getMockBuilder(RequestStack::class)->setMethods(['push', 'pop'])->getMock(); + $stack = $this->getMockBuilder(RequestStack::class)->onlyMethods(['push', 'pop'])->getMock(); $stack->expects($this->once())->method('push')->with($this->equalTo($request)); $stack->expects($this->once())->method('pop'); diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index fa2074694e..30055163ce 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -148,7 +148,7 @@ public function testBootSetsTheBootedFlagToTrue() public function testClassCacheIsNotLoadedByDefault() { - $kernel = $this->getKernel(['initializeBundles', 'doLoadClassCache']); + $kernel = $this->getKernel(['initializeBundles'], [], false, ['doLoadClassCache']); $kernel->expects($this->never()) ->method('doLoadClassCache'); @@ -449,7 +449,7 @@ public function testTerminateDelegatesTerminationOnlyForTerminableInterface() // implements TerminableInterface $httpKernelMock = $this->getMockBuilder(HttpKernel::class) ->disableOriginalConstructor() - ->setMethods(['terminate']) + ->onlyMethods(['terminate']) ->getMock(); $httpKernelMock @@ -630,7 +630,7 @@ protected function getBundle($dir = null, $parent = null, $className = null, $bu { $bundle = $this ->getMockBuilder(BundleInterface::class) - ->setMethods(['getPath', 'getName']) + ->onlyMethods(['getPath', 'getName']) ->disableOriginalConstructor() ; @@ -661,16 +661,21 @@ protected function getBundle($dir = null, $parent = null, $className = null, $bu * @param array $methods Additional methods to mock (besides the abstract ones) * @param array $bundles Bundles to register */ - protected function getKernel(array $methods = [], array $bundles = [], bool $debug = false): Kernel + protected function getKernel(array $methods = [], array $bundles = [], bool $debug = false, array $methodsToAdd = []): Kernel { $methods[] = 'registerBundles'; - $kernel = $this + $kernelMockBuilder = $this ->getMockBuilder(KernelForTest::class) - ->setMethods($methods) + ->onlyMethods($methods) ->setConstructorArgs(['test', $debug]) - ->getMock() ; + + if (0 !== \count($methodsToAdd)) { + $kernelMockBuilder->addMethods($methodsToAdd); + } + + $kernel = $kernelMockBuilder->getMock(); $kernel->expects($this->any()) ->method('registerBundles') ->willReturn($bundles) diff --git a/Tests/Profiler/ProfilerTest.php b/Tests/Profiler/ProfilerTest.php index dfa5f1e4ed..5512399d4c 100644 --- a/Tests/Profiler/ProfilerTest.php +++ b/Tests/Profiler/ProfilerTest.php @@ -45,7 +45,7 @@ public function testCollect() public function testReset() { $collector = $this->getMockBuilder(DataCollectorInterface::class) - ->setMethods(['collect', 'getName', 'reset']) + ->onlyMethods(['collect', 'getName', 'reset']) ->getMock(); $collector->expects($this->any())->method('getName')->willReturn('mock'); $collector->expects($this->once())->method('reset'); From 80479fe76cc68fb12229072bc462516dee15fdf5 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 6 Mar 2023 20:42:33 +0100 Subject: [PATCH 19/31] [Tests] Remove occurrences of `withConsecutive()` --- .../DebugHandlersListenerTest.php | 8 ++++- .../EventListener/LocaleAwareListenerTest.php | 36 ++++++++++--------- Tests/KernelTest.php | 10 +++--- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Tests/EventListener/DebugHandlersListenerTest.php b/Tests/EventListener/DebugHandlersListenerTest.php index 81a84e92f1..1014c7a180 100644 --- a/Tests/EventListener/DebugHandlersListenerTest.php +++ b/Tests/EventListener/DebugHandlersListenerTest.php @@ -222,7 +222,13 @@ public function testLevelsAssignedToLoggers(bool $hasLogger, bool $hasDeprecatio $handler ->expects($this->exactly(\count($expectedCalls))) ->method('setDefaultLogger') - ->withConsecutive(...$expectedCalls); + ->willReturnCallback(function (LoggerInterface $logger, $levels) use (&$expectedCalls) { + [$expectedLogger, $expectedLevels] = array_shift($expectedCalls); + + $this->assertSame($expectedLogger, $logger); + $this->assertSame($expectedLevels, $levels); + }) + ; $sut = new DebugHandlersListener(null, $logger, $levels, null, true, true, $deprecationLogger); $prevHander = set_exception_handler([$handler, 'handleError']); diff --git a/Tests/EventListener/LocaleAwareListenerTest.php b/Tests/EventListener/LocaleAwareListenerTest.php index 3c89cafd04..f6328e2507 100644 --- a/Tests/EventListener/LocaleAwareListenerTest.php +++ b/Tests/EventListener/LocaleAwareListenerTest.php @@ -46,16 +46,18 @@ public function testLocaleIsSetInOnKernelRequest() public function testDefaultLocaleIsUsedOnExceptionsInOnKernelRequest() { + $matcher = $this->exactly(2); $this->localeAwareService - ->expects($this->exactly(2)) + ->expects($matcher) ->method('setLocale') - ->withConsecutive( - [$this->anything()], - ['en'] - ) - ->willReturnOnConsecutiveCalls( - $this->throwException(new \InvalidArgumentException()) - ); + ->willReturnCallback(function (string $locale) use ($matcher) { + if (1 === $matcher->getInvocationCount()) { + throw new \InvalidArgumentException(); + } + + $this->assertSame('en', $locale); + }) + ; $event = new RequestEvent($this->createMock(HttpKernelInterface::class), $this->createRequest('fr'), HttpKernelInterface::MAIN_REQUEST); $this->listener->onKernelRequest($event); @@ -90,16 +92,18 @@ public function testLocaleIsSetToDefaultOnKernelFinishRequestWhenParentRequestDo public function testDefaultLocaleIsUsedOnExceptionsInOnKernelFinishRequest() { + $matcher = $this->exactly(2); $this->localeAwareService - ->expects($this->exactly(2)) + ->expects($matcher) ->method('setLocale') - ->withConsecutive( - [$this->anything()], - ['en'] - ) - ->willReturnOnConsecutiveCalls( - $this->throwException(new \InvalidArgumentException()) - ); + ->willReturnCallback(function (string $locale) use ($matcher) { + if (1 === $matcher->getInvocationCount()) { + throw new \InvalidArgumentException(); + } + + $this->assertSame('en', $locale); + }) + ; $this->requestStack->push($this->createRequest('fr')); $this->requestStack->push($subRequest = $this->createRequest('de')); diff --git a/Tests/KernelTest.php b/Tests/KernelTest.php index fa2074694e..3ff7bed430 100644 --- a/Tests/KernelTest.php +++ b/Tests/KernelTest.php @@ -182,10 +182,12 @@ public function testShutdownGivesNullContainerToAllBundles() $bundle = $this->createMock(Bundle::class); $bundle->expects($this->exactly(2)) ->method('setContainer') - ->withConsecutive( - [$this->isInstanceOf(ContainerInterface::class)], - [null] - ); + ->willReturnCallback(function ($container) { + if (null !== $container) { + $this->assertInstanceOf(ContainerInterface::class, $container); + } + }) + ; $kernel = $this->getKernel(['getBundles']); $kernel->expects($this->any()) From 13b9831be953c052c6c515a7fd58c7d31979542d Mon Sep 17 00:00:00 2001 From: Lesnykh Ilia Date: Fri, 10 Mar 2023 12:26:07 +0100 Subject: [PATCH 20/31] Change limit argument from string to integer. --- Profiler/Profiler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Profiler/Profiler.php b/Profiler/Profiler.php index 25e126f731..d07b887c02 100644 --- a/Profiler/Profiler.php +++ b/Profiler/Profiler.php @@ -116,7 +116,7 @@ public function purge() /** * Finds profiler tokens for the given criteria. * - * @param string|null $limit The maximum number of tokens to return + * @param int|null $limit The maximum number of tokens to return * @param string|null $start The start date to search from * @param string|null $end The end date to search to * @@ -124,7 +124,7 @@ public function purge() * * @see https://php.net/datetime.formats for the supported date/time formats */ - public function find(?string $ip, ?string $url, ?string $limit, ?string $method, ?string $start, ?string $end, string $statusCode = null) + public function find(?string $ip, ?string $url, ?int $limit, ?string $method, ?string $start, ?string $end, string $statusCode = null) { return $this->storage->find($ip, $url, $limit, $method, $this->getTimestamp($start), $this->getTimestamp($end), $statusCode); } From 3dc322145a80344d2b6c3b9481c72089f7b500e2 Mon Sep 17 00:00:00 2001 From: MatTheCat Date: Thu, 16 Mar 2023 16:48:23 +0100 Subject: [PATCH 21/31] Stop stopwatch events in case of exception --- Controller/TraceableArgumentResolver.php | 10 ++--- Controller/TraceableControllerResolver.php | 10 ++--- .../TraceableArgumentResolverTest.php | 45 +++++++++++++++++++ .../TraceableControllerResolverTest.php | 44 ++++++++++++++++++ 4 files changed, 99 insertions(+), 10 deletions(-) create mode 100644 Tests/Controller/TraceableArgumentResolverTest.php create mode 100644 Tests/Controller/TraceableControllerResolverTest.php diff --git a/Controller/TraceableArgumentResolver.php b/Controller/TraceableArgumentResolver.php index e22cf082c4..859cf3a6f4 100644 --- a/Controller/TraceableArgumentResolver.php +++ b/Controller/TraceableArgumentResolver.php @@ -35,10 +35,10 @@ public function getArguments(Request $request, callable $controller) { $e = $this->stopwatch->start('controller.get_arguments'); - $ret = $this->resolver->getArguments($request, $controller); - - $e->stop(); - - return $ret; + try { + return $this->resolver->getArguments($request, $controller); + } finally { + $e->stop(); + } } } diff --git a/Controller/TraceableControllerResolver.php b/Controller/TraceableControllerResolver.php index bf6b6aa1f2..013dfe2361 100644 --- a/Controller/TraceableControllerResolver.php +++ b/Controller/TraceableControllerResolver.php @@ -35,10 +35,10 @@ public function getController(Request $request) { $e = $this->stopwatch->start('controller.get_callable'); - $ret = $this->resolver->getController($request); - - $e->stop(); - - return $ret; + try { + return $this->resolver->getController($request); + } finally { + $e->stop(); + } } } diff --git a/Tests/Controller/TraceableArgumentResolverTest.php b/Tests/Controller/TraceableArgumentResolverTest.php new file mode 100644 index 0000000000..6de47bd1f4 --- /dev/null +++ b/Tests/Controller/TraceableArgumentResolverTest.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Controller; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface; +use Symfony\Component\HttpKernel\Controller\TraceableArgumentResolver; +use Symfony\Component\Stopwatch\Stopwatch; +use Symfony\Component\Stopwatch\StopwatchEvent; + +class TraceableArgumentResolverTest extends TestCase +{ + public function testStopwatchEventIsStoppedWhenResolverThrows() + { + $stopwatchEvent = $this->createMock(StopwatchEvent::class); + $stopwatchEvent->expects(self::once())->method('stop'); + + $stopwatch = $this->createStub(Stopwatch::class); + $stopwatch->method('start')->willReturn($stopwatchEvent); + + $resolver = new class() implements ArgumentResolverInterface { + public function getArguments(Request $request, callable $controller) + { + throw new \Exception(); + } + }; + + $traceableResolver = new TraceableArgumentResolver($resolver, $stopwatch); + + try { + $traceableResolver->getArguments(new Request(), function () {}); + } catch (\Exception $ex) { + } + } +} diff --git a/Tests/Controller/TraceableControllerResolverTest.php b/Tests/Controller/TraceableControllerResolverTest.php new file mode 100644 index 0000000000..707d06bc6e --- /dev/null +++ b/Tests/Controller/TraceableControllerResolverTest.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Controller; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; +use Symfony\Component\HttpKernel\Controller\TraceableControllerResolver; +use Symfony\Component\Stopwatch\Stopwatch; +use Symfony\Component\Stopwatch\StopwatchEvent; + +class TraceableControllerResolverTest extends TestCase +{ + public function testStopwatchEventIsStoppedWhenResolverThrows() + { + $stopwatchEvent = $this->createMock(StopwatchEvent::class); + $stopwatchEvent->expects(self::once())->method('stop'); + + $stopwatch = $this->createStub(Stopwatch::class); + $stopwatch->method('start')->willReturn($stopwatchEvent); + + $resolver = new class() implements ControllerResolverInterface { + public function getController(Request $request) + { + throw new \Exception(); + } + }; + + $traceableResolver = new TraceableControllerResolver($resolver, $stopwatch); + try { + $traceableResolver->getController(new Request()); + } catch (\Exception $ex) { + } + } +} From d249592068726c07726267b364bc966edfca55c0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 20 Mar 2023 17:10:32 +0100 Subject: [PATCH 22/31] Fix merge --- Tests/Controller/TraceableArgumentResolverTest.php | 2 +- Tests/Controller/TraceableControllerResolverTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Controller/TraceableArgumentResolverTest.php b/Tests/Controller/TraceableArgumentResolverTest.php index 6de47bd1f4..43bbb13e6b 100644 --- a/Tests/Controller/TraceableArgumentResolverTest.php +++ b/Tests/Controller/TraceableArgumentResolverTest.php @@ -29,7 +29,7 @@ public function testStopwatchEventIsStoppedWhenResolverThrows() $stopwatch->method('start')->willReturn($stopwatchEvent); $resolver = new class() implements ArgumentResolverInterface { - public function getArguments(Request $request, callable $controller) + public function getArguments(Request $request, callable $controller): array { throw new \Exception(); } diff --git a/Tests/Controller/TraceableControllerResolverTest.php b/Tests/Controller/TraceableControllerResolverTest.php index 707d06bc6e..ecd4a23736 100644 --- a/Tests/Controller/TraceableControllerResolverTest.php +++ b/Tests/Controller/TraceableControllerResolverTest.php @@ -29,7 +29,7 @@ public function testStopwatchEventIsStoppedWhenResolverThrows() $stopwatch->method('start')->willReturn($stopwatchEvent); $resolver = new class() implements ControllerResolverInterface { - public function getController(Request $request) + public function getController(Request $request): callable|false { throw new \Exception(); } From 2d3a8be2c756353627398827c409af6f126c096d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 31 Mar 2023 13:54:37 +0200 Subject: [PATCH 23/31] Update VERSION for 5.4.22 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 7e69e9c746..30b3db27b3 100644 --- a/Kernel.php +++ b/Kernel.php @@ -78,12 +78,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static $freshCache = []; - public const VERSION = '5.4.22-DEV'; + public const VERSION = '5.4.22'; public const VERSION_ID = 50422; public const MAJOR_VERSION = 5; 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/2024'; public const END_OF_LIFE = '11/2025'; From e4651b2ee8bed28483252a0f51edb288a9b33e2d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 31 Mar 2023 13:59:10 +0200 Subject: [PATCH 24/31] Bump Symfony version to 5.4.23 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 30b3db27b3..4fca2b499d 100644 --- a/Kernel.php +++ b/Kernel.php @@ -78,12 +78,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static $freshCache = []; - public const VERSION = '5.4.22'; - public const VERSION_ID = 50422; + public const VERSION = '5.4.23-DEV'; + public const VERSION_ID = 50423; public const MAJOR_VERSION = 5; 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/2024'; public const END_OF_LIFE = '11/2025'; From 9563229e56076070d92ca30c089e801e8a4629a3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 31 Mar 2023 14:00:10 +0200 Subject: [PATCH 25/31] Update VERSION for 6.2.8 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 20031c5d11..1b0c6224b0 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.2.8-DEV'; + public const VERSION = '6.2.8'; public const VERSION_ID = 60208; public const MAJOR_VERSION = 6; 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/2023'; public const END_OF_LIFE = '07/2023'; From b1415c734feaa3f73f919648010794e06975a09e Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 31 Mar 2023 14:04:41 +0200 Subject: [PATCH 26/31] Bump Symfony version to 6.2.9 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 1b0c6224b0..47c30e254b 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.2.8'; - public const VERSION_ID = 60208; + public const VERSION = '6.2.9-DEV'; + public const VERSION_ID = 60209; public const MAJOR_VERSION = 6; 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/2023'; public const END_OF_LIFE = '07/2023'; From 02246510cf7031726f7237138d61b796b95799b3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 13 Apr 2023 18:41:43 +0200 Subject: [PATCH 27/31] Update VERSION for 6.2.9 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index 47c30e254b..1500b8ff02 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.2.9-DEV'; + public const VERSION = '6.2.9'; public const VERSION_ID = 60209; public const MAJOR_VERSION = 6; 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/2023'; public const END_OF_LIFE = '07/2023'; From cb3d56a696c85ecaf8e0b6a655912d602ed9d49d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 13 Apr 2023 18:47:34 +0200 Subject: [PATCH 28/31] Bump Symfony version to 6.2.10 --- Kernel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Kernel.php b/Kernel.php index 1500b8ff02..fbce432cb7 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.2.9'; - public const VERSION_ID = 60209; + public const VERSION = '6.2.10-DEV'; + public const VERSION_ID = 60210; public const MAJOR_VERSION = 6; 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/2023'; public const END_OF_LIFE = '07/2023'; From d55efe912b5570edcb8627f33f019ab87d61bdcd Mon Sep 17 00:00:00 2001 From: Gordienko Vladislav Date: Sun, 1 Jan 2023 20:41:23 +0500 Subject: [PATCH 29/31] [HttpKernel] Tests for DataCollector --- DataCollector/TimeDataCollector.php | 3 +- .../DataCollector/RouterDataCollectorTest.php | 80 ++++++++++++++ Tests/DataCollector/TimeDataCollectorTest.php | 101 ++++++++++++++++++ 3 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 Tests/DataCollector/RouterDataCollectorTest.php diff --git a/DataCollector/TimeDataCollector.php b/DataCollector/TimeDataCollector.php index 43799060f6..fa8bb4a52a 100644 --- a/DataCollector/TimeDataCollector.php +++ b/DataCollector/TimeDataCollector.php @@ -31,6 +31,7 @@ public function __construct(KernelInterface $kernel = null, Stopwatch $stopwatch { $this->kernel = $kernel; $this->stopwatch = $stopwatch; + $this->data = ['events' => [], 'stopwatch_installed' => false, 'start_time' => 0]; } /** @@ -57,7 +58,7 @@ public function collect(Request $request, Response $response, \Throwable $except */ public function reset() { - $this->data = []; + $this->data = ['events' => [], 'stopwatch_installed' => false, 'start_time' => 0]; if (null !== $this->stopwatch) { $this->stopwatch->reset(); diff --git a/Tests/DataCollector/RouterDataCollectorTest.php b/Tests/DataCollector/RouterDataCollectorTest.php new file mode 100644 index 0000000000..e073f6867d --- /dev/null +++ b/Tests/DataCollector/RouterDataCollectorTest.php @@ -0,0 +1,80 @@ +createControllerEvent($request); + + $collector->onKernelController($event); + $collector->collect($request, $response); + + $this->assertTrue($collector->getRedirect()); + $this->assertEquals('http://test.com/redirect', $collector->getTargetUrl()); + $this->assertEquals('n/a', $collector->getTargetRoute()); + } + + public function testRouteNotRedirectResponse() + { + $collector = new RouterDataCollector(); + + $request = Request::create('http://test.com/foo?bar=baz'); + $response = new Response('test'); + + $event = $this->createControllerEvent($request); + + $collector->onKernelController($event); + $collector->collect($request, $response); + + $this->assertFalse($collector->getRedirect()); + $this->assertNull($collector->getTargetUrl()); + $this->assertNull($collector->getTargetRoute()); + } + + public function testReset() + { + $collector = new RouterDataCollector(); + + // Fill Collector + $request = Request::create('http://test.com/foo?bar=baz'); + $response = new RedirectResponse('http://test.com/redirect'); + $event = $this->createControllerEvent($request); + $collector->onKernelController($event); + $collector->collect($request, $response); + + $collector->reset(); + + $this->assertFalse($collector->getRedirect()); + $this->assertNull($collector->getTargetUrl()); + $this->assertNull($collector->getTargetRoute()); + } + + public function testGetName() + { + $collector = new RouterDataCollector(); + + $this->assertEquals('router', $collector->getName()); + } + + protected function createControllerEvent(Request $request): ControllerEvent + { + $kernel = $this->createMock(KernelInterface::class); + + return new ControllerEvent($kernel, function () {}, $request, null); + } +} diff --git a/Tests/DataCollector/TimeDataCollectorTest.php b/Tests/DataCollector/TimeDataCollectorTest.php index 0496f1a3d1..50657f742b 100644 --- a/Tests/DataCollector/TimeDataCollectorTest.php +++ b/Tests/DataCollector/TimeDataCollectorTest.php @@ -17,6 +17,7 @@ use Symfony\Component\HttpKernel\DataCollector\TimeDataCollector; use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\Stopwatch\Stopwatch; +use Symfony\Component\Stopwatch\StopwatchEvent; /** * @group time-sensitive @@ -55,4 +56,104 @@ public function testCollect() $this->assertEquals(123456000, $c->getStartTime()); $this->assertSame(class_exists(Stopwatch::class, false), $c->isStopwatchInstalled()); } + + public function testReset() + { + $collector = new TimeDataCollector(); + + // Fill Collector + $request = Request::create('http://test.com/foo?bar=baz'); + $response = new Response('test'); + $collector->collect($request, $response); + + $collector->reset(); + + $this->assertEquals([], $collector->getEvents()); + $this->assertEquals(0, $collector->getStartTime()); + $this->assertFalse($collector->isStopwatchInstalled()); + } + + public function testLateCollect() + { + $stopwatch = new Stopwatch(); + $stopwatch->start('test'); + + $collector = new TimeDataCollector(null, $stopwatch); + + $request = new Request(); + $request->attributes->set('_stopwatch_token', '__root__'); + + $collector->collect($request, new Response()); + $collector->lateCollect(); + + $this->assertEquals(['test'], array_keys($collector->getEvents())); + } + + public function testSetEvents() + { + $collector = new TimeDataCollector(); + + $event = $this->createMock(StopwatchEvent::class); + $event->expects($this->once())->method('ensureStopped'); + + $events = [$event]; + + $collector->setEvents($events); + + $this->assertCount(1, $collector->getEvents()); + } + + public function testGetDurationHasEvents() + { + $collector = new TimeDataCollector(); + + $request = new Request(); + $request->server->set('REQUEST_TIME_FLOAT', 1); + $collector->collect($request, new Response()); + + $event = $this->createMock(StopwatchEvent::class); + $event->expects($this->once())->method('getDuration')->willReturn(2000.0); + $event->expects($this->once())->method('getOrigin')->willReturn(1000.0); + $events = ['__section__' => $event]; + $collector->setEvents($events); + + $this->assertEquals(1000 + 2000 - 1000, $collector->getDuration()); + } + + public function testGetDurationNotEvents() + { + $collector = new TimeDataCollector(); + + $this->assertEquals(0, $collector->getDuration()); + } + + public function testGetInitTimeNotEvents() + { + $collector = new TimeDataCollector(); + + $this->assertEquals(0, $collector->getInitTime()); + } + + public function testGetInitTimeHasEvents() + { + $collector = new TimeDataCollector(); + + $request = new Request(); + $request->server->set('REQUEST_TIME_FLOAT', 1); + $collector->collect($request, new Response()); + + $event = $this->createMock(StopwatchEvent::class); + $event->expects($this->once())->method('getOrigin')->willReturn(2000.0); + $events = ['__section__' => $event]; + $collector->setEvents($events); + + $this->assertEquals(2000 - 1000, $collector->getInitTime()); + } + + public function testGetName() + { + $collector = new TimeDataCollector(); + + $this->assertEquals('time', $collector->getName()); + } } From f184280fe1c93aa7e202043d437f12cb056dbeff Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 18 Apr 2023 15:53:46 +0200 Subject: [PATCH 30/31] CS fix --- Tests/DataCollector/RouterDataCollectorTest.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Tests/DataCollector/RouterDataCollectorTest.php b/Tests/DataCollector/RouterDataCollectorTest.php index e073f6867d..d716ea15f1 100644 --- a/Tests/DataCollector/RouterDataCollectorTest.php +++ b/Tests/DataCollector/RouterDataCollectorTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\HttpKernel\Tests\DataCollector; use PHPUnit\Framework\TestCase; @@ -16,7 +25,7 @@ public function testRouteRedirectResponse() { $collector = new RouterDataCollector(); - $request = Request::create('http://test.com/foo?bar=baz'); + $request = Request::create('http://test.com/foo?bar=baz'); $response = new RedirectResponse('http://test.com/redirect'); $event = $this->createControllerEvent($request); @@ -33,7 +42,7 @@ public function testRouteNotRedirectResponse() { $collector = new RouterDataCollector(); - $request = Request::create('http://test.com/foo?bar=baz'); + $request = Request::create('http://test.com/foo?bar=baz'); $response = new Response('test'); $event = $this->createControllerEvent($request); @@ -51,9 +60,9 @@ public function testReset() $collector = new RouterDataCollector(); // Fill Collector - $request = Request::create('http://test.com/foo?bar=baz'); + $request = Request::create('http://test.com/foo?bar=baz'); $response = new RedirectResponse('http://test.com/redirect'); - $event = $this->createControllerEvent($request); + $event = $this->createControllerEvent($request); $collector->onKernelController($event); $collector->collect($request, $response); From 81064a65a5496f17d2b6984f6519406f98864215 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 28 Apr 2023 15:50:28 +0200 Subject: [PATCH 31/31] Update VERSION for 6.2.10 --- Kernel.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel.php b/Kernel.php index fbce432cb7..e9694e978e 100644 --- a/Kernel.php +++ b/Kernel.php @@ -75,12 +75,12 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl */ private static array $freshCache = []; - public const VERSION = '6.2.10-DEV'; + public const VERSION = '6.2.10'; public const VERSION_ID = 60210; public const MAJOR_VERSION = 6; 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/2023'; public const END_OF_LIFE = '07/2023';