diff options
| author | Brett Parson <brett@brett-parson.com> | 2026-08-29 15:56:31 -0500 |
|---|---|---|
| committer | Brett Parson <brett@brett-parson.com> | 2026-08-29 15:56:31 -0500 |
| commit | 965551532d684456b74baf960157c0c2cef7335d (patch) | |
| tree | 1445afbc47730caa11d08fd84d9d65db132821f5 /tests/RouterTest.php | |
| parent | d039a5d62a9ac6ababae70d9d96422ca59f2b2d4 (diff) | |
| download | miniroute-965551532d684456b74baf960157c0c2cef7335d.tar.gz miniroute-965551532d684456b74baf960157c0c2cef7335d.zip | |
Add regression and integration test suite
Port the stress-test findings into PHPUnit: realistic brett-parson.com
route model, known-issue baselines, router boundary cases, and a
standalone scaling benchmark (composer bench).
Diffstat (limited to 'tests/RouterTest.php')
| -rw-r--r-- | tests/RouterTest.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/RouterTest.php b/tests/RouterTest.php index b8d4d49..3279ede 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -8,10 +8,12 @@ use ArrayObject; use BrettParson\MiniRoute\Routing\RouteNotFoundException; use BrettParson\MiniRoute\Routing\RouteRegistrationException; use BrettParson\MiniRoute\Routing\Router; +use BrettParson\MiniRoute\Tests\Fixtures\CollidingController; use BrettParson\MiniRoute\Tests\Fixtures\FakeController; use BrettParson\MiniRoute\Tests\Fixtures\FakeMiddleware; use BrettParson\MiniRoute\Tests\Fixtures\FakeResolver; use BrettParson\MiniRoute\Tests\Fixtures\TestRequest; +use BrettParson\MiniRoute\Tests\Fixtures\TestResponse; use PHPUnit\Framework\TestCase; final class RouterTest extends TestCase @@ -78,4 +80,63 @@ final class RouterTest extends TestCase $this->expectException(RouteNotFoundException::class); $router->dispatch(new TestRequest('GET', '/missing')); } + + public function testNotFoundHandlerIsCalledWhenSet(): void + { + [$router] = $this->makeRouter(); + $router->registerController(FakeController::class); + $router->setNotFoundHandler(static fn (): TestResponse => new TestResponse(404, 'custom-nf')); + + $response = $router->dispatch(new TestRequest('GET', '/missing')); + + $this->assertSame(404, $response->status()); + $this->assertSame('custom-nf', $response->body()); + } + + public function testTrailingSlashIsNormalized(): void + { + [$router] = $this->makeRouter(); + $router->registerController(FakeController::class); + + $response = $router->dispatch(new TestRequest('GET', '/entries/')); + + $this->assertSame('index', $response->body()); + } + + public function testMethodIsCaseInsensitive(): void + { + [$router] = $this->makeRouter(); + $router->registerController(FakeController::class); + + $response = $router->dispatch(new TestRequest('get', '/entries')); + + $this->assertSame('index', $response->body()); + } + + public function testLeadingDoubleSlashDoesNotMatch(): void + { + [$router] = $this->makeRouter(); + $router->registerController(FakeController::class); + + $this->expectException(RouteNotFoundException::class); + $router->dispatch(new TestRequest('GET', '//entries')); + } + + public function testPathsAreCaseSensitive(): void + { + [$router] = $this->makeRouter(); + $router->registerController(FakeController::class); + + $this->expectException(RouteNotFoundException::class); + $router->dispatch(new TestRequest('GET', '/Entries')); + } + + public function testDuplicateRouteAcrossControllersThrows(): void + { + [$router] = $this->makeRouter(); + $router->registerController(FakeController::class); + + $this->expectException(RouteRegistrationException::class); + $router->registerController(CollidingController::class); + } } |
