Bug #16343 [Router] Too many Routes ?

This commit is contained in:
Jelte Steijaert 2015-10-30 10:20:47 +01:00 committed by Nicolas Grekas
parent 8d0ec00caa
commit 0113ac3ce2
2 changed files with 38 additions and 1 deletions

View File

@ -53,7 +53,7 @@ use Psr\Log\LoggerInterface;
*/ */
class {$options['class']} extends {$options['base_class']} class {$options['class']} extends {$options['base_class']}
{ {
private static \$declaredRoutes = {$this->generateDeclaredRoutes()}; private static \$declaredRoutes;
/** /**
* Constructor. * Constructor.
@ -62,6 +62,9 @@ class {$options['class']} extends {$options['base_class']}
{ {
\$this->context = \$context; \$this->context = \$context;
\$this->logger = \$logger; \$this->logger = \$logger;
if (null === self::\$declaredRoutes) {
self::\$declaredRoutes = {$this->generateDeclaredRoutes()};
}
} }
{$this->generateGenerateMethod()} {$this->generateGenerateMethod()}

View File

@ -34,6 +34,11 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
*/ */
private $testTmpFilepath; private $testTmpFilepath;
/**
* @var string
*/
private $largeTestTmpFilepath;
protected function setUp() protected function setUp()
{ {
parent::setUp(); parent::setUp();
@ -41,7 +46,9 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
$this->routeCollection = new RouteCollection(); $this->routeCollection = new RouteCollection();
$this->generatorDumper = new PhpGeneratorDumper($this->routeCollection); $this->generatorDumper = new PhpGeneratorDumper($this->routeCollection);
$this->testTmpFilepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.'php_generator.'.$this->getName().'.php'; $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->testTmpFilepath);
@unlink($this->largeTestTmpFilepath);
} }
protected function tearDown() protected function tearDown()
@ -76,6 +83,33 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($relativeUrlWithoutParameter, '/app.php/testing2'); $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 * @expectedException \InvalidArgumentException
*/ */