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