From 7943c39040574bedd78db68f2f198274c577b980 Mon Sep 17 00:00:00 2001 From: Antoine Apollis Date: Thu, 13 Oct 2022 16:26:38 +0200 Subject: [PATCH] [Routing] Fix TypeError when using UrlGenerator --- src/Symfony/Component/Routing/Router.php | 5 ++-- .../Component/Routing/Tests/RouterTest.php | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Routing/Router.php b/src/Symfony/Component/Routing/Router.php index 89b14925e7124..67c0827b406bf 100644 --- a/src/Symfony/Component/Routing/Router.php +++ b/src/Symfony/Component/Routing/Router.php @@ -313,14 +313,15 @@ public function getGenerator() if (null === $this->options['cache_dir']) { $routes = $this->getRouteCollection(); - $aliases = []; $compiled = is_a($this->options['generator_class'], CompiledUrlGenerator::class, true); if ($compiled) { $generatorDumper = new CompiledUrlGeneratorDumper($routes); $routes = $generatorDumper->getCompiledRoutes(); $aliases = $generatorDumper->getCompiledAliases(); + $this->generator = new $this->options['generator_class'](array_merge($routes, $aliases), $this->context, $this->logger, $this->defaultLocale); + } else { + $this->generator = new $this->options['generator_class']($routes, $this->context, $this->logger, $this->defaultLocale); } - $this->generator = new $this->options['generator_class'](array_merge($routes, $aliases), $this->context, $this->logger, $this->defaultLocale); } else { $cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/url_generating_routes.php', function (ConfigCacheInterface $cache) { diff --git a/src/Symfony/Component/Routing/Tests/RouterTest.php b/src/Symfony/Component/Routing/Tests/RouterTest.php index e1800975b0c39..6db5bed1a6149 100644 --- a/src/Symfony/Component/Routing/Tests/RouterTest.php +++ b/src/Symfony/Component/Routing/Tests/RouterTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\Routing\Generator\CompiledUrlGenerator; use Symfony\Component\Routing\Generator\UrlGenerator; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Matcher\RequestMatcherInterface; @@ -131,6 +132,29 @@ public function testGeneratorIsCreatedIfCacheIsNotConfigured() $this->assertInstanceOf(UrlGenerator::class, $this->router->getGenerator()); } + /** + * @dataProvider provideGeneratorClass + */ + public function testGeneratorIsCreatedWithGeneratorClass(string $generatorClass) + { + $this->router->setOption('cache_dir', null); + $this->router->setOption('generator_class', $generatorClass); + + $this->loader->expects($this->once()) + ->method('load')->with('routing.yml', null) + ->willReturn(new RouteCollection()); + + $this->assertInstanceOf($generatorClass, $this->router->getGenerator()); + } + + public function provideGeneratorClass(): array + { + return [ + CompiledUrlGenerator::class => [CompiledUrlGenerator::class], + UrlGenerator::class => [UrlGenerator::class], + ]; + } + public function testMatchRequestWithUrlMatcherInterface() { $matcher = $this->createMock(UrlMatcherInterface::class); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy