Skip to content

Commit

Permalink
Make sure we only build once and have one time the prefix when import…
Browse files Browse the repository at this point in the history
…ing routes
  • Loading branch information
sroze committed Jan 15, 2018
1 parent f657057 commit 927a75a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Symfony/Component/Routing/RouteCollectionBuilder.php
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
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 comments on commit 927a75a

Please sign in to comment.