From 42856ff7dfc6bca3d353652c3c6fca493068ad77 Mon Sep 17 00:00:00 2001 From: Elias De Vos Date: Wed, 24 Jan 2018 09:07:54 +0100 Subject: [PATCH] change method name and return type --- src/Routing/Router.php | 13 ++++++------- tests/TestCase/Routing/RouterTest.php | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Routing/Router.php b/src/Routing/Router.php index 537deb76997..f4d33475587 100644 --- a/src/Routing/Router.php +++ b/src/Routing/Router.php @@ -686,9 +686,7 @@ public static function url($url = null, $full = false) /** * 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 @@ public static function url($url = null, $full = false) * 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; } } diff --git a/tests/TestCase/Routing/RouterTest.php b/tests/TestCase/Routing/RouterTest.php index 69bb078175e..9f6853956af 100644 --- a/tests/TestCase/Routing/RouterTest.php +++ b/tests/TestCase/Routing/RouterTest.php @@ -130,16 +130,16 @@ public function testRouteDefaultParams() } /** - * 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'])); } /**