Browse Source

add the route name to the check subcommand

antograssiot 10 years ago
parent
commit
569dfd2df0
2 changed files with 30 additions and 2 deletions
  1. 7 1
      src/Shell/RoutesShell.php
  2. 23 1
      tests/TestCase/Shell/RoutesShellTest.php

+ 7 - 1
src/Shell/RoutesShell.php

@@ -54,9 +54,15 @@ class RoutesShell extends Shell
     {
         try {
             $route = Router::parse($url);
+            foreach (Router::routes() as $r) {
+                if ($r->match($route)) {
+                    $name = isset($r->options['_name']) ? $r->options['_name'] : $r->getName();
+                    break;
+                }
+            }
             $output = [
                 ['Route name', 'URI template', 'Defaults'],
-                ['', $url, json_encode($route)]
+                [$name, $url, json_encode($route)]
             ];
             $this->helper('table')->output($output);
         } catch (MissingRouteException $e) {

+ 23 - 1
tests/TestCase/Shell/RoutesShellTest.php

@@ -105,7 +105,7 @@ class RoutesShellTest extends TestCase
                 $this->logicalAnd(
                     $this->contains(['Route name', 'URI template', 'Defaults']),
                     $this->contains([
-                        '',
+                        'articles:_action',
                         '/articles/index',
                         '{"action":"index","pass":[],"controller":"Articles","plugin":null}'
                     ])
@@ -115,6 +115,28 @@ class RoutesShellTest extends TestCase
     }
 
     /**
+     * Test checking an existing route with named route.
+     *
+     * @return void
+     */
+    public function testCheckWithNamedRoute()
+    {
+        $this->table->expects($this->once())
+            ->method('output')
+            ->with(
+                $this->logicalAnd(
+                    $this->contains(['Route name', 'URI template', 'Defaults']),
+                    $this->contains([
+                        'testName',
+                        '/tests/index',
+                        '{"action":"index","pass":[],"controller":"Tests","plugin":null}'
+                    ])
+                )
+            );
+        $this->shell->check('/tests/index');
+    }
+
+    /**
      * Test checking an non-existing route.
      *
      * @return void