Skip to content

Commit

Permalink
Fix NotFoundException does not contain route name
Browse files Browse the repository at this point in the history
  • Loading branch information
ElGigi committed Dec 3, 2024
1 parent 74eded0 commit 230eb62
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

Expand Down

0 comments on commit 230eb62

Please sign in to comment.