Skip to content

Commit

Permalink
Bug #16343 [Router] Too many Routes ?
Browse files Browse the repository at this point in the history
  • Loading branch information
Jelte Steijaert authored and nicolas-grekas committed Nov 25, 2015
1 parent 8d0ec00 commit 0113ac3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Expand Up @@ -53,7 +53,7 @@ public function dump(array $options = array())
*/
class {$options['class']} extends {$options['base_class']}
{
private static \$declaredRoutes = {$this->generateDeclaredRoutes()};
private static \$declaredRoutes;
/**
* Constructor.
Expand All @@ -62,6 +62,9 @@ public function __construct(RequestContext \$context, LoggerInterface \$logger =
{
\$this->context = \$context;
\$this->logger = \$logger;
if (null === self::\$declaredRoutes) {
self::\$declaredRoutes = {$this->generateDeclaredRoutes()};
}
}
{$this->generateGenerateMethod()}
Expand Down
Expand Up @@ -34,14 +34,21 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
*/
private $testTmpFilepath;

/**
* @var string
*/
private $largeTestTmpFilepath;

protected function setUp()
{
parent::setUp();

$this->routeCollection = new RouteCollection();
$this->generatorDumper = new PhpGeneratorDumper($this->routeCollection);
$this->testTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.'.$this->getName().'.php';
$this->largeTestTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.'.$this->getName().'.large.php';
@unlink($this->testTmpFilepath);
@unlink($this->largeTestTmpFilepath);
}

protected function tearDown()
Expand Down Expand Up @@ -76,6 +83,33 @@ public function testDumpWithRoutes()
$this->assertEquals($relativeUrlWithoutParameter, '/app.php/testing2');
}

public function testDumpWithTooManyRoutes()
{
$this->routeCollection->add('Test', new Route('/testing/{foo}'));
for ( $i = 0; $i < 32769; ++$i ) {
$this->routeCollection->add('route_'.$i, new Route('/route_'.$i));
}
$this->routeCollection->add('Test2', new Route('/testing2'));

$data = $this->generatorDumper->dump(array(
'class' => 'ProjectLargeUrlGenerator',
));
file_put_contents($this->largeTestTmpFilepath, $data);
include $this->largeTestTmpFilepath;

$projectUrlGenerator = new \ProjectLargeUrlGenerator(new RequestContext('/app.php'));

$absoluteUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_URL);
$absoluteUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_URL);
$relativeUrlWithParameter = $projectUrlGenerator->generate('Test', array('foo' => 'bar'), UrlGeneratorInterface::ABSOLUTE_PATH);
$relativeUrlWithoutParameter = $projectUrlGenerator->generate('Test2', array(), UrlGeneratorInterface::ABSOLUTE_PATH);

$this->assertEquals($absoluteUrlWithParameter, 'http://localhost/app.php/testing/bar');
$this->assertEquals($absoluteUrlWithoutParameter, 'http://localhost/app.php/testing2');
$this->assertEquals($relativeUrlWithParameter, '/app.php/testing/bar');
$this->assertEquals($relativeUrlWithoutParameter, '/app.php/testing2');
}

/**
* @expectedException \InvalidArgumentException
*/
Expand Down

0 comments on commit 0113ac3

Please sign in to comment.