From 230eb62c980cc339413a0c5b41aada6c3106e120 Mon Sep 17 00:00:00 2001 From: Ronan Giron Date: Tue, 3 Dec 2024 18:03:45 +0100 Subject: [PATCH] Fix `NotFoundException` does not contain route name --- CHANGELOG.md | 6 ++++++ src/Router.php | 4 ++-- tests/RouterTest.php | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 54ea5f5..e381e92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. This projec to [Semantic Versioning] (http://semver.org/). For change log format, use [Keep a Changelog] (http://keepachangelog.com/). +## [2.5.1] - 2024-12-03 + +### Fixed + +- `NotFoundException` does not contain route name + ## [2.5.0] - 2024-12-03 ### Added diff --git a/src/Router.php b/src/Router.php index d5c5529..89e2c10 100644 --- a/src/Router.php +++ b/src/Router.php @@ -103,10 +103,10 @@ protected function log(string $level, string $message): void public function generate(string|RouteInterface $route, array|RouteAttributes $parameters = []): string { $parameters = $this->generateParameters($parameters); - is_string($route) && $route = $this->getRoute($route); + is_string($route) && $route = $this->getRoute($routeName = $route); if (null === $route) { - throw new NotFoundException(sprintf('Route "%s" does not exists', $route)); + throw new NotFoundException(sprintf('Route "%s" does not exists', $routeName)); } return $this->finalizePath($route->generate($parameters)); diff --git a/tests/RouterTest.php b/tests/RouterTest.php index f5343c9..b607dff 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -182,6 +182,7 @@ public function testGenerateWithNotFoundRoute() $router->addRoute(new Route('/path/{attr1}/sub-path', name: 'route1')); $this->expectException(NotFoundException::class); + $this->expectExceptionMessage('Route "route2" does not exists'); $router->generate('route2', ['attr2' => 'test2']); }