8000 [Routing] Make sure we only build routes once by sroze · Pull Request #25791 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
6 changes: 3 additions & 3 deletions src/Symfony/Component/Routing/RouteCollectionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public function import($resource, $prefix = '/', $type = null)
foreach ($collection->getResources() as $resource) {
$builder->addResource($resource);
}

// mount into this builder
$this->mount($prefix, $builder);
}

// mount into this builder
$this->mount($prefix, $builder);

return $builder;
}

Expand Down
26 changes: 26 additions & 0 deletions src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,30 @@ public function testAutomaticRouteNamesDoNotConflict()
// there are 2 routes (i.e. with non-conflicting names)
$this->assertCount(3, $collection->all());
}

public function testAddsThePrefixOnlyOnceWhenLoadingMultipleCollections()
{
$firstCollection = new RouteCollection();
$firstCollection->add('a', new Route('/a'));

$secondCollection = new RouteCollection();
$secondCollection->add('b', new Route('/b'));

$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
$loader->expects($this->any())
->method('supports')
->will($this->returnValue(true));
$loader
->expects($this->any())
->method('load')
->will($this->returnValue(array($firstCollection, $secondCollection)));

$routeCollectionBuilder = new RouteCollectionBuilder($loader);
$routeCollectionBuilder->import('/directory/recurse/*', '/other/', 'glob');
$routes = $routeCollectionBuilder->build()->all();

$this->assertEquals(2, count($routes));
$this->assertEquals('/other/a', $routes['a']->getPath());
$this->assertEquals('/other/b', $routes['b']->getPath());
}
}
0