namespace Symfony\Component\Routing\Tests;
use PHPUnit\Framework\TestCase;
+use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Resource\FileResource;
+use Symfony\Component\Routing\Loader\YamlFileLoader;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RouteCollectionBuilder;
$this->assertCount(1, $addedCollection->getResources());
// make sure the routes were imported into the top-level builder
+ $routeCollection = $routes->build();
$this->assertCount(1, $routes->build());
+ $this->assertCount(1, $routeCollection->getResources());
+ }
+
+ public function testImportAddResources()
+ {
+ $routeCollectionBuilder = new RouteCollectionBuilder(new YamlFileLoader(new FileLocator(array(__DIR__.'/Fixtures/'))));
+ $routeCollectionBuilder->import('file_resource.yml');
+ $routeCollection = $routeCollectionBuilder->build();
+
+ $this->assertCount(1, $routeCollection->getResources());
}
/**
// 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->assertCount(2, $routes);
+ $this->assertEquals('/other/a', $routes['a']->getPath());
+ $this->assertEquals('/other/b', $routes['b']->getPath());
+ }
}