diff --git a/CHANGELOG.md b/CHANGELOG.md index a15a7a9..e42b400 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +v3.2.1 +- Fix `getActionName()` output + v3.2.0 - Add `getRoutes()` method to Router - Add `getActionName()` method to Route diff --git a/src/Route.php b/src/Route.php index c37e3e9..a811fad 100644 --- a/src/Route.php +++ b/src/Route.php @@ -183,14 +183,18 @@ public function getActionName() { $callableName = null; - if (isset($this->controllerName)) { - return $this->controllerName; + if (isset($this->controllerName) && isset($this->controllerMethod)) { + return $this->controllerName . '@' . $this->controllerMethod; } if (is_callable($this->action, false, $callableName)) { list($controller, $method) = explode('::', $callableName); - return $controller; + if ($controller === 'Closure') { + return $controller; + } + + return $controller . '@' . $method; } } } diff --git a/tests/RouteTest.php b/tests/RouteTest.php index 88d7097..cdbcdb3 100644 --- a/tests/RouteTest.php +++ b/tests/RouteTest.php @@ -79,7 +79,7 @@ public function can_get_route_action_name_when_callable() $router = new Router; $route = $router->get('test/123', [TestCallableController::class, 'testStatic']); - $this->assertSame(TestCallableController::class, $route->getActionName()); + $this->assertSame(TestCallableController::class.'@testStatic', $route->getActionName()); } /** @test */ @@ -89,7 +89,7 @@ public function can_get_route_action_name_when_callable_instance() $controller = new TestCallableController; $route = $router->get('test/123', [$controller, 'test']); - $this->assertSame(TestCallableController::class, $route->getActionName()); + $this->assertSame(TestCallableController::class.'@test', $route->getActionName()); } /** @test */ @@ -98,7 +98,7 @@ public function can_get_route_action_name_when_controller_string() $router = new Router; $route = $router->get('test/123', TestCallableController::class.'@test'); - $this->assertSame(TestCallableController::class, $route->getActionName()); + $this->assertSame(TestCallableController::class.'@test', $route->getActionName()); } }