Skip to content

Commit

Permalink
IBX-9587: Fixed failing REST requests after Symfony 6 upgrade (#145)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
alongosz authored Feb 18, 2025
1 parent d87f621 commit f2b929d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion src/bundle/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 2 additions & 7 deletions src/bundle/Routing/OptionsLoader/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
48 changes: 34 additions & 14 deletions tests/bundle/Functional/BookmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -60,27 +67,32 @@ 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
);

$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',
Expand All @@ -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(
Expand All @@ -103,20 +120,23 @@ 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
);

$response = $this->sendHttpRequest($request);

self::assertHttpResponseCodeEquals($response, Response::HTTP_NOT_FOUND);
$this->assertHttpResponseCodeEquals($response, Response::HTTP_NOT_FOUND);
}
}
2 changes: 1 addition & 1 deletion tests/bundle/Functional/LocationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
<?xml version="1.0" encoding="UTF-8"?>
Expand Down
2 changes: 1 addition & 1 deletion tests/bundle/Routing/OptionsLoader/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testMapRoute()
);

self::assertEquals(
'Ibexa\Rest\Server\Controller\Options:getRouteOptions',
'Ibexa\Rest\Server\Controller\Options::getRouteOptions',
$optionsRoute->getDefault('_controller')
);
}
Expand Down

0 comments on commit f2b929d

Please sign in to comment.