8a6668e0c2beb1b1e756e812d261138c1ae030f6
[yaffs-website] / vendor / symfony / routing / Tests / Loader / AnnotationDirectoryLoaderTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
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(3))->method('getClassAnnotation');
33
34         $this->reader
35             ->expects($this->any())
36             ->method('getMethodAnnotations')
37             ->will($this->returnValue(array()))
38         ;
39
40         $this->reader
41             ->expects($this->any())
42             ->method('getClassAnnotations')
43             ->will($this->returnValue(array()))
44         ;
45
46         $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
47     }
48
49     public function testLoadIgnoresHiddenDirectories()
50     {
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',
55         ));
56
57         $this->reader
58             ->expects($this->any())
59             ->method('getMethodAnnotations')
60             ->will($this->returnValue(array()))
61         ;
62
63         $this->reader
64             ->expects($this->any())
65             ->method('getClassAnnotations')
66             ->will($this->returnValue(array()))
67         ;
68
69         $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
70     }
71
72     public function testSupports()
73     {
74         $fixturesDir = __DIR__.'/../Fixtures';
75
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');
78
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');
81     }
82
83     public function testItSupportsAnyAnnotation()
84     {
85         $this->assertTrue($this->loader->supports(__DIR__.'/../Fixtures/even-with-not-existing-folder', 'annotation'));
86     }
87
88     public function testLoadFileIfLocatedResourceIsFile()
89     {
90         $this->reader->expects($this->exactly(1))->method('getClassAnnotation');
91
92         $this->reader
93             ->expects($this->any())
94             ->method('getMethodAnnotations')
95             ->will($this->returnValue(array()))
96         ;
97
98         $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
99     }
100
101     private function expectAnnotationsToBeReadFrom(array $classes)
102     {
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);
107             }));
108     }
109 }