diff --git a/tests/RouterTest.php b/tests/RouterTest.php index 9aed6a7..bfaa544 100644 --- a/tests/RouterTest.php +++ b/tests/RouterTest.php @@ -96,6 +96,22 @@ public function testCanMatchAlias(): void $this->assertEquals($routeGET, Router::match(Http::REQUEST_METHOD_GET, '/alias2')); } + public function testCanMatchMultipleAliases(): void + { + $routeGET = new Route(Http::REQUEST_METHOD_GET, '/target'); + $routeGET + ->alias('/alias1') + ->alias('/alias2') + ->alias('/alias3'); + + Router::addRoute($routeGET); + + $this->assertEquals($routeGET, Router::match(Http::REQUEST_METHOD_GET, '/target')); + $this->assertEquals($routeGET, Router::match(Http::REQUEST_METHOD_GET, '/alias1')); + $this->assertEquals($routeGET, Router::match(Http::REQUEST_METHOD_GET, '/alias2')); + $this->assertEquals($routeGET, Router::match(Http::REQUEST_METHOD_GET, '/alias3')); + } + public function testCanMatchMix(): void { $routeGET = new Route(Http::REQUEST_METHOD_GET, '/'); diff --git a/tests/e2e/BaseTest.php b/tests/e2e/BaseTest.php index 9a9d453..07f9427 100644 --- a/tests/e2e/BaseTest.php +++ b/tests/e2e/BaseTest.php @@ -43,4 +43,15 @@ public function testSetCookie() $this->assertEquals('value1', $response['cookies']['key1']); $this->assertEquals('value2', $response['cookies']['key2']); } + + public function testAliases() + { + $paths = ['/aliased', '/aliased-1', '/aliased-2', '/aliased-3']; + + foreach ($paths as $path) { + $response = $this->client->call(Client::METHOD_GET, $path); + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('Aliased!', $response['body']); + } + } } diff --git a/tests/e2e/init.php b/tests/e2e/init.php index e521265..9f410ce 100644 --- a/tests/e2e/init.php +++ b/tests/e2e/init.php @@ -70,3 +70,12 @@ ->action(function (Response $response) { $response->noContent(); }); + +Http::get('/aliased') + ->alias('/aliased-1') + ->alias('/aliased-2') + ->alias('/aliased-3') + ->inject('response') + ->action(function (Response $response) { + $response->send('Aliased!'); + });