diff --git a/src/Core/Router/RouteLoader.php b/src/Core/Router/RouteLoader.php index 4f0bcf88cf..195151b304 100644 --- a/src/Core/Router/RouteLoader.php +++ b/src/Core/Router/RouteLoader.php @@ -83,10 +83,10 @@ class RouteLoader extends Loader $this->rc->add($id, new Route( // path -- URI path - $uri_path, + path: $uri_path, // defaults = [] -- param default values, // and special configuration options - array_merge( + defaults: array_merge( [ '_controller' => is_array($target) ? $target : [$target, '__invoke'], '_format' => $options['format'] ?? 'html', @@ -97,21 +97,21 @@ class RouteLoader extends Loader $options['defaults'] ?? [] ), // requirements = [] -- param => regex - $param_reqs, + requirements: $param_reqs, // options = [] -- possible keys: compiler_class:, utf8 // No need for a special compiler class for now, // Enforce UTF8 - ['utf8' => true], + options: ['utf8' => true], // host = '' -- hostname (subdomain, for instance) to match, // we don't want this - '', + host: '', // schemes = [] -- URI schemes (https, ftp and such) - $options['schemes'] ?? [], + schemes: $options['schemes'] ?? [], // methods = [] -- HTTP methods - $options['http-methods'] ?? $options['methods'] ?? [], + methods: $options['http-methods'] ?? $options['methods'] ?? [], // condition = '' -- Symfony condition expression, // see https://symfony.com/doc/current/routing.html#matching-expressions - $options['condition'] ?? '' + condition: $options['condition'] ?? '' ) ); } @@ -122,6 +122,7 @@ class RouteLoader extends Loader * `config/routes.php` * * @param mixed $resource + * @codeCoverageIgnore */ public function supports($resource, ?string $type = null): bool { diff --git a/tests/Core/RouterTest.php b/tests/Core/RouterTest.php new file mode 100644 index 0000000000..c507c6034e --- /dev/null +++ b/tests/Core/RouterTest.php @@ -0,0 +1,53 @@ +. + +// }}} + +namespace App\Tests\Core; + +use App\Core\Router\RouteLoader; +use App\Core\Router\Router; +use App\Util\GNUsocialTestCase; +use Symfony\Component\Routing\Route as SRoute; + +class RouterTest extends GNUsocialTestCase +{ + public function testRouter() + { + parent::bootKernel(); + $rl = new RouteLoader(); + $rl->load('', null); // parameters ignored + + $rl->connect(id: 'test_route', uri_path: '/test/{id<\d+>}', target: []); + + $refl = (new \ReflectionClass($rl))->getProperty('rc'); + $refl->setAccessible(true); + $routes = $refl->getValue($rl)->all(); + static::assertIsArray($routes); + + static::assertInstanceOf(SRoute::class, $routes['test_route']); + static::assertSame('/test/{id}', $routes['test_route']->getPath()); + } + + public function testURLGen() + { + parent::bootKernel(); + static::assertSame('/thumbnail/1', Router::url('thumbnail', ['id' => 1])); + } +}