From e967c07eade67be68b58caa73e779a3926fc2492 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 8 Sep 2024 18:56:12 +0200 Subject: [PATCH 1/7] Remove obsolete requires annotation --- Tests/Functional/Psr4RoutingTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tests/Functional/Psr4RoutingTest.php b/Tests/Functional/Psr4RoutingTest.php index 811a99a11..6104a52ce 100644 --- a/Tests/Functional/Psr4RoutingTest.php +++ b/Tests/Functional/Psr4RoutingTest.php @@ -11,9 +11,6 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Functional; -/** - * @requires function Symfony\Component\Routing\Loader\Psr4DirectoryLoader::__construct - */ final class Psr4RoutingTest extends AbstractAttributeRoutingTestCase { protected function getTestCaseApp(): string From 8bd84c5faf8385db988d23c52cb0e5db2c8a27f8 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 10 Sep 2024 10:17:27 +0200 Subject: [PATCH 2/7] Work around parse_url() bug --- Controller/RedirectController.php | 11 ++++++++--- Tests/Controller/RedirectControllerTest.php | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Controller/RedirectController.php b/Controller/RedirectController.php index 702d69748..3d8efe0de 100644 --- a/Controller/RedirectController.php +++ b/Controller/RedirectController.php @@ -119,14 +119,19 @@ public function urlRedirectAction(Request $request, string $path, bool $permanen $statusCode = $permanent ? 301 : 302; } + if (null === $scheme) { + $scheme = $request->getScheme(); + } + + if (str_starts_with($path, '//')) { + $path = $scheme.':'.$path; + } + // redirect if the path is a full URL if (parse_url($path, \PHP_URL_SCHEME)) { return new RedirectResponse($path, $statusCode); } - if (null === $scheme) { - $scheme = $request->getScheme(); - } if ($qs = $request->server->get('QUERY_STRING') ?: $request->getQueryString()) { if (!str_contains($path, '?')) { diff --git a/Tests/Controller/RedirectControllerTest.php b/Tests/Controller/RedirectControllerTest.php index b2da9ef58..161424e0e 100644 --- a/Tests/Controller/RedirectControllerTest.php +++ b/Tests/Controller/RedirectControllerTest.php @@ -183,6 +183,20 @@ public function testFullURLWithMethodKeep() $this->assertEquals(307, $returnResponse->getStatusCode()); } + public function testProtocolRelative() + { + $request = new Request(); + $controller = new RedirectController(); + + $returnResponse = $controller->urlRedirectAction($request, '//foo.bar/'); + $this->assertRedirectUrl($returnResponse, 'http://foo.bar/'); + $this->assertSame(302, $returnResponse->getStatusCode()); + + $returnResponse = $controller->urlRedirectAction($request, '//foo.bar/', false, 'https'); + $this->assertRedirectUrl($returnResponse, 'https://foo.bar/'); + $this->assertSame(302, $returnResponse->getStatusCode()); + } + public function testUrlRedirectDefaultPorts() { $host = 'www.example.com'; From 32c98b3b22c425376743fa19003811cd96771e29 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Thu, 12 Sep 2024 06:15:22 +0200 Subject: [PATCH 3/7] [FrameworkBundle] Fix service reset between tests --- Test/KernelTestCase.php | 5 ++++ .../ResettableService.php | 27 +++++++++++++++++++ Tests/Functional/KernelTestCaseTest.php | 11 ++++++++ .../app/TestServiceContainer/services.yml | 5 ++++ composer.json | 2 +- 5 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Tests/Functional/Bundle/TestBundle/TestServiceContainer/ResettableService.php diff --git a/Test/KernelTestCase.php b/Test/KernelTestCase.php index 456085014..89dbd40af 100644 --- a/Test/KernelTestCase.php +++ b/Test/KernelTestCase.php @@ -160,6 +160,11 @@ protected static function ensureKernelShutdown() static::$kernel->shutdown(); static::$booted = false; + if ($container->has('services_resetter')) { + // Instantiate the service because Container::reset() only resets services that have been used + $container->get('services_resetter'); + } + if ($container instanceof ResetInterface) { $container->reset(); } diff --git a/Tests/Functional/Bundle/TestBundle/TestServiceContainer/ResettableService.php b/Tests/Functional/Bundle/TestBundle/TestServiceContainer/ResettableService.php new file mode 100644 index 000000000..e723da81e --- /dev/null +++ b/Tests/Functional/Bundle/TestBundle/TestServiceContainer/ResettableService.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer; + +class ResettableService +{ + private $count = 0; + + public function myCustomName(): void + { + ++$this->count; + } + + public function getCount(): int + { + return $this->count; + } +} diff --git a/Tests/Functional/KernelTestCaseTest.php b/Tests/Functional/KernelTestCaseTest.php index 32bee3b58..5c979a2d0 100644 --- a/Tests/Functional/KernelTestCaseTest.php +++ b/Tests/Functional/KernelTestCaseTest.php @@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\NonPublicService; use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService; use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PublicService; +use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\ResettableService; use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\UnusedPrivateService; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -41,4 +42,14 @@ public function testThatPrivateServicesAreAvailableIfTestConfigIsEnabled() $this->assertTrue($container->has('private_service')); $this->assertFalse($container->has(UnusedPrivateService::class)); } + + public function testServicesAreResetOnEnsureKernelShutdown() + { + static::bootKernel(['test_case' => 'TestServiceContainer']); + + $resettableService = static::getContainer()->get(ResettableService::class); + + self::ensureKernelShutdown(); + self::assertSame(1, $resettableService->getCount()); + } } diff --git a/Tests/Functional/app/TestServiceContainer/services.yml b/Tests/Functional/app/TestServiceContainer/services.yml index 523cca58d..c2b6f3698 100644 --- a/Tests/Functional/app/TestServiceContainer/services.yml +++ b/Tests/Functional/app/TestServiceContainer/services.yml @@ -13,3 +13,8 @@ services: arguments: - '@Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\NonPublicService' - '@Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\PrivateService' + + Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\TestServiceContainer\ResettableService: + public: true + tags: + - kernel.reset: { method: 'myCustomName' } diff --git a/composer.json b/composer.json index c1f08b183..3bae1c386 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "ext-xml": "*", "symfony/cache": "^5.2|^6.0", "symfony/config": "^5.3|^6.0", - "symfony/dependency-injection": "^5.4.5|^6.0.5", + "symfony/dependency-injection": "^5.4.44|^6.0.5", "symfony/deprecation-contracts": "^2.1|^3", "symfony/event-dispatcher": "^5.1|^6.0", "symfony/error-handler": "^4.4.1|^5.0.1|^6.0", From 2f1b7a7ec50337d9b681427fe13a66b1abbb36b0 Mon Sep 17 00:00:00 2001 From: HypeMC Date: Fri, 13 Sep 2024 03:03:54 +0200 Subject: [PATCH 4/7] [FrameworkBundle] Fix schema & finish incomplete tests for lock & semaphore config --- .../DependencyInjection/Fixtures/php/lock.php | 9 +++ .../Fixtures/php/lock_named.php | 16 ++++++ .../Fixtures/php/semaphore.php | 9 +++ .../Fixtures/php/semaphore_named.php | 14 +++++ .../DependencyInjection/Fixtures/xml/lock.xml | 4 +- .../Fixtures/xml/lock_named.xml | 3 +- .../Fixtures/xml/semaphore.xml | 4 +- .../Fixtures/xml/semaphore_named.xml | 16 ++++++ .../FrameworkExtensionTestCase.php | 56 +++++++++++++++++++ 9 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 Tests/DependencyInjection/Fixtures/php/lock.php create mode 100644 Tests/DependencyInjection/Fixtures/php/lock_named.php create mode 100644 Tests/DependencyInjection/Fixtures/php/semaphore.php create mode 100644 Tests/DependencyInjection/Fixtures/php/semaphore_named.php create mode 100644 Tests/DependencyInjection/Fixtures/xml/semaphore_named.xml diff --git a/Tests/DependencyInjection/Fixtures/php/lock.php b/Tests/DependencyInjection/Fixtures/php/lock.php new file mode 100644 index 000000000..116e074df --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/php/lock.php @@ -0,0 +1,9 @@ +loadFromExtension('framework', [ + 'annotations' => false, + 'http_method_override' => false, + 'handle_all_throwables' => true, + 'php_errors' => ['log' => true], + 'lock' => null, +]); diff --git a/Tests/DependencyInjection/Fixtures/php/lock_named.php b/Tests/DependencyInjection/Fixtures/php/lock_named.php new file mode 100644 index 000000000..de8a8f495 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/php/lock_named.php @@ -0,0 +1,16 @@ +setParameter('env(REDIS_DSN)', 'redis://paas.com'); + +$container->loadFromExtension('framework', [ + 'annotations' => false, + 'http_method_override' => false, + 'handle_all_throwables' => true, + 'php_errors' => ['log' => true], + 'lock' => [ + 'foo' => 'semaphore', + 'bar' => 'flock', + 'baz' => ['semaphore', 'flock'], + 'qux' => '%env(REDIS_DSN)%', + ], +]); diff --git a/Tests/DependencyInjection/Fixtures/php/semaphore.php b/Tests/DependencyInjection/Fixtures/php/semaphore.php new file mode 100644 index 000000000..c2a1e3b6e --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/php/semaphore.php @@ -0,0 +1,9 @@ +loadFromExtension('framework', [ + 'annotations' => false, + 'http_method_override' => false, + 'handle_all_throwables' => true, + 'php_errors' => ['log' => true], + 'semaphore' => 'redis://localhost', +]); diff --git a/Tests/DependencyInjection/Fixtures/php/semaphore_named.php b/Tests/DependencyInjection/Fixtures/php/semaphore_named.php new file mode 100644 index 000000000..c42b55983 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/php/semaphore_named.php @@ -0,0 +1,14 @@ +setParameter('env(REDIS_DSN)', 'redis://paas.com'); + +$container->loadFromExtension('framework', [ + 'annotations' => false, + 'http_method_override' => false, + 'handle_all_throwables' => true, + 'php_errors' => ['log' => true], + 'semaphore' => [ + 'foo' => 'redis://paas.com', + 'qux' => '%env(REDIS_DSN)%', + ], +]); diff --git a/Tests/DependencyInjection/Fixtures/xml/lock.xml b/Tests/DependencyInjection/Fixtures/xml/lock.xml index 5ddb62f11..ab344ae0e 100644 --- a/Tests/DependencyInjection/Fixtures/xml/lock.xml +++ b/Tests/DependencyInjection/Fixtures/xml/lock.xml @@ -8,6 +8,8 @@ - + + semaphore + diff --git a/Tests/DependencyInjection/Fixtures/xml/lock_named.xml b/Tests/DependencyInjection/Fixtures/xml/lock_named.xml index 85cf3cb57..02659713e 100644 --- a/Tests/DependencyInjection/Fixtures/xml/lock_named.xml +++ b/Tests/DependencyInjection/Fixtures/xml/lock_named.xml @@ -5,7 +5,6 @@ xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - redis://paas.com @@ -18,7 +17,7 @@ flock semaphore flock - %env(REDIS_URL)% + %env(REDIS_DSN)% diff --git a/Tests/DependencyInjection/Fixtures/xml/semaphore.xml b/Tests/DependencyInjection/Fixtures/xml/semaphore.xml index 7acbe2ced..dcab80326 100644 --- a/Tests/DependencyInjection/Fixtures/xml/semaphore.xml +++ b/Tests/DependencyInjection/Fixtures/xml/semaphore.xml @@ -8,6 +8,8 @@ - + + redis://localhost + diff --git a/Tests/DependencyInjection/Fixtures/xml/semaphore_named.xml b/Tests/DependencyInjection/Fixtures/xml/semaphore_named.xml new file mode 100644 index 000000000..7e454c2fd --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/xml/semaphore_named.xml @@ -0,0 +1,16 @@ + + + + + + + + redis://paas.com + %env(REDIS_DSN)% + + + diff --git a/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/Tests/DependencyInjection/FrameworkExtensionTestCase.php index 705ec5f31..e6616a07d 100644 --- a/Tests/DependencyInjection/FrameworkExtensionTestCase.php +++ b/Tests/DependencyInjection/FrameworkExtensionTestCase.php @@ -2396,6 +2396,62 @@ public function testAssetMapperWithoutAssets() $this->assertFalse($container->has('assets._default_package')); } + public function testDefaultLock() + { + $container = $this->createContainerFromFile('lock'); + + self::assertTrue($container->hasDefinition('lock.default.factory')); + $storeDef = $container->getDefinition($container->getDefinition('lock.default.factory')->getArgument(0)); + self::assertEquals(new Reference('semaphore'), $storeDef->getArgument(0)); + } + + public function testNamedLocks() + { + $container = $this->createContainerFromFile('lock_named'); + + self::assertTrue($container->hasDefinition('lock.foo.factory')); + $storeDef = $container->getDefinition($container->getDefinition('lock.foo.factory')->getArgument(0)); + self::assertEquals(new Reference('semaphore'), $storeDef->getArgument(0)); + + self::assertTrue($container->hasDefinition('lock.bar.factory')); + $storeDef = $container->getDefinition($container->getDefinition('lock.bar.factory')->getArgument(0)); + self::assertEquals(new Reference('flock'), $storeDef->getArgument(0)); + + self::assertTrue($container->hasDefinition('lock.baz.factory')); + $storeDef = $container->getDefinition($container->getDefinition('lock.baz.factory')->getArgument(0)); + self::assertIsArray($storeDefArg = $storeDef->getArgument(0)); + $storeDef1 = $container->getDefinition($storeDefArg[0]); + $storeDef2 = $container->getDefinition($storeDefArg[1]); + self::assertEquals(new Reference('semaphore'), $storeDef1->getArgument(0)); + self::assertEquals(new Reference('flock'), $storeDef2->getArgument(0)); + + self::assertTrue($container->hasDefinition('lock.qux.factory')); + $storeDef = $container->getDefinition($container->getDefinition('lock.qux.factory')->getArgument(0)); + self::assertStringContainsString('REDIS_DSN', $storeDef->getArgument(0)); + } + + public function testDefaultSemaphore() + { + $container = $this->createContainerFromFile('semaphore'); + + self::assertTrue($container->hasDefinition('semaphore.default.factory')); + $storeDef = $container->getDefinition($container->getDefinition('semaphore.default.factory')->getArgument(0)); + self::assertSame('redis://localhost', $storeDef->getArgument(0)); + } + + public function testNamedSemaphores() + { + $container = $this->createContainerFromFile('semaphore_named'); + + self::assertTrue($container->hasDefinition('semaphore.foo.factory')); + $storeDef = $container->getDefinition($container->getDefinition('semaphore.foo.factory')->getArgument(0)); + self::assertSame('redis://paas.com', $storeDef->getArgument(0)); + + self::assertTrue($container->hasDefinition('semaphore.qux.factory')); + $storeDef = $container->getDefinition($container->getDefinition('semaphore.qux.factory')->getArgument(0)); + self::assertStringContainsString('REDIS_DSN', $storeDef->getArgument(0)); + } + protected function createContainer(array $data = []) { return new ContainerBuilder(new EnvPlaceholderParameterBag(array_merge([ From d022058d94f0c16ed28b1ac158720d3d042deb35 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 17 Sep 2024 13:49:18 +0200 Subject: [PATCH 5/7] fix XSD to allow to configure locks without resources --- Resources/config/schema/symfony-1.0.xsd | 2 +- Tests/DependencyInjection/Fixtures/php/lock.php | 5 +++++ .../FrameworkExtensionTestCase.php | 15 +++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 Tests/DependencyInjection/Fixtures/php/lock.php diff --git a/Resources/config/schema/symfony-1.0.xsd b/Resources/config/schema/symfony-1.0.xsd index 60e87a1bc..66596679a 100644 --- a/Resources/config/schema/symfony-1.0.xsd +++ b/Resources/config/schema/symfony-1.0.xsd @@ -492,7 +492,7 @@ - + diff --git a/Tests/DependencyInjection/Fixtures/php/lock.php b/Tests/DependencyInjection/Fixtures/php/lock.php new file mode 100644 index 000000000..ddcb443b6 --- /dev/null +++ b/Tests/DependencyInjection/Fixtures/php/lock.php @@ -0,0 +1,5 @@ +loadFromExtension('framework', [ + 'lock' => null, +]); diff --git a/Tests/DependencyInjection/FrameworkExtensionTestCase.php b/Tests/DependencyInjection/FrameworkExtensionTestCase.php index 7555b7530..26dec07bc 100644 --- a/Tests/DependencyInjection/FrameworkExtensionTestCase.php +++ b/Tests/DependencyInjection/FrameworkExtensionTestCase.php @@ -52,6 +52,7 @@ use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\HttpKernel\DependencyInjection\LoggerPass; use Symfony\Component\HttpKernel\Fragment\FragmentUriGeneratorInterface; +use Symfony\Component\Lock\Store\SemaphoreStore; use Symfony\Component\Messenger\Transport\TransportFactory; use Symfony\Component\Notifier\ChatterInterface; use Symfony\Component\Notifier\TexterInterface; @@ -2081,6 +2082,20 @@ public function testIfNotifierTransportsAreKnownByFrameworkExtension() } } + public function testDefaultLock() + { + $container = $this->createContainerFromFile('lock'); + + self::assertTrue($container->hasDefinition('lock.default.factory')); + $storeDef = $container->getDefinition($container->getDefinition('lock.default.factory')->getArgument(0)); + + if (class_exists(SemaphoreStore::class) && SemaphoreStore::isSupported()) { + self::assertEquals(new Reference('semaphore'), $storeDef->getArgument(0)); + } else { + self::assertEquals(new Reference('flock'), $storeDef->getArgument(0)); + } + } + protected function createContainer(array $data = []) { return new ContainerBuilder(new EnvPlaceholderParameterBag(array_merge([ From f40274b9b398c21d80c96c658a1a68883a9c6606 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Tue, 17 Sep 2024 22:24:34 +0200 Subject: [PATCH 6/7] fix merge --- Tests/DependencyInjection/Fixtures/xml/lock.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Tests/DependencyInjection/Fixtures/xml/lock.xml b/Tests/DependencyInjection/Fixtures/xml/lock.xml index ab344ae0e..2796cb3f9 100644 --- a/Tests/DependencyInjection/Fixtures/xml/lock.xml +++ b/Tests/DependencyInjection/Fixtures/xml/lock.xml @@ -8,8 +8,6 @@ - - semaphore - + From 9ae1957fb817c0fec6d171931f675895a434d988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Fri, 20 Sep 2024 10:11:35 +0200 Subject: [PATCH 7/7] [FrameworkBundle] Do not access the container when the kernel is shut down --- Test/KernelTestCase.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Test/KernelTestCase.php b/Test/KernelTestCase.php index 89dbd40af..d44d77b67 100644 --- a/Test/KernelTestCase.php +++ b/Test/KernelTestCase.php @@ -157,14 +157,15 @@ protected static function ensureKernelShutdown() if (null !== static::$kernel) { static::$kernel->boot(); $container = static::$kernel->getContainer(); - static::$kernel->shutdown(); - static::$booted = false; if ($container->has('services_resetter')) { // Instantiate the service because Container::reset() only resets services that have been used $container->get('services_resetter'); } + static::$kernel->shutdown(); + static::$booted = false; + if ($container instanceof ResetInterface) { $container->reset(); }