Skip to content

Commit

Permalink
Merge branch '5.4' into 6.0
Browse files Browse the repository at this point in the history
* 5.4:
  [HttpKernel] Fix empty request stack when terminating with exception
  [HttpKernel] Remove EOL when using error_log() in HttpKernel Logger
  [HttpClient] Add test case for seeking into the content of RetryableHttpClient responses
  [HttpClient] Fix buffering after calling AsyncContext::passthru()
  s/annd/and
  s/gargage/garbage
  [Console] Fix error output on windows cli
  Reserve keys when using numeric ones
  add missing Azerbaijani translations
  fix few typos/inconsistencies in latvian translations
  Fix TypeError in Router when using UrlGenerator
  [Messenger] Fix amqp socket lost
  fix: use message object from event
  • Loading branch information
nicolas-grekas committed Oct 18, 2022
2 parents 434b64f + 5c9b129 commit 3b7384f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,12 @@ public function getGenerator(): UrlGeneratorInterface

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();
$routes = array_merge($generatorDumper->getCompiledRoutes(), $generatorDumper->getCompiledAliases());
}
$this->generator = new $this->options['generator_class'](array_merge($routes, $aliases), $this->context, $this->logger, $this->defaultLocale);
$this->generator = new $this->options['generator_class']($routes, $this->context, $this->logger, $this->defaultLocale);
} else {
$cache = $this->getConfigCacheFactory()->cache($this->options['cache_dir'].'/url_generating_routes.php',
function (ConfigCacheInterface $cache) {
Expand Down
14 changes: 14 additions & 0 deletions Tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,11 +125,24 @@ public function testGeneratorIsCreatedIfCacheIsNotConfigured()
{
$this->router->setOption('cache_dir', null);

$this->loader->expects($this->once())
->method('load')->with('routing.yml', null)
->willReturn(new RouteCollection());

$this->assertInstanceOf(CompiledUrlGenerator::class, $this->router->getGenerator());
}

public function testGeneratorIsCreatedIfCacheIsNotConfiguredNotCompiled()
{
$this->router->setOption('cache_dir', null);
$this->router->setOption('generator_class', UrlGenerator::class);

$this->loader->expects($this->once())
->method('load')->with('routing.yml', null)
->willReturn(new RouteCollection());

$this->assertInstanceOf(UrlGenerator::class, $this->router->getGenerator());
$this->assertNotInstanceOf(CompiledUrlGenerator::class, $this->router->getGenerator());
}

public function testMatchRequestWithUrlMatcherInterface()
Expand Down

0 comments on commit 3b7384f

Please sign in to comment.