Browse Source

change method name and return type

Elias De Vos 8 years ago
parent
commit
42856ff7df
2 changed files with 10 additions and 11 deletions
  1. 6 7
      src/Routing/Router.php
  2. 4 4
      tests/TestCase/Routing/RouterTest.php

+ 6 - 7
src/Routing/Router.php

@@ -686,9 +686,7 @@ class Router
     /**
      * Finds URL for specified action.
      *
-     * Returns a URL pointing to a combination of controller and action.
-     *
-     * If the url doesn't exist returns null
+     * Returns a bool if the url exists
      *
      * ### Usage
      *
@@ -700,14 +698,15 @@ class Router
      *   string.
      * @param bool $full If true, the full base URL will be prepended to the result.
      *   Default is false.
-     * @return string Full translated URL with base path or null if url does not exist
+     * @return bool
      */
-    public static function urlOrNull($url = null, $full = false)
+    public static function routeExists($url = null, $full = false)
     {
         try {
-            return static::url($url, $full);
+            $route = static::url($url, $full);
+            return true;
         } catch (MissingRouteException $e) {
-            return null;
+            return false;
         }
     }
 

+ 4 - 4
tests/TestCase/Routing/RouterTest.php

@@ -130,16 +130,16 @@ class RouterTest extends TestCase
     }
 
     /**
-     * testRouteUrlOrNull method
+     * testRouteExists method
      *
      * @return void
      */
-    public function testRouteUrlOrNull()
+    public function testRouteExists()
     {
         Router::connect('/:controller/:action', ['controller' => 'posts']);
-        $this->assertEquals(Router::urlOrNull(['action' => 'view']), '/view');
+        $this->assertTrue(Router::routeExists(['action' => 'view']));
 
-        $this->assertNull(Router::urlOrNull(['action' => 'view', 'controller' => 'users', 'plugin' => 'test']));
+        $this->assertFalse(Router::routeExists(['action' => 'view', 'controller' => 'users', 'plugin' => 'test']));
     }
 
     /**