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\Routing\Loader\AnnotationDirectoryLoader;
17 class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
22 protected function setUp()
26 $this->reader = $this->getReader();
27 $this->loader = new AnnotationDirectoryLoader(new FileLocator(), $this->getClassLoader($this->reader));
30 public function testLoad()
32 $this->reader->expects($this->exactly(3))->method('getClassAnnotation');
35 ->expects($this->any())
36 ->method('getMethodAnnotations')
37 ->will($this->returnValue(array()))
41 ->expects($this->any())
42 ->method('getClassAnnotations')
43 ->will($this->returnValue(array()))
46 $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
49 public function testLoadIgnoresHiddenDirectories()
51 $this->expectAnnotationsToBeReadFrom(array(
52 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
53 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass',
54 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\FooClass',
58 ->expects($this->any())
59 ->method('getMethodAnnotations')
60 ->will($this->returnValue(array()))
64 ->expects($this->any())
65 ->method('getClassAnnotations')
66 ->will($this->returnValue(array()))
69 $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
72 public function testSupports()
74 $fixturesDir = __DIR__.'/../Fixtures';
76 $this->assertTrue($this->loader->supports($fixturesDir), '->supports() returns true if the resource is loadable');
77 $this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
79 $this->assertTrue($this->loader->supports($fixturesDir, 'annotation'), '->supports() checks the resource type if specified');
80 $this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified');
83 public function testItSupportsAnyAnnotation()
85 $this->assertTrue($this->loader->supports(__DIR__.'/../Fixtures/even-with-not-existing-folder', 'annotation'));
88 public function testLoadFileIfLocatedResourceIsFile()
90 $this->reader->expects($this->exactly(1))->method('getClassAnnotation');
93 ->expects($this->any())
94 ->method('getMethodAnnotations')
95 ->will($this->returnValue(array()))
98 $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
101 private function expectAnnotationsToBeReadFrom(array $classes)
103 $this->reader->expects($this->exactly(\count($classes)))
104 ->method('getClassAnnotation')
105 ->with($this->callback(function (\ReflectionClass $class) use ($classes) {
106 return \in_array($class->getName(), $classes);