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\Routing\Loader\AnnotationFileLoader;
15 use Symfony\Component\Config\FileLocator;
16 use Symfony\Component\Routing\Annotation\Route;
18 class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
23 protected function setUp()
27 $this->reader = $this->getReader();
28 $this->loader = new AnnotationFileLoader(new FileLocator(), $this->getClassLoader($this->reader));
31 public function testLoad()
33 $this->reader->expects($this->once())->method('getClassAnnotation');
35 $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
41 public function testLoadTraitWithClassConstant()
43 $this->reader->expects($this->never())->method('getClassAnnotation');
45 $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php');
49 * @expectedException \InvalidArgumentException
50 * @expectedExceptionMessage Did you forgot to add the "<?php" start tag at the beginning of the file?
52 public function testLoadFileWithoutStartTag()
54 $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
60 public function testLoadVariadic()
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)));
67 $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
73 public function testLoadAnonymousClass()
75 $this->reader->expects($this->never())->method('getClassAnnotation');
76 $this->reader->expects($this->never())->method('getMethodAnnotations');
78 $this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/AnonymousClassInTrait.php');
81 public function testSupports()
83 $fixture = __DIR__.'/../Fixtures/annotated.php';
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');
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');