4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Routing\Tests\Loader;
14 use Symfony\Component\Config\FileLocator;
15 use Symfony\Component\Config\Loader\LoaderResolver;
16 use Symfony\Component\Routing\Loader\AnnotationFileLoader;
17 use Symfony\Component\Routing\Loader\DirectoryLoader;
18 use Symfony\Component\Routing\Loader\YamlFileLoader;
19 use Symfony\Component\Routing\RouteCollection;
21 class DirectoryLoaderTest extends AbstractAnnotationLoaderTest
26 protected function setUp()
30 $locator = new FileLocator();
31 $this->reader = $this->getReader();
32 $this->loader = new DirectoryLoader($locator);
33 $resolver = new LoaderResolver(array(
34 new YamlFileLoader($locator),
35 new AnnotationFileLoader($locator, $this->getClassLoader($this->reader)),
38 $this->loader->setResolver($resolver);
41 public function testLoadDirectory()
43 $collection = $this->loader->load(__DIR__.'/../Fixtures/directory', 'directory');
44 $this->verifyCollection($collection);
47 public function testImportDirectory()
49 $collection = $this->loader->load(__DIR__.'/../Fixtures/directory_import', 'directory');
50 $this->verifyCollection($collection);
53 private function verifyCollection(RouteCollection $collection)
55 $routes = $collection->all();
57 $this->assertCount(3, $routes, 'Three routes are loaded');
58 $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
60 for ($i = 1; $i <= 3; ++$i) {
61 $this->assertSame('/route/'.$i, $routes['route'.$i]->getPath());
65 public function testSupports()
67 $fixturesDir = __DIR__.'/../Fixtures';
69 $this->assertFalse($this->loader->supports($fixturesDir), '->supports(*) returns false');
71 $this->assertTrue($this->loader->supports($fixturesDir, 'directory'), '->supports(*, "directory") returns true');
72 $this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports(*, "foo") returns false');