AnnotationDirectoryLoaderTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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\Routing\Loader\AnnotationDirectoryLoader;
  13. class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
  14. {
  15. protected $loader;
  16. protected $reader;
  17. protected function setUp()
  18. {
  19. parent::setUp();
  20. $this->reader = $this->getReader();
  21. $this->loader = new AnnotationDirectoryLoader(new FileLocator(), $this->getClassLoader($this->reader));
  22. }
  23. public function testLoad()
  24. {
  25. $this->reader->expects($this->exactly(2))->method('getClassAnnotation');
  26. $this->reader
  27. ->expects($this->any())
  28. ->method('getMethodAnnotations')
  29. ->will($this->returnValue(array()))
  30. ;
  31. $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
  32. }
  33. public function testLoadIgnoresHiddenDirectories()
  34. {
  35. $this->expectAnnotationsToBeReadFrom(array(
  36. 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
  37. 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\FooClass',
  38. ));
  39. $this->reader
  40. ->expects($this->any())
  41. ->method('getMethodAnnotations')
  42. ->will($this->returnValue(array()))
  43. ;
  44. $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
  45. }
  46. public function testSupports()
  47. {
  48. $fixturesDir = __DIR__.'/../Fixtures';
  49. $this->assertTrue($this->loader->supports($fixturesDir), '->supports() returns true if the resource is loadable');
  50. $this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  51. $this->assertTrue($this->loader->supports($fixturesDir, 'annotation'), '->supports() checks the resource type if specified');
  52. $this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified');
  53. }
  54. private function expectAnnotationsToBeReadFrom(array $classes)
  55. {
  56. $this->reader->expects($this->exactly(\count($classes)))
  57. ->method('getClassAnnotation')
  58. ->with($this->callback(function (\ReflectionClass $class) use ($classes) {
  59. return \in_array($class->getName(), $classes);
  60. }));
  61. }
  62. }