Skip to content

Commit

Permalink
Add tests to ensure defaultLocale is properly passed to the URL gener…
Browse files Browse the repository at this point in the history
…ator
  • Loading branch information
HypeMC authored and nicolas-grekas committed Nov 4, 2019
1 parent 16c9baf commit 9aa66e2
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/Symfony/Component/Routing/Tests/RouterTest.php
Expand Up @@ -22,10 +22,26 @@ class RouterTest extends TestCase

private $loader = null;

private $cacheDir;

protected function setUp(): void
{
$this->loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$this->router = new Router($this->loader, 'routing.yml');

$this->cacheDir = sys_get_temp_dir().\DIRECTORY_SEPARATOR.uniqid('router_', true);
}

protected function tearDown(): void
{
if (is_dir($this->cacheDir)) {
array_map('unlink', glob($this->cacheDir.\DIRECTORY_SEPARATOR.'*'));
rmdir($this->cacheDir);
}

$this->loader = null;
$this->router = null;
$this->cacheDir = null;
}

public function testSetOptionsWithSupportedOptions()
Expand Down Expand Up @@ -132,4 +148,68 @@ public function testMatchRequestWithRequestMatcherInterface()

$this->router->matchRequest(Request::create('/'));
}

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

$router = new Router($this->loader, 'routing.yml', [
'cache_dir' => null,
], null, null, 'hr');

$generator = $router->getGenerator();

$this->assertInstanceOf('Symfony\Component\Routing\Generator\UrlGeneratorInterface', $generator);

$p = new \ReflectionProperty($generator, 'defaultLocale');
$p->setAccessible(true);

$this->assertSame('hr', $p->getValue($generator));
}

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

$router = new Router($this->loader, 'routing.yml', [
'cache_dir' => $this->cacheDir,
], null, null, 'hr');

$generator = $router->getGenerator();

$this->assertInstanceOf('Symfony\Component\Routing\Generator\UrlGeneratorInterface', $generator);

$p = new \ReflectionProperty($generator, 'defaultLocale');
$p->setAccessible(true);

$this->assertSame('hr', $p->getValue($generator));
}

/**
* @group legacy
*/
public function testDefaultLocaleIsPassedToNotCompiledGeneratorCacheClass()
{
$this->loader->expects($this->once())
->method('load')->with('routing.yml', null)
->willReturn(new RouteCollection());

$router = new Router($this->loader, 'routing.yml', [
'cache_dir' => $this->cacheDir,
'generator_class' => 'Symfony\Component\Routing\Generator\UrlGenerator',
], null, null, 'hr');

$generator = $router->getGenerator();

$this->assertInstanceOf('Symfony\Component\Routing\Generator\UrlGeneratorInterface', $generator);

$p = new \ReflectionProperty($generator, 'defaultLocale');
$p->setAccessible(true);

$this->assertSame('hr', $p->getValue($generator));
}
}

0 comments on commit 9aa66e2

Please sign in to comment.