Skip to content

Commit

Permalink
Star accept header (*/*) matches the first route (#30)
Browse files Browse the repository at this point in the history
* feature: deeper dynamic pages
closes #4

* feature: test matching star accept header
closes #19
  • Loading branch information
g105b authored Jan 17, 2023
1 parent 8fe302d commit e00c1e0
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion test/phpunit/BaseRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use Exception;
use Gt\Config\ConfigSection;
use Gt\Http\Request;
use Gt\Http\ResponseStatusException\AbstractResponseStatusException;
use Gt\Http\ResponseStatusException\ClientError\HttpNotAcceptable;
use Gt\Http\ResponseStatusException\ClientError\HttpNotFound;
use Gt\Http\ResponseStatusException\Redirection\HttpFound;
Expand Down Expand Up @@ -234,6 +233,7 @@ public function thisShouldNotMatchBecauseItsNothing():void {
throw new HttpNotFound();
}

/** @noinspection PhpUnused */
#[Any(path: "/something", accept: "application/json,application/xml")]
public function thisShouldMatch():void {
throw new Exception("Match!");
Expand All @@ -249,6 +249,45 @@ public function thisShouldNotMatchBecauseLessQuality():void {
$sut->route($request);
}

public function testRoute_matchesFirstRouteIfStarAccept():void {
$uri = self::createMock(Uri::class);
$uri->method("getPath")->willReturn("/something");
$request = self::createMock(Request::class);
$request->method("getUri")->willReturn($uri);
$request->method("getMethod")->willReturn("GET");
$request->method("getHeaderLine")
->with("accept")
->willReturn("*/*");

$sut = new class extends BaseRouter {
/** @noinspection PhpUnused */
#[Any(path: "/something", accept: "text/html")]
public function thisShouldNotMatch():void {
throw new Exception("Route 1");
}

/** @noinspection PhpUnused */
#[Any(path: "/something", accept: "fake/nothing")]
public function thisShouldNotMatchBecauseItsNothing():void {
throw new Exception("Route 2");
}

/** @noinspection PhpUnused */
#[Any(path: "/something", accept: "application/json,application/xml")]
public function thisShouldMatch():void {
throw new Exception("Route 3");
}

/** @noinspection PhpUnused */
#[Any(path: "/something", accept: "application/xhtml+xml,application/xml;q=0.8")]
public function thisShouldNotMatchBecauseLessQuality():void {
throw new Exception("Route 4");
}
};
self::expectExceptionMessage("Route 1");
$sut->route($request);
}

/** @dataProvider data_redirectCode */
public function testHandleRedirects_responseCodeFromConfig(
int $code,
Expand Down

0 comments on commit e00c1e0

Please sign in to comment.