8000 Make sure we only build once and have one time the prefix when import… · symfony/symfony@927a75a · GitHub
[go: up one dir, main page]

Skip to content

Commit 927a75a

Browse files
committed
Make sure we only build once and have one time the prefix when importing routes
1 parent f657057 commit 927a75a

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/Symfony/Component/Routing/RouteCollectionBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ public function import($resource, $prefix = '/', $type = null)
7676
foreach ($collection->getResources() as $resource) {
7777
$builder->addResource($resource);
7878
}
79-
80-
// mount into this builder
81-
$this->mount($prefix, $builder);
8279
}
8380

81+
// mount into this builder
82+
$this->mount($prefix, $builder);
83+
8484
return $builder;
8585
}
8686

src/Symfony/Component/Routing/Tests/RouteCollectionBuilderTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,4 +335,30 @@ public function testAutomaticRouteNamesDoNotConflict()
335335
// there are 2 routes (i.e. with non-conflicting names)
336336
$this->assertCount(3, $collection->all());
337337
}
338+
339+
public function testAddsThePrefixOnlyOnceWhenLoadingMultipleCollections()
340+
{
341+
$firstCollection = new RouteCollection();
342+
$firstCollection->add('a', new Route('/a'));
343+
344+
$secondCollection = new RouteCollection();
345+
$secondCollection->add('b', new Route('/b'));
346+
347+
$loader = $this->getMockBuilder('Symfony\Component\Config\Loader\LoaderInterface')->getMock();
348+
$loader->expects($this->any())
349+
->method('supports')
350+
->will($this->returnValue(true));
351+
$loader
352+
->expects($this->any())
353+
->method('load')
354+
->will($this->returnValue(array($firstCollection, $secondCollection)));
355+
356+
$routeCollectionBuilder = new RouteCollectionBuilder($loader);
357+
$routeCollectionBuilder->import('/directory/recurse/*', '/other/', 'glob');
358+
$routes = $routeCollectionBuilder->build()->all();
359+
360+
$this->assertEquals(2, count($routes));
361+
$this->assertEquals('/other/a', $routes['a']->getPath());
362+
$this->assertEquals('/other/b', $routes['b']->getPath());
363+
}
338364
}

0 commit comments

Comments
 (0)
0