Commit 43aee48f authored by Fabien Potencier's avatar Fabien Potencier

changed auto-generated route names when there is a conflict

parent e98dd5f7
...@@ -208,8 +208,9 @@ class ControllerCollection ...@@ -208,8 +208,9 @@ class ControllerCollection
$controller->getRoute()->setPath($prefix.$controller->getRoute()->getPath()); $controller->getRoute()->setPath($prefix.$controller->getRoute()->getPath());
if (!$name = $controller->getRouteName()) { if (!$name = $controller->getRouteName()) {
$name = $controller->generateRouteName(''); $name = $controller->generateRouteName('');
$i = 0;
while ($routes->get($name)) { while ($routes->get($name)) {
$name .= '_'; $name = $controller->generateRouteName('').'_'.++$i;
} }
$controller->bind($name); $controller->bind($name);
} }
......
...@@ -71,7 +71,7 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase ...@@ -71,7 +71,7 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase
$mountedRootController = $controllers->match('/', function () {}); $mountedRootController = $controllers->match('/', function () {});
$mainRootController = new Controller(new Route('/')); $mainRootController = new Controller(new Route('/'));
$mainRootController->bind($mainRootController->generateRouteName('main_')); $mainRootController->bind($mainRootController->generateRouteName('main_1'));
$controllers->flush(); $controllers->flush();
...@@ -84,11 +84,12 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase ...@@ -84,11 +84,12 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase
$controllers->match('/a-a', function () {}); $controllers->match('/a-a', function () {});
$controllers->match('/a_a', function () {}); $controllers->match('/a_a', function () {});
$controllers->match('/a/a', function () {});
$routes = $controllers->flush(); $routes = $controllers->flush();
$this->assertCount(2, $routes->all()); $this->assertCount(3, $routes->all());
$this->assertEquals(array('_a_a', '_a_a_'), array_keys($routes->all())); $this->assertEquals(array('_a_a', '_a_a_1', '_a_a_2'), array_keys($routes->all()));
} }
public function testUniqueGeneratedRouteNamesAmongMounts() public function testUniqueGeneratedRouteNamesAmongMounts()
...@@ -104,7 +105,7 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase ...@@ -104,7 +105,7 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase
$routes = $controllers->flush(); $routes = $controllers->flush();
$this->assertCount(2, $routes->all()); $this->assertCount(2, $routes->all());
$this->assertEquals(array('_root_a_leaf', '_root_a_leaf_'), array_keys($routes->all())); $this->assertEquals(array('_root_a_leaf', '_root_a_leaf_1'), array_keys($routes->all()));
} }
public function testUniqueGeneratedRouteNamesAmongNestedMounts() public function testUniqueGeneratedRouteNamesAmongNestedMounts()
...@@ -123,7 +124,7 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase ...@@ -123,7 +124,7 @@ class ControllerCollectionTest extends \PHPUnit_Framework_TestCase
$routes = $controllers->flush(); $routes = $controllers->flush();
$this->assertCount(2, $routes->all()); $this->assertCount(2, $routes->all());
$this->assertEquals(array('_root_a_tree_leaf', '_root_a_tree_leaf_'), array_keys($routes->all())); $this->assertEquals(array('_root_a_tree_leaf', '_root_a_tree_leaf_1'), array_keys($routes->all()));
} }
public function testAssert() public function testAssert()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment