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 class AnnotationClassLoaderTest
extends AbstractAnnotationLoaderTest
18 protected function setUp()
22 $this->reader
= $this->getReader();
23 $this->loader
= $this->getClassLoader($this->reader
);
27 * @expectedException \InvalidArgumentException
29 public function testLoadMissingClass()
31 $this->loader
->load('MissingClass');
35 * @expectedException \InvalidArgumentException
37 public function testLoadAbstractClass()
39 $this->loader
->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\AbstractClass');
43 * @dataProvider provideTestSupportsChecksResource
45 public function testSupportsChecksResource($resource, $expectedSupports)
47 $this->assertSame($expectedSupports, $this->loader
->supports($resource), '->supports() returns true if the resource is loadable');
50 public function provideTestSupportsChecksResource()
54 array('\fully\qualified\class\name', true),
55 array('namespaced\class\without\leading\slash', true),
56 array('ÿClassWithLegalSpecialCharacters', true),
58 array('foo.foo', false),
63 public function testSupportsChecksTypeIfSpecified()
65 $this->assertTrue($this->loader
->supports('class', 'annotation'), '->supports() checks the resource type if specified');
66 $this->assertFalse($this->loader
->supports('class', 'foo'), '->supports() checks the resource type if specified');
69 public function getLoadTests()
73 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
74 array('name'=>'route1'),
75 array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3')
78 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
79 array('name'=>'route1', 'defaults' => array('arg2' => 'foo')),
80 array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3')
86 * @dataProvider getLoadTests
88 public function testLoad($className, $routeDatas = array(), $methodArgs = array())
90 $routeDatas = array_replace(array(
93 'requirements' => array(),
95 'defaults' => array(),
101 ->expects($this->once())
102 ->method('getMethodAnnotations')
103 ->will($this->returnValue(array($this->getAnnotatedRoute($routeDatas))))
105 $routeCollection = $this->loader
->load($className);
106 $route = $routeCollection->get($routeDatas['name']);
108 $this->assertSame($routeDatas['path'], $route->getPath(), '->load preserves path annotation');
109 $this->assertSame($routeDatas['requirements'],$route->getRequirements(), '->load preserves requirements annotation');
110 $this->assertCount(0, array_intersect($route->getOptions(), $routeDatas['options']), '->load preserves options annotation');
111 $this->assertSame(array_replace($routeDatas['defaults'], $methodArgs), $route->getDefaults(), '->load preserves defaults annotation');
114 private function getAnnotatedRoute($datas)
116 return new \Symfony\Component\Routing\Annotation\
Route($datas);