]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php
gitignore vendor
[github/wallabag/wallabag.git] / vendor / symfony / routing / Symfony / Component / Routing / Tests / Loader / AnnotationClassLoaderTest.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 class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
15 {
16 protected $loader;
17
18 protected function setUp()
19 {
20 parent::setUp();
21
22 $this->reader = $this->getReader();
23 $this->loader = $this->getClassLoader($this->reader);
24 }
25
26 /**
27 * @expectedException \InvalidArgumentException
28 */
29 public function testLoadMissingClass()
30 {
31 $this->loader->load('MissingClass');
32 }
33
34 /**
35 * @expectedException \InvalidArgumentException
36 */
37 public function testLoadAbstractClass()
38 {
39 $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\AbstractClass');
40 }
41
42 /**
43 * @dataProvider provideTestSupportsChecksResource
44 */
45 public function testSupportsChecksResource($resource, $expectedSupports)
46 {
47 $this->assertSame($expectedSupports, $this->loader->supports($resource), '->supports() returns true if the resource is loadable');
48 }
49
50 public function provideTestSupportsChecksResource()
51 {
52 return array(
53 array('class', true),
54 array('\fully\qualified\class\name', true),
55 array('namespaced\class\without\leading\slash', true),
56 array('ÿClassWithLegalSpecialCharacters', true),
57 array('5', false),
58 array('foo.foo', false),
59 array(null, false),
60 );
61 }
62
63 public function testSupportsChecksTypeIfSpecified()
64 {
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');
67 }
68
69 public function getLoadTests()
70 {
71 return array(
72 array(
73 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
74 array('name'=>'route1'),
75 array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3')
76 ),
77 array(
78 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
79 array('name'=>'route1', 'defaults' => array('arg2' => 'foo')),
80 array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3')
81 ),
82 );
83 }
84
85 /**
86 * @dataProvider getLoadTests
87 */
88 public function testLoad($className, $routeDatas = array(), $methodArgs = array())
89 {
90 $routeDatas = array_replace(array(
91 'name' => 'route',
92 'path' => '/',
93 'requirements' => array(),
94 'options' => array(),
95 'defaults' => array(),
96 'schemes' => array(),
97 'methods' => array(),
98 ), $routeDatas);
99
100 $this->reader
101 ->expects($this->once())
102 ->method('getMethodAnnotations')
103 ->will($this->returnValue(array($this->getAnnotatedRoute($routeDatas))))
104 ;
105 $routeCollection = $this->loader->load($className);
106 $route = $routeCollection->get($routeDatas['name']);
107
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');
112 }
113
114 private function getAnnotatedRoute($datas)
115 {
116 return new \Symfony\Component\Routing\Annotation\Route($datas);
117 }
118
119 }