Browse Source

[Routing] Use routing exceptions in the dumper and add tests.

alexandresalome 14 years ago
parent
commit
1d6b94189b

+ 3 - 1
src/Symfony/Component/Routing/Generator/Dumper/PhpGeneratorDumper.php

@@ -77,7 +77,7 @@ EOF
     public function generate(\$name, array \$parameters = array(), \$absolute = false)
     {
         if (!isset(self::\$declaredRouteNames[\$name])) {
-            throw new \InvalidArgumentException(sprintf('Route "%s" does not exist.', \$name));
+            throw new NotExistingRouteException(sprintf('Route "%s" does not exist.', \$name));
         }
 
         \$escapedName = str_replace('.', '__', \$name);
@@ -103,6 +103,8 @@ EOF;
 <?php
 
 use Symfony\Component\Routing\RequestContext;
+use Symfony\Component\Routing\Exception\NotExistingRouteException;
+
 
 /**
  * $class

+ 14 - 0
tests/Symfony/Tests/Component/Routing/Generator/Dumper/PhpGeneratorDumperTest.php

@@ -84,6 +84,20 @@ class PhpGeneratorDumperTest extends \PHPUnit_Framework_TestCase
         $projectUrlGenerator->generate('Test', array());
     }
 
+    /**
+     * @expectedException Symfony\Component\Routing\Exception\NotExistingRouteException
+     */
+    public function testGenerateNonExistingRoute()
+    {
+        $this->routeCollection->add('Test', new Route('/test'));
+
+        file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(array('class' => 'NonExistingRoutesUrlGenerator')));
+        include ($this->testTmpFilepath);
+
+        $projectUrlGenerator = new \NonExistingRoutesUrlGenerator(new RequestContext());
+        $url = $projectUrlGenerator->generate('NonExisting', array());
+    }
+
     public function testDumpForRouteWithDefaults()
     {
         $this->routeCollection->add('Test', new Route('/testing/{foo}', array('foo' => 'bar')));