1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\Routing\Tests\Loader;
13:
14: use Symfony\Component\Routing\Loader\DirectoryLoader;
15: use Symfony\Component\Routing\Loader\YamlFileLoader;
16: use Symfony\Component\Routing\Loader\AnnotationFileLoader;
17: use Symfony\Component\Config\Loader\LoaderResolver;
18: use Symfony\Component\Config\FileLocator;
19: use Symfony\Component\Routing\RouteCollection;
20:
21: class DirectoryLoaderTest extends AbstractAnnotationLoaderTest
22: {
23: private $loader;
24: private $reader;
25:
26: protected function setUp()
27: {
28: parent::setUp();
29:
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)),
36: $this->loader,
37: ));
38: $this->loader->setResolver($resolver);
39: }
40:
41: public function testLoadDirectory()
42: {
43: $collection = $this->loader->load(__DIR__.'/../Fixtures/directory', 'directory');
44: $this->verifyCollection($collection);
45: }
46:
47: public function testImportDirectory()
48: {
49: $collection = $this->loader->load(__DIR__.'/../Fixtures/directory_import', 'directory');
50: $this->verifyCollection($collection);
51: }
52:
53: private function verifyCollection(RouteCollection $collection)
54: {
55: $routes = $collection->all();
56:
57: $this->assertCount(3, $routes, 'Three routes are loaded');
58: $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
59:
60: for ($i = 1; $i <= 3; ++$i) {
61: $this->assertSame('/route/'.$i, $routes['route'.$i]->getPath());
62: }
63: }
64:
65: public function testSupports()
66: {
67: $fixturesDir = __DIR__.'/../Fixtures';
68:
69: $this->assertFalse($this->loader->supports($fixturesDir), '->supports(*) returns false');
70:
71: $this->assertTrue($this->loader->supports($fixturesDir, 'directory'), '->supports(*, "directory") returns true');
72: $this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports(*, "foo") returns false');
73: }
74: }
75: