Skip to content

Commit 5c9b129

Browse files
committed
Fix TypeError in Router when using UrlGenerator
1 parent 3e01ccd commit 5c9b129

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Router.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,12 @@ public function getGenerator()
313313

314314
if (null === $this->options['cache_dir']) {
315315
$routes = $this->getRouteCollection();
316-
$aliases = [];
317316
$compiled = is_a($this->options['generator_class'], CompiledUrlGenerator::class, true);
318317
if ($compiled) {
319318
$generatorDumper = new CompiledUrlGeneratorDumper($routes);
320-
$routes = $generatorDumper->getCompiledRoutes();
321-
$aliases = $generatorDumper->getCompiledAliases();
319+
$routes = array_merge($generatorDumper->getCompiledRoutes(), $generatorDumper->getCompiledAliases());
322320
}
323-
$this->generator = new $this->options['generator_class'](array_merge($routes, $aliases), $this->context, $this->logger, $this->defaultLocale);
321+
$this->generator = new $this->options['generator_class']($routes, $this->context, $this->logger, $this->defaultLocale);
324322
} else {
325323
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/url_generating_routes.php',
326324
function (ConfigCacheInterface $cache) {

Tests/RouterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\Loader\LoaderInterface;
1616
use Symfony\Component\HttpFoundation\Request;
17+
use Symfony\Component\Routing\Generator\CompiledUrlGenerator;
1718
use Symfony\Component\Routing\Generator\UrlGenerator;
1819
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
1920
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
@@ -124,11 +125,24 @@ public function testGeneratorIsCreatedIfCacheIsNotConfigured()
124125
{
125126
$this->router->setOption('cache_dir', null);
126127

128+
$this->loader->expects($this->once())
129+
->method('load')->with('routing.yml', null)
130+
->willReturn(new RouteCollection());
131+
132+
$this->assertInstanceOf(CompiledUrlGenerator::class, $this->router->getGenerator());
133+
}
134+
135+
public function testGeneratorIsCreatedIfCacheIsNotConfiguredNotCompiled()
136+
{
137+
$this->router->setOption('cache_dir', null);
138+
$this->router->setOption('generator_class', UrlGenerator::class);
139+
127140
$this->loader->expects($this->once())
128141
->method('load')->with('routing.yml', null)
129142
->willReturn(new RouteCollection());
130143

131144
$this->assertInstanceOf(UrlGenerator::class, $this->router->getGenerator());
145+
$this->assertNotInstanceOf(CompiledUrlGenerator::class, $this->router->getGenerator());
132146
}
133147

134148
public function testMatchRequestWithUrlMatcherInterface()

0 commit comments

Comments
 (0)