8000 Bug #16343 [Router] Too many Routes ? by jelte · Pull Request #16386 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Bug #16343 [Router] Too many Routes ? #16386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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