소스 검색

[Routing] added some unit tests for latest merge (and fixed a bug ;))

Fabien Potencier 14 년 전
부모
커밋
1438f6be04

+ 2 - 0
src/Symfony/Component/Routing/Matcher/Dumper/PhpMatcherDumper.php

@@ -73,6 +73,7 @@ EOF;
     {
         $code = array();
 
+        $routes = clone $routes;
         $routeIterator = $routes->getIterator();
         $keys = array_keys($routeIterator->getArrayCopy());
         $keysCount = count($keys);
@@ -82,6 +83,7 @@ EOF;
         foreach ($routeIterator as $name => $route) {
             $i++;
 
+            $route = clone $route;
             if ($route instanceof RouteCollection) {
                 $prefix = $route->getPrefix();
                 $optimizable = $prefix && count($route->all()) > 1 && false === strpos($route->getPrefix(), '{');

+ 13 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher1.php

@@ -113,8 +113,21 @@ class ProjectUrlMatcher extends Symfony\Component\Routing\Matcher\UrlMatcher
                     return $matches;
                 }
         
+                throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
             }
     
+            // ababa
+            if ($pathinfo === '/ababa') {
+                return array('_route' => 'ababa');
+            }
+    
+            // foo
+            if (preg_match('#^/aba/(?P<foo>[^/]+?)$#x', $pathinfo, $matches)) {
+                $matches['_route'] = 'foo';
+                return $matches;
+            }
+    
+            throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
         }
 
         // foo

+ 13 - 0
tests/Symfony/Tests/Component/Routing/Fixtures/dumper/url_matcher2.php

@@ -125,8 +125,21 @@ class ProjectUrlMatcher extends Symfony\Tests\Component\Routing\Fixtures\Redirec
                     return $matches;
                 }
         
+                throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
             }
     
+            // ababa
+            if ($pathinfo === '/ababa') {
+                return array('_route' => 'ababa');
+            }
+    
+            // foo
+            if (preg_match('#^/aba/(?P<foo>[^/]+?)$#x', $pathinfo, $matches)) {
+                $matches['_route'] = 'foo';
+                return $matches;
+            }
+    
+            throw 0 < count($allow) ? new MethodNotAllowedException(array_unique($allow)) : new ResourceNotFoundException();
         }
 
         // foo

+ 7 - 0
tests/Symfony/Tests/Component/Routing/Matcher/Dumper/PhpMatcherDumperTest.php

@@ -90,6 +90,13 @@ class PhpMatcherDumperTest extends \PHPUnit_Framework_TestCase
         $collection2->addCollection($collection1, '/b');
         $collection->addCollection($collection2, '/{_locale}');
 
+        $collection->add('ababa', new Route('/ababa'));
+
+        // some more prefixes
+        $collection1 = new RouteCollection();
+        $collection1->add('foo', new Route('/{foo}'));
+        $collection->addCollection($collection1, '/aba');
+
         $dumper = new PhpMatcherDumper($collection, new RequestContext());
         $this->assertStringEqualsFile(__DIR__.'/../../Fixtures/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');