Make sure we only build once and have one time the prefix when importing routes
This commit is contained in:
parent
f65705736f
commit
927a75ac3e
@ -76,11 +76,11 @@ class RouteCollectionBuilder
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -335,4 +335,30 @@ class RouteCollectionBuilderTest extends TestCase
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user