8000 bug #25791 [Routing] Make sure we only build routes once (sroze) · symfony/symfony@663f3f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 663f3f0

Browse files
committed
bug #25791 [Routing] Make sure we only build routes once (sroze)
This PR was merged into the 3.3 branch. Discussion ---------- [Routing] Make sure we only build routes once | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25746 | License | MIT | Doc PR | ø We need to build the collection(s) only once, else the prefix would be duplicated. Commits ------- 927a75a Make sure we only build once and have one time the prefix when importing routes
2 parents ff40995 + 927a75a commit 663f3f0

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