Skip to content

Commit ff58201

Browse files
authored
Chore: Add alias e2e + integration test (#236)
1 parent d6b360d commit ff58201

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

tests/RouterTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,22 @@ public function testCanMatchAlias(): void
9696
$this->assertEquals($routeGET, Router::match(Http::REQUEST_METHOD_GET, '/alias2'));
9797
}
9898

99+
public function testCanMatchMultipleAliases(): void
100+
{
101+
$routeGET = new Route(Http::REQUEST_METHOD_GET, '/target');
102+
$routeGET
103+
->alias('/alias1')
104+
->alias('/alias2')
105+
->alias('/alias3');
106+
107+
Router::addRoute($routeGET);
108+
109+
$this->assertEquals($routeGET, Router::match(Http::REQUEST_METHOD_GET, '/target'));
110+
$this->assertEquals($routeGET, Router::match(Http::REQUEST_METHOD_GET, '/alias1'));
111+
$this->assertEquals($routeGET, Router::match(Http::REQUEST_METHOD_GET, '/alias2'));
112+
$this->assertEquals($routeGET, Router::match(Http::REQUEST_METHOD_GET, '/alias3'));
113+
}
114+
99115
public function testCanMatchMix(): void
100116
{
101117
$routeGET = new Route(Http::REQUEST_METHOD_GET, '/');

tests/e2e/BaseTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,15 @@ public function testSetCookie()
4343
$this->assertEquals('value1', $response['cookies']['key1']);
4444
$this->assertEquals('value2', $response['cookies']['key2']);
4545
}
46+
47+
public function testAliases()
48+
{
49+
$paths = ['/aliased', '/aliased-1', '/aliased-2', '/aliased-3'];
50+
51+
foreach ($paths as $path) {
52+
$response = $this->client->call(Client::METHOD_GET, $path);
53+
$this->assertEquals(200, $response['headers']['status-code']);
54+
$this->assertEquals('Aliased!', $response['body']);
55+
}
56+
}
4657
}

tests/e2e/init.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,12 @@
7070
->action(function (Response $response) {
7171
$response->noContent();
7272
});
73+
74+
Http::get('/aliased')
75+
->alias('/aliased-1')
76+
->alias('/aliased-2')
77+
->alias('/aliased-3')
78+
->inject('response')
79+
->action(function (Response $response) {
80+
$response->send('Aliased!');
81+
});

0 commit comments

Comments
 (0)