Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions tests/Unit/Middleware/ApiContractMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ class ApiContractMiddlewareTest extends TestCase {
*
* @param string|false $path The request path info.
* @param Response $response The controller response.
* @param string|null $uri The request URI; null puts `/index.php` before the path.
*
* @return Response The decorated response.
*/
private function decorate(string|false $path, Response $response): Response {
private function decorate(string|false $path, Response $response, ?string $uri = null): Response {
$request = $this->createMock(originalClassName: IRequest::class);
$request->method('getPathInfo')->willReturn($path);
$request->method('getRequestUri')->willReturn('/index.php'.(string) $path.'?q=1');
$request->method('getRequestUri')->willReturn($uri ?? '/index.php'.(string) $path.'?q=1');
$appManager = $this->createMock(originalClassName: IAppManager::class);
$appManager->method('getAppVersion')->willReturn('1.2.3');

Expand Down Expand Up @@ -198,6 +199,24 @@ public function testUnversionedPathAnnouncesItsSuccessor(): void {
$this->assertSame(expected: '</index.php/apps/launchpad/api/v1/things/7/parts>; rel="successor-version"', actual: $headers['Link']);
}//end testUnversionedPathAnnouncesItsSuccessor()

/**
* When the request URI does not contain the path info (a rewritten URL), the
* successor link carries no front-controller prefix.
*
* @return void
*/
public function testSuccessorLinkHasNoPrefixWhenTheUriLacksThePath(): void {
$response = $this->decorate(
path: '/apps/launchpad/api/things/7/parts',
response: new JSONResponse(data: ['id' => 7]),
uri: '/rewritten/elsewhere'
);
$headers = $this->headersOf(response: $response);

$this->assertSame(expected: '@1794441600', actual: $headers['Deprecation']);
$this->assertSame(expected: '</apps/launchpad/api/v1/things/7/parts>; rel="successor-version"', actual: $headers['Link']);
}//end testSuccessorLinkHasNoPrefixWhenTheUriLacksThePath()

/**
* A versioned API path is not deprecated, and still carries the version.
*
Expand Down