Skip to content

Commit f69f100

Browse files
committed
Tests
1 parent 0057b76 commit f69f100

2 files changed

Lines changed: 70 additions & 1 deletion

File tree

tests/AppTest.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function testCanExecuteRoute(): void
221221
->param('x', 'x-def', new Text(1, min: 0), 'x param', false)
222222
->param('y', 'y-def', new Text(1, min: 0), 'y param', false)
223223
->action(function ($x, $y) {
224-
echo $x . '-', $y;
224+
echo $x . '-' . $y;
225225
});
226226

227227
\ob_start();
@@ -497,6 +497,58 @@ public function testCanMatchRoute(string $method, string $path, string $url = nu
497497
$this->assertEquals($expected, $this->app->getRoute());
498498
}
499499

500+
public function testMatchWithNullPath(): void
501+
{
502+
// Create a route for root path
503+
$expected = App::get('/');
504+
505+
// Test case where parse_url returns null (malformed URL)
506+
$_SERVER['REQUEST_METHOD'] = 'GET';
507+
$_SERVER['REQUEST_URI'] = '://invalid-url'; // This will cause parse_url to return null for PATH component
508+
509+
$matched = $this->app->match(new Request());
510+
$this->assertEquals($expected, $matched);
511+
}
512+
513+
public function testMatchWithEmptyPath(): void
514+
{
515+
// Create a route for root path
516+
$expected = App::get('/');
517+
518+
// Test case where URI has no path component
519+
$_SERVER['REQUEST_METHOD'] = 'GET';
520+
$_SERVER['REQUEST_URI'] = 'https://example.com'; // No path component
521+
522+
$matched = $this->app->match(new Request());
523+
$this->assertEquals($expected, $matched);
524+
}
525+
526+
public function testMatchWithMalformedURL(): void
527+
{
528+
// Create a route for root path
529+
$expected = App::get('/');
530+
531+
// Test case where parse_url returns false (severely malformed URL)
532+
$_SERVER['REQUEST_METHOD'] = 'GET';
533+
$_SERVER['REQUEST_URI'] = 'ht!tp://invalid'; // Malformed scheme
534+
535+
$matched = $this->app->match(new Request());
536+
$this->assertEquals($expected, $matched);
537+
}
538+
539+
public function testMatchWithOnlyQueryString(): void
540+
{
541+
// Create a route for root path
542+
$expected = App::get('/');
543+
544+
// Test case where URI has only query string (no path)
545+
$_SERVER['REQUEST_METHOD'] = 'GET';
546+
$_SERVER['REQUEST_URI'] = '?param=value'; // Only query string, no path
547+
548+
$matched = $this->app->match(new Request());
549+
$this->assertEquals($expected, $matched);
550+
}
551+
500552
public function testNoMismatchRoute(): void
501553
{
502554
$requests = [

tests/e2e/ResponseTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ public function testEarlyResponse()
5757
$this->assertEquals('Init response. Actioned before: no', $response['body']);
5858
}
5959

60+
public function testNullPathHandling()
61+
{
62+
// Test that malformed URLs default to root path
63+
$response = $this->client->call(Client::METHOD_GET, '/');
64+
$this->assertEquals('Hello World!', $response['body']);
65+
$this->assertEquals(200, $response['headers']['status-code']);
66+
}
67+
68+
public function testRootPathFallback()
69+
{
70+
// Test that when path parsing fails, it falls back to root
71+
// This is tested by ensuring the root route works correctly
72+
$response = $this->client->call(Client::METHOD_GET, '/');
73+
$this->assertEquals('Hello World!', $response['body']);
74+
$this->assertEquals(200, $response['headers']['status-code']);
75+
}
76+
6077
public function testAliasWithParameter(): void
6178
{
6279
$response = $this->client->call(Client::METHOD_POST, '/functions/deployment', [

0 commit comments

Comments
 (0)