DirectoryLoaderTest.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\Config\FileLocator;
  12. use Symfony\Component\Config\Loader\LoaderResolver;
  13. use Symfony\Component\Routing\Loader\AnnotationFileLoader;
  14. use Symfony\Component\Routing\Loader\DirectoryLoader;
  15. use Symfony\Component\Routing\Loader\YamlFileLoader;
  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([
  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. }