From 1ddfd1bef7367ad13f3df2958d43863bb3bbbe1d Mon Sep 17 00:00:00 2001 From: Andras Ratz Date: Sun, 24 Aug 2014 14:33:20 +0200 Subject: [PATCH 1/4] Implement priority routes for annotated controller actions --- .../Component/Routing/Annotation/Route.php | 5 ++++ .../Routing/Loader/AnnotationClassLoader.php | 28 +++++++++++++++++++ .../Loader/AnnotationDirectoryLoader.php | 4 +++ .../Routing/Loader/AnnotationFileLoader.php | 4 +++ .../Loader/AnnotationClassLoaderTest.php | 8 +++++- .../Loader/AnnotationDirectoryLoaderTest.php | 24 ++++++++++++++++ .../Tests/Loader/AnnotationFileLoaderTest.php | 23 +++++++++++++++ 7 files changed, 95 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Routing/Annotation/Route.php b/src/Symfony/Component/Routing/Annotation/Route.php index 90521c0be8e0d..91cabb4e7faf3 100644 --- a/src/Symfony/Component/Routing/Annotation/Route.php +++ b/src/Symfony/Component/Routing/Annotation/Route.php @@ -120,6 +120,11 @@ public function getOptions() return $this->options; } + public function getOption($name) + { + return isset($this->options[$name]) ? $this->options[$name] : null; + } + public function setDefaults($defaults) { $this->defaults = $defaults; diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index f6d44252157a1..2ac406e54dcfd 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -72,6 +72,11 @@ abstract class AnnotationClassLoader implements LoaderInterface */ protected $defaultRouteIndex = 0; + /** + * @var array + */ + protected $routesWithPriority = array(); + /** * Constructor. * @@ -92,6 +97,11 @@ public function setRouteAnnotationClass($class) $this->routeAnnotationClass = $class; } + public function hasRoutesWithPriority() + { + return !empty($this->routesWithPriority); + } + /** * Loads from annotations from a class. * @@ -122,6 +132,10 @@ public function load($class, $type = null) $this->defaultRouteIndex = 0; foreach ($this->reader->getMethodAnnotations($method) as $annot) { if ($annot instanceof $this->routeAnnotationClass) { + if ($annot->getOption('priority')) { + $this->routesWithPriority[$annot->getOption('priority')][] + = array($annot, $globals, $class, $method); + } $this->addRoute($collection, $annot, $globals, $class, $method); } } @@ -130,6 +144,20 @@ public function load($class, $type = null) return $collection; } + public function adddPriorityRoutes() + { + krsort($this->routesWithPriority); + $collection = new RouteCollection(); + + foreach ($this->routesWithPriority as $priorityGroup) { + foreach ($priorityGroup as $route) { + $this->addRoute($collection, $route[0], $route[1], $route[2], $route[3]); + } + } + + return $collection; + } + protected function addRoute(RouteCollection $collection, $annot, $globals, \ReflectionClass $class, \ReflectionMethod $method) { $name = $annot->getName(); diff --git a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php index abd68ed6c4fab..9a08f2f42927d 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php @@ -58,6 +58,10 @@ public function load($path, $type = null) } } + if ($this->loader->hasRoutesWithPriority()) { + $collection->addCollection($this->loader->adddPriorityRoutes()); + } + return $collection; } diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index e54a0181c7861..edad8daa139a1 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -65,6 +65,10 @@ public function load($file, $type = null) $collection->addCollection($this->loader->load($class, $type)); } + if ($this->loader->hasRoutesWithPriority()) { + $collection->addCollection($this->loader->adddPriorityRoutes()); + } + return $collection; } diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php index 3b39a666edc26..de4b675eefcf9 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php @@ -91,6 +91,11 @@ public function getLoadTests() array('name' => 'route1', 'defaults' => array('arg2' => 'foo'), 'condition' => 'context.getMethod() == "GET"'), array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3') ), + array( + 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass', + array('name' => 'route_priority', 'options' => array('priority' => 10)), + array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3'), + ), ); } @@ -120,7 +125,8 @@ public function testLoad($className, $routeDatas = array(), $methodArgs = array( $this->assertSame($routeDatas['path'], $route->getPath(), '->load preserves path annotation'); $this->assertSame($routeDatas['requirements'],$route->getRequirements(), '->load preserves requirements annotation'); - $this->assertCount(0, array_intersect($route->getOptions(), $routeDatas['options']), '->load preserves options annotation'); + $this->assertSame(count($routeDatas['options']), count(array_intersect($route->getOptions(), $routeDatas['options'])), '->load preserves options annotation'); + $this->assertEquals(array_key_exists('priority', $routeDatas['options']), $this->loader->hasRoutesWithPriority()); $this->assertSame(array_replace($methodArgs, $routeDatas['defaults']), $route->getDefaults(), '->load preserves defaults annotation'); $this->assertEquals($routeDatas['condition'], $route->getCondition(), '->load preserves condition annotation'); } diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php index 29126ba4f2091..3161bb06e43be 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php @@ -13,6 +13,8 @@ use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader; use Symfony\Component\Config\FileLocator; +use Symfony\Component\Routing\Annotation\Route; + class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest { @@ -50,4 +52,26 @@ public function testSupports() $this->assertTrue($this->loader->supports($fixturesDir, 'annotation'), '->supports() checks the resource type if specified'); $this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified'); } + + public function testRoutesWithPriority() + { + $routeDatas = array( + 'foo' => new Route(array('name' => 'foo', 'path' => '/foo')), + 'bar' => new Route(array('name' => 'bar', 'path' => '/bar')), + 'static_id' => new Route(array('name' => 'static_id', 'path' => '/static/{id}', 'options' => array('priority' => 1))), + 'home' => new Route(array('name' => 'home', 'path' => '/home')), + 'static_contact' => new Route(array('name' => 'static_contact', 'path' => '/static/contact', 'options' => array('priority' => 5))), + 'login' => new Route(array('name' => 'login', 'path' => '/login')), + 'static_location' => new Route(array('name' => 'static_location', 'path' => '/static/location', 'options' => array('priority' => 5))), + ); + + $this->reader + ->expects($this->once()) + ->method('getMethodAnnotations') + ->will($this->returnValue($routeDatas)); + + $routeCollection = $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses'); + $expectedOrder = array('foo', 'bar', 'home', 'login', 'static_contact', 'static_location', 'static_id'); + $this->assertEquals($expectedOrder, array_keys($routeCollection->all())); + } } diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php index f0a8a0e329539..9408303532121 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Routing\Tests\Loader; +use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Loader\AnnotationFileLoader; use Symfony\Component\Config\FileLocator; @@ -44,4 +45,26 @@ public function testSupports() $this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified'); $this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified'); } + + public function testRoutesWithPriority() + { + $routeDatas = array( + 'foo' => new Route(array('name' => 'foo', 'path' => '/foo')), + 'bar' => new Route(array('name' => 'bar', 'path' => '/bar')), + 'static_id' => new Route(array('name' => 'static_id', 'path' => '/static/{id}', 'options' => array('priority' => 1))), + 'home' => new Route(array('name' => 'home', 'path' => '/home')), + 'static_contact' => new Route(array('name' => 'static_contact', 'path' => '/static/contact', 'options' => array('priority' => 5))), + 'login' => new Route(array('name' => 'login', 'path' => '/login')), + 'static_location' => new Route(array('name' => 'static_location', 'path' => '/static/location', 'options' => array('priority' => 5))), + ); + + $this->reader + ->expects($this->once()) + ->method('getMethodAnnotations') + ->will($this->returnValue($routeDatas)); + + $routeCollection = $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/BarClass.php'); + $expectedOrder = array('foo', 'bar', 'home', 'login', 'static_contact', 'static_location', 'static_id'); + $this->assertEquals($expectedOrder, array_keys($routeCollection->all())); + } } From fe825f3ed17dd53f6a317b5eb0e65b6e958034ac Mon Sep 17 00:00:00 2001 From: Andras Ratz Date: Sun, 24 Aug 2014 19:28:31 +0200 Subject: [PATCH 2/4] fix typo and coding standard error --- src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php | 2 +- .../Component/Routing/Loader/AnnotationDirectoryLoader.php | 2 +- src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php | 2 +- .../Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index 2ac406e54dcfd..b7aeaaf3253eb 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -144,7 +144,7 @@ public function load($class, $type = null) return $collection; } - public function adddPriorityRoutes() + public function addPriorityRoutes() { krsort($this->routesWithPriority); $collection = new RouteCollection(); diff --git a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php index 9a08f2f42927d..6df8c565d6abf 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php @@ -59,7 +59,7 @@ public function load($path, $type = null) } if ($this->loader->hasRoutesWithPriority()) { - $collection->addCollection($this->loader->adddPriorityRoutes()); + $collection->addCollection($this->loader->addPriorityRoutes()); } return $collection; diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index edad8daa139a1..eec45f76184f1 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -66,7 +66,7 @@ public function load($file, $type = null) } if ($this->loader->hasRoutesWithPriority()) { - $collection->addCollection($this->loader->adddPriorityRoutes()); + $collection->addCollection($this->loader->addPriorityRoutes()); } return $collection; diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php index 3161bb06e43be..370df10e8d384 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php @@ -15,7 +15,6 @@ use Symfony\Component\Config\FileLocator; use Symfony\Component\Routing\Annotation\Route; - class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest { protected $loader; From 3804ba9f2dd32e44cd3cbf64d859b8a7f03576e3 Mon Sep 17 00:00:00 2001 From: Andras Ratz Date: Mon, 25 Aug 2014 21:19:06 +0200 Subject: [PATCH 3/4] Put routes with priority in the front --- .../Routing/Loader/AnnotationClassLoader.php | 14 +++++++++++++- .../Routing/Loader/AnnotationDirectoryLoader.php | 2 +- .../Routing/Loader/AnnotationFileLoader.php | 2 +- .../Tests/Loader/AnnotationClassLoaderTest.php | 5 ----- .../Tests/Loader/AnnotationDirectoryLoaderTest.php | 2 +- .../Tests/Loader/AnnotationFileLoaderTest.php | 2 +- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index b7aeaaf3253eb..19d73e7916166 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -133,8 +133,10 @@ public function load($class, $type = null) foreach ($this->reader->getMethodAnnotations($method) as $annot) { if ($annot instanceof $this->routeAnnotationClass) { if ($annot->getOption('priority')) { + //These routes will be added to the collection later in File or Directory Loader $this->routesWithPriority[$annot->getOption('priority')][] = array($annot, $globals, $class, $method); + continue; } $this->addRoute($collection, $annot, $globals, $class, $method); } @@ -144,7 +146,16 @@ public function load($class, $type = null) return $collection; } - public function addPriorityRoutes() + /** + * Create a new collection of routes with priority + * These routes will be already sorted by priority + * and after that append all the other routes which + * don't have any priority + * + * @param $originalCollection + * @return RouteCollection + */ + public function addPriorityRoutes($originalCollection) { krsort($this->routesWithPriority); $collection = new RouteCollection(); @@ -154,6 +165,7 @@ public function addPriorityRoutes() $this->addRoute($collection, $route[0], $route[1], $route[2], $route[3]); } } + $collection->addCollection($originalCollection); return $collection; } diff --git a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php index 6df8c565d6abf..0ec6a0dddad8a 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php @@ -59,7 +59,7 @@ public function load($path, $type = null) } if ($this->loader->hasRoutesWithPriority()) { - $collection->addCollection($this->loader->addPriorityRoutes()); + $collection = $this->loader->addPriorityRoutes($collection); } return $collection; diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index eec45f76184f1..73479c5ddf7a3 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -66,7 +66,7 @@ public function load($file, $type = null) } if ($this->loader->hasRoutesWithPriority()) { - $collection->addCollection($this->loader->addPriorityRoutes()); + $collection = $this->loader->addPriorityRoutes($collection); } return $collection; diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php index de4b675eefcf9..65c5cea600e8e 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php @@ -91,11 +91,6 @@ public function getLoadTests() array('name' => 'route1', 'defaults' => array('arg2' => 'foo'), 'condition' => 'context.getMethod() == "GET"'), array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3') ), - array( - 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass', - array('name' => 'route_priority', 'options' => array('priority' => 10)), - array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3'), - ), ); } diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php index 370df10e8d384..aa46fbb4020b0 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php @@ -70,7 +70,7 @@ public function testRoutesWithPriority() ->will($this->returnValue($routeDatas)); $routeCollection = $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses'); - $expectedOrder = array('foo', 'bar', 'home', 'login', 'static_contact', 'static_location', 'static_id'); + $expectedOrder = array( 'static_contact', 'static_location', 'static_id', 'foo', 'bar', 'home', 'login'); $this->assertEquals($expectedOrder, array_keys($routeCollection->all())); } } diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php index 9408303532121..034d19bf2116d 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationFileLoaderTest.php @@ -64,7 +64,7 @@ public function testRoutesWithPriority() ->will($this->returnValue($routeDatas)); $routeCollection = $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/BarClass.php'); - $expectedOrder = array('foo', 'bar', 'home', 'login', 'static_contact', 'static_location', 'static_id'); + $expectedOrder = array( 'static_contact', 'static_location', 'static_id', 'foo', 'bar', 'home', 'login'); $this->assertEquals($expectedOrder, array_keys($routeCollection->all())); } } From 992e38627d59b9e36d4c9134025a244a5471baf6 Mon Sep 17 00:00:00 2001 From: Andras Ratz Date: Tue, 26 Aug 2014 14:33:09 +0200 Subject: [PATCH 4/4] add support for routes with negative priority value --- .../Routing/Loader/AnnotationClassLoader.php | 27 +++++-------------- .../Loader/AnnotationDirectoryLoader.php | 4 +-- .../Routing/Loader/AnnotationFileLoader.php | 4 +-- .../Loader/AnnotationClassLoaderTest.php | 6 ++++- .../Loader/AnnotationDirectoryLoaderTest.php | 3 ++- 5 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php index 19d73e7916166..8cb23305b13eb 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationClassLoader.php @@ -97,11 +97,6 @@ public function setRouteAnnotationClass($class) $this->routeAnnotationClass = $class; } - public function hasRoutesWithPriority() - { - return !empty($this->routesWithPriority); - } - /** * Loads from annotations from a class. * @@ -132,40 +127,32 @@ public function load($class, $type = null) $this->defaultRouteIndex = 0; foreach ($this->reader->getMethodAnnotations($method) as $annot) { if ($annot instanceof $this->routeAnnotationClass) { - if ($annot->getOption('priority')) { - //These routes will be added to the collection later in File or Directory Loader - $this->routesWithPriority[$annot->getOption('priority')][] - = array($annot, $globals, $class, $method); - continue; - } - $this->addRoute($collection, $annot, $globals, $class, $method); + $priority = (int) $annot->getOption('priority'); + $this->routesWithPriority[$priority][] = array($annot, $globals, $class, $method); } } } + $collection = $this->addPriorityRoutes($collection); + return $collection; } /** - * Create a new collection of routes with priority - * These routes will be already sorted by priority - * and after that append all the other routes which - * don't have any priority + * Add the prioritised routes to the collection * - * @param $originalCollection + * @param $collection * @return RouteCollection */ - public function addPriorityRoutes($originalCollection) + public function addPriorityRoutes($collection) { krsort($this->routesWithPriority); - $collection = new RouteCollection(); foreach ($this->routesWithPriority as $priorityGroup) { foreach ($priorityGroup as $route) { $this->addRoute($collection, $route[0], $route[1], $route[2], $route[3]); } } - $collection->addCollection($originalCollection); return $collection; } diff --git a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php index 0ec6a0dddad8a..4044b1a8bc8e9 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationDirectoryLoader.php @@ -58,9 +58,7 @@ public function load($path, $type = null) } } - if ($this->loader->hasRoutesWithPriority()) { - $collection = $this->loader->addPriorityRoutes($collection); - } + $collection = $this->loader->addPriorityRoutes($collection); return $collection; } diff --git a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php index 73479c5ddf7a3..5da11bab22960 100644 --- a/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/AnnotationFileLoader.php @@ -65,9 +65,7 @@ public function load($file, $type = null) $collection->addCollection($this->loader->load($class, $type)); } - if ($this->loader->hasRoutesWithPriority()) { - $collection = $this->loader->addPriorityRoutes($collection); - } + $collection = $this->loader->addPriorityRoutes($collection); return $collection; } diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php index 65c5cea600e8e..95b101c98f3f3 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationClassLoaderTest.php @@ -91,6 +91,11 @@ public function getLoadTests() array('name' => 'route1', 'defaults' => array('arg2' => 'foo'), 'condition' => 'context.getMethod() == "GET"'), array('arg2' => 'defaultValue2', 'arg3' =>'defaultValue3') ), + array( + 'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass', + array('name' => 'route1', 'options' => array('priority' => 10)), + array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3'), + ), ); } @@ -121,7 +126,6 @@ public function testLoad($className, $routeDatas = array(), $methodArgs = array( $this->assertSame($routeDatas['path'], $route->getPath(), '->load preserves path annotation'); $this->assertSame($routeDatas['requirements'],$route->getRequirements(), '->load preserves requirements annotation'); $this->assertSame(count($routeDatas['options']), count(array_intersect($route->getOptions(), $routeDatas['options'])), '->load preserves options annotation'); - $this->assertEquals(array_key_exists('priority', $routeDatas['options']), $this->loader->hasRoutesWithPriority()); $this->assertSame(array_replace($methodArgs, $routeDatas['defaults']), $route->getDefaults(), '->load preserves defaults annotation'); $this->assertEquals($routeDatas['condition'], $route->getCondition(), '->load preserves condition annotation'); } diff --git a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php index aa46fbb4020b0..5be8a25c394bb 100644 --- a/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php +++ b/src/Symfony/Component/Routing/Tests/Loader/AnnotationDirectoryLoaderTest.php @@ -56,6 +56,7 @@ public function testRoutesWithPriority() { $routeDatas = array( 'foo' => new Route(array('name' => 'foo', 'path' => '/foo')), + 'unimportant' => new Route(array('name' => 'unimportant', 'path' => '/unimportant', 'options' => array('priority' => -10))), 'bar' => new Route(array('name' => 'bar', 'path' => '/bar')), 'static_id' => new Route(array('name' => 'static_id', 'path' => '/static/{id}', 'options' => array('priority' => 1))), 'home' => new Route(array('name' => 'home', 'path' => '/home')), @@ -70,7 +71,7 @@ public function testRoutesWithPriority() ->will($this->returnValue($routeDatas)); $routeCollection = $this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses'); - $expectedOrder = array( 'static_contact', 'static_location', 'static_id', 'foo', 'bar', 'home', 'login'); + $expectedOrder = array( 'static_contact', 'static_location', 'static_id', 'foo', 'bar', 'home', 'login', 'unimportant'); $this->assertEquals($expectedOrder, array_keys($routeCollection->all())); } }