From f2b929d870ad5bda0b8cb796cc013b5a4918d0a2 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Tue, 18 Feb 2025 16:27:19 +0100 Subject: [PATCH] IBX-9587: Fixed failing REST requests after Symfony 6 upgrade (#145) * Fixed OPTIONS controller reference * [Tests] Aligned MapperTest with OPTIONS controller reference fix * [Tests] Fixed incorrect case for named test prefix in LocationTest * Fixed obsolete single-colon SessionController reference * [Tests] Fixed functional BookmarkTest to be self-contained --- src/bundle/Resources/config/routing.yml | 2 +- src/bundle/Routing/OptionsLoader/Mapper.php | 9 +--- tests/bundle/Functional/BookmarkTest.php | 48 +++++++++++++------ tests/bundle/Functional/LocationTest.php | 2 +- .../Routing/OptionsLoader/MapperTest.php | 2 +- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/bundle/Resources/config/routing.yml b/src/bundle/Resources/config/routing.yml index 62cd4fa93..d5c6a3a2a 100644 --- a/src/bundle/Resources/config/routing.yml +++ b/src/bundle/Resources/config/routing.yml @@ -40,7 +40,7 @@ ibexa.rest.delete_section: ibexa.rest.refresh_session: path: /user/sessions/{sessionId}/refresh - controller: Ibexa\Rest\Server\Controller\SessionController:refreshSessionAction + controller: Ibexa\Rest\Server\Controller\SessionController::refreshSessionAction defaults: csrf_protection: false methods: [POST] diff --git a/src/bundle/Routing/OptionsLoader/Mapper.php b/src/bundle/Routing/OptionsLoader/Mapper.php index 33a6f323d..a6d92ec12 100644 --- a/src/bundle/Routing/OptionsLoader/Mapper.php +++ b/src/bundle/Routing/OptionsLoader/Mapper.php @@ -14,18 +14,13 @@ */ class Mapper { - /** - * @param $route Route REST route - * - * @return \Symfony\Component\Routing\Route - */ - public function mapRoute(Route $route) + public function mapRoute(Route $route): Route { $optionsRoute = clone $route; $optionsRoute->setMethods(['OPTIONS']); $optionsRoute->setDefault( '_controller', - 'Ibexa\Rest\Server\Controller\Options:getRouteOptions' + 'Ibexa\Rest\Server\Controller\Options::getRouteOptions' ); $optionsRoute->setDefault( diff --git a/tests/bundle/Functional/BookmarkTest.php b/tests/bundle/Functional/BookmarkTest.php index 3a5c7c74e..1c79d60f7 100644 --- a/tests/bundle/Functional/BookmarkTest.php +++ b/tests/bundle/Functional/BookmarkTest.php @@ -13,6 +13,9 @@ class BookmarkTest extends RESTFunctionalTestCase { + /** + * @throws \Psr\Http\Client\ClientExceptionInterface + */ public function testCreateBookmark(): int { $content = $this->createFolder(__FUNCTION__, '/api/ibexa/v2/content/locations/1/2'); @@ -28,13 +31,15 @@ public function testCreateBookmark(): int $response = $this->sendHttpRequest($request); - self::assertHttpResponseCodeEquals($response, Response::HTTP_CREATED); + $this->assertHttpResponseCodeEquals($response, Response::HTTP_CREATED); return $locationId; } /** * @depends testCreateBookmark + * + * @throws \Psr\Http\Client\ClientExceptionInterface */ public function testCreateBookmarkIfAlreadyExists(int $locationId): void { @@ -45,11 +50,13 @@ public function testCreateBookmarkIfAlreadyExists(int $locationId): void $response = $this->sendHttpRequest($request); - self::assertHttpResponseCodeEquals($response, Response::HTTP_CONFLICT); + $this->assertHttpResponseCodeEquals($response, Response::HTTP_CONFLICT); } /** * @depends testCreateBookmark + * + * @throws \Psr\Http\Client\ClientExceptionInterface */ public function testIsBookmarked(int $locationId): void { @@ -60,13 +67,16 @@ public function testIsBookmarked(int $locationId): void $response = $this->sendHttpRequest($request); - self::assertHttpResponseCodeEquals($response, Response::HTTP_OK); + $this->assertHttpResponseCodeEquals($response, Response::HTTP_OK); } - public function testIsBookmarkedReturnsNotFound(): void + /** + * @depends testDeleteBookmark + * + * @throws \Psr\Http\Client\ClientExceptionInterface + */ + public function testIsBookmarkedReturnsNotFound(int $locationId): void { - $locationId = 43; - $request = $this->createHttpRequest( 'HEAD', '/api/ibexa/v2/bookmark/' . $locationId @@ -74,13 +84,15 @@ public function testIsBookmarkedReturnsNotFound(): void $response = $this->sendHttpRequest($request); - self::assertHttpResponseCodeEquals($response, Response::HTTP_NOT_FOUND); + $this->assertHttpResponseCodeEquals($response, Response::HTTP_NOT_FOUND); } /** * @depends testCreateBookmark + * + * @throws \Psr\Http\Client\ClientExceptionInterface */ - public function testDeleteBookmark(int $locationId): void + public function testDeleteBookmark(int $locationId): int { $request = $this->createHttpRequest( 'DELETE', @@ -89,9 +101,14 @@ public function testDeleteBookmark(int $locationId): void $response = $this->sendHttpRequest($request); - self::assertHttpResponseCodeEquals($response, Response::HTTP_NO_CONTENT); + $this->assertHttpResponseCodeEquals($response, Response::HTTP_NO_CONTENT); + + return $locationId; } + /** + * @throws \Psr\Http\Client\ClientExceptionInterface + */ public function testLoadBookmarks(): void { $request = $this->createHttpRequest( @@ -103,13 +120,16 @@ public function testLoadBookmarks(): void $response = $this->sendHttpRequest($request); - self::assertHttpResponseCodeEquals($response, Response::HTTP_OK); + $this->assertHttpResponseCodeEquals($response, Response::HTTP_OK); } - public function testDeleteBookmarkReturnNotFound(): void + /** + * @depends testDeleteBookmark + * + * @throws \Psr\Http\Client\ClientExceptionInterface + */ + public function testDeleteBookmarkReturnNotFound(int $locationId): void { - $locationId = 43; - $request = $this->createHttpRequest( 'DELETE', '/api/ibexa/v2/bookmark/' . $locationId @@ -117,6 +137,6 @@ public function testDeleteBookmarkReturnNotFound(): void $response = $this->sendHttpRequest($request); - self::assertHttpResponseCodeEquals($response, Response::HTTP_NOT_FOUND); + $this->assertHttpResponseCodeEquals($response, Response::HTTP_NOT_FOUND); } } diff --git a/tests/bundle/Functional/LocationTest.php b/tests/bundle/Functional/LocationTest.php index c99459933..cc681b0d5 100644 --- a/tests/bundle/Functional/LocationTest.php +++ b/tests/bundle/Functional/LocationTest.php @@ -21,7 +21,7 @@ public function testCreateLocation() $content = $this->createFolder('testCreateLocation', '/api/ibexa/v2/content/locations/1/2'); $contentHref = $content['_href']; - $remoteId = $this->addTestSuffix('testCreatelocation'); + $remoteId = $this->addTestSuffix('testCreateLocation'); $body = <<< XML diff --git a/tests/bundle/Routing/OptionsLoader/MapperTest.php b/tests/bundle/Routing/OptionsLoader/MapperTest.php index 85cafe8a5..ad2475e65 100644 --- a/tests/bundle/Routing/OptionsLoader/MapperTest.php +++ b/tests/bundle/Routing/OptionsLoader/MapperTest.php @@ -77,7 +77,7 @@ public function testMapRoute() ); self::assertEquals( - 'Ibexa\Rest\Server\Controller\Options:getRouteOptions', + 'Ibexa\Rest\Server\Controller\Options::getRouteOptions', $optionsRoute->getDefault('_controller') ); }