DirectoryLoaderTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Routing\Tests\Loader;
  11. use Symfony\Component\Routing\Loader\DirectoryLoader;
  12. use Symfony\Component\Routing\Loader\YamlFileLoader;
  13. use Symfony\Component\Routing\Loader\AnnotationFileLoader;
  14. use Symfony\Component\Config\Loader\LoaderResolver;
  15. use Symfony\Component\Config\FileLocator;
  16. use Symfony\Component\Routing\RouteCollection;
  17. class DirectoryLoaderTest extends AbstractAnnotationLoaderTest
  18. {
  19. private $loader;
  20. private $reader;
  21. protected function setUp()
  22. {
  23. parent::setUp();
  24. $locator = new FileLocator();
  25. $this->reader = $this->getReader();
  26. $this->loader = new DirectoryLoader($locator);
  27. $resolver = new LoaderResolver(array(
  28. new YamlFileLoader($locator),
  29. new AnnotationFileLoader($locator, $this->getClassLoader($this->reader)),
  30. $this->loader,
  31. ));
  32. $this->loader->setResolver($resolver);
  33. }
  34. public function testLoadDirectory()
  35. {
  36. $collection = $this->loader->load(__DIR__.'/../Fixtures/directory', 'directory');
  37. $this->verifyCollection($collection);
  38. }
  39. public function testImportDirectory()
  40. {
  41. $collection = $this->loader->load(__DIR__.'/../Fixtures/directory_import', 'directory');
  42. $this->verifyCollection($collection);
  43. }
  44. private function verifyCollection(RouteCollection $collection)
  45. {
  46. $routes = $collection->all();
  47. $this->assertCount(3, $routes, 'Three routes are loaded');
  48. $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
  49. for ($i = 1; $i <= 3; ++$i) {
  50. $this->assertSame('/route/'.$i, $routes['route'.$i]->getPath());
  51. }
  52. }
  53. public function testSupports()
  54. {
  55. $fixturesDir = __DIR__.'/../Fixtures';
  56. $this->assertFalse($this->loader->supports($fixturesDir), '->supports(*) returns false');
  57. $this->assertTrue($this->loader->supports($fixturesDir, 'directory'), '->supports(*, "directory") returns true');
  58. $this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports(*, "foo") returns false');
  59. }
  60. }