Make sure we only build once and have one time the prefix when importing routes

This commit is contained in:
Samuel ROZE 2018-01-15 10:33:10 +00:00
parent f65705736f
commit 927a75ac3e
No known key found for this signature in database
GPG Key ID: 835426F55A19FB84
2 changed files with 29 additions and 3 deletions

View File

@ -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;
}

View File

@ -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());
}
}