7f1d5765574a49284da8605ad7c8c88b23bbaf11
[yaffs-website] / vendor / symfony / routing / Tests / Loader / AnnotationFileLoaderTest.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\AnnotationFileLoader;
15 use Symfony\Component\Config\FileLocator;
16 use Symfony\Component\Routing\Annotation\Route;
17
18 class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
19 {
20     protected $loader;
21     protected $reader;
22
23     protected function setUp()
24     {
25         parent::setUp();
26
27         $this->reader = $this->getReader();
28         $this->loader = new AnnotationFileLoader(new FileLocator(), $this->getClassLoader($this->reader));
29     }
30
31     public function testLoad()
32     {
33         $this->reader->expects($this->once())->method('getClassAnnotation');
34
35         $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
36     }
37
38     /**
39      * @requires PHP 5.4
40      */
41     public function testLoadTraitWithClassConstant()
42     {
43         $this->reader->expects($this->never())->method('getClassAnnotation');
44
45         $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php');
46     }
47
48     /**
49      * @expectedException \InvalidArgumentException
50      * @expectedExceptionMessage Did you forgot to add the "<?php" start tag at the beginning of the file?
51      */
52     public function testLoadFileWithoutStartTag()
53     {
54         $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
55     }
56
57     /**
58      * @requires PHP 5.6
59      */
60     public function testLoadVariadic()
61     {
62         $route = new Route(array('path' => '/path/to/{id}'));
63         $this->reader->expects($this->once())->method('getClassAnnotation');
64         $this->reader->expects($this->once())->method('getMethodAnnotations')
65             ->will($this->returnValue(array($route)));
66
67         $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
68     }
69
70     /**
71      * @requires PHP 7.0
72      */
73     public function testLoadAnonymousClass()
74     {
75         $this->reader->expects($this->never())->method('getClassAnnotation');
76         $this->reader->expects($this->never())->method('getMethodAnnotations');
77
78         $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/AnonymousClassInTrait.php');
79     }
80
81     public function testSupports()
82     {
83         $fixture = __DIR__.'/../Fixtures/annotated.php';
84
85         $this->assertTrue($this->loader->supports($fixture), '->supports() returns true if the resource is loadable');
86         $this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
87
88         $this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
89         $this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
90     }
91 }