SiteWeaver_CMS/tests/unit/Core/RouterTest.php

34 lines
946 B
PHP
Raw Permalink Normal View History

2026-09-10 19:17:19 +00:00
<?php
declare(strict_types=1);
namespace Tests\unit\Core;
use SiteWeaver\Core\Router;
use PHPUnit\Framework\TestCase;
final class RouterTest extends TestCase
{
public function testRouteRegistrationAndDispatch(): void
{
$router = new Router();
$router->get('/users/{id}', fn($params) => 'handler', [], 'user_show');
$result = $router->dispatch('GET', '/users/42');
$this->assertNotNull($result);
$handler = $result['handler'];
$this->assertIsCallable($handler);
$this->assertSame('handler', ($handler)(['id' => '42']));
$this->assertEquals(['id' => '42'], $result['params']);
}
public function testUrlGeneration(): void
{
$router = new Router();
$router->get('/posts/{slug}', fn() => null, [], 'post_show');
$url = $router->url('post_show', ['slug' => 'hello-world']);
$this->assertSame('/posts/hello-world', $url);
}
}