From 3af769421be38ff97170f00683291e2ded970170 Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Thu, 31 Oct 2024 13:41:39 +0100 Subject: [PATCH] Adjusted to changes in core package --- src/bundle/Resources/config/services.yml | 2 +- .../config/value_object_visitors.yml | 8 ++-- src/lib/Server/Controller/Content.php | 28 ++++++------- src/lib/Server/Controller/User.php | 39 +++++++++---------- .../Output/ValueObjectVisitor/Location.php | 6 +-- .../ValueObjectVisitor/RestExecutedView.php | 10 +++-- .../Server/Output/ValueObjectVisitor/User.php | 10 +++-- .../Output/ValueObjectVisitor/UserGroup.php | 6 +-- .../ValueObjectVisitor/LocationTest.php | 21 +++++----- .../RestExecutedViewTest.php | 18 ++++----- 10 files changed, 73 insertions(+), 75 deletions(-) diff --git a/src/bundle/Resources/config/services.yml b/src/bundle/Resources/config/services.yml index ef87dcbd..158b5f6b 100644 --- a/src/bundle/Resources/config/services.yml +++ b/src/bundle/Resources/config/services.yml @@ -149,7 +149,7 @@ services: - '@ibexa.api.service.section' - '@ibexa.api.repository' - '@Ibexa\Contracts\Core\Repository\PermissionResolver' - - '@Ibexa\Core\Helper\RelationListHelper' + - '@Ibexa\Contracts\Core\Repository\ContentService\RelationListFacade' tags: [controller.service_arguments] Ibexa\Rest\Server\Controller\URLWildcard: diff --git a/src/bundle/Resources/config/value_object_visitors.yml b/src/bundle/Resources/config/value_object_visitors.yml index cef85b8a..d887470d 100644 --- a/src/bundle/Resources/config/value_object_visitors.yml +++ b/src/bundle/Resources/config/value_object_visitors.yml @@ -221,7 +221,7 @@ services: parent: Ibexa\Contracts\Rest\Output\ValueObjectVisitor class: Ibexa\Rest\Server\Output\ValueObjectVisitor\UserGroup arguments: - $relationListHelper: '@Ibexa\Core\Helper\RelationListHelper' + $relationListFacade: '@Ibexa\Contracts\Core\Repository\ContentService\RelationListFacade' tags: - { name: ibexa.rest.output.value_object.visitor, type: Ibexa\Contracts\Core\Repository\Values\User\UserGroup } @@ -272,7 +272,7 @@ services: parent: Ibexa\Contracts\Rest\Output\ValueObjectVisitor class: Ibexa\Rest\Server\Output\ValueObjectVisitor\User arguments: - $relationListHelper: '@Ibexa\Core\Helper\RelationListHelper' + $relationListFacade: '@Ibexa\Contracts\Core\Repository\ContentService\RelationListFacade' tags: - { name: ibexa.rest.output.value_object.visitor, type: Ibexa\Contracts\Core\Repository\Values\User\User } @@ -477,7 +477,7 @@ services: - { name: ibexa.rest.output.value_object.visitor, type: Ibexa\Contracts\Core\Repository\Values\Content\Location } arguments: $locationService: '@ibexa.api.service.location' - $relationListHelper: '@Ibexa\Core\Helper\RelationListHelper' + $relationListFacade: '@Ibexa\Contracts\Core\Repository\ContentService\RelationListFacade' Ibexa\Rest\Server\Output\ValueObjectVisitor\LocationList: parent: Ibexa\Contracts\Rest\Output\ValueObjectVisitor @@ -504,7 +504,7 @@ services: class: Ibexa\Rest\Server\Output\ValueObjectVisitor\RestExecutedView arguments: - '@ibexa.api.service.location' - - '@Ibexa\Core\Helper\RelationListHelper' + - '@Ibexa\Contracts\Core\Repository\ContentService\RelationListFacade' tags: - { name: ibexa.rest.output.value_object.visitor, type: Ibexa\Rest\Server\Values\RestExecutedView } diff --git a/src/lib/Server/Controller/Content.php b/src/lib/Server/Controller/Content.php index 581ddfb7..d02a8b01 100644 --- a/src/lib/Server/Controller/Content.php +++ b/src/lib/Server/Controller/Content.php @@ -15,7 +15,6 @@ use Ibexa\Contracts\Core\Repository\Values\Content\Relation; use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; use Ibexa\Contracts\Rest\Exceptions; -use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Message; use Ibexa\Rest\Server\Controller as RestController; use Ibexa\Rest\Server\Exceptions\BadRequestException; @@ -27,14 +26,11 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; -/** - * Content controller. - */ class Content extends RestController { public function __construct( private readonly ContentService $contentService, - private readonly RelationListHelper $relationListHelper + private readonly ContentService\RelationListFacade $relationListFacade ) { } @@ -90,7 +86,7 @@ public function loadContent($contentId, Request $request) $languages = $this->getLanguages($request); $contentVersion = $this->repository->getContentService()->loadContent($contentId, $languages); - $relations = $this->relationListHelper->getRelations($contentVersion->getVersionInfo()); + $relations = $this->relationListFacade->getRelations($contentVersion->getVersionInfo()); } $restContent = new Values\RestContent( @@ -98,7 +94,7 @@ public function loadContent($contentId, Request $request) $mainLocation, $contentVersion, $contentType, - $relations, + $relations !== null ? iterator_to_array($relations) : null, $request->getPathInfo() ); @@ -208,7 +204,7 @@ public function loadContentInVersion($contentId, $versionNumber, Request $reques $versionValue = new Values\Version( $content, $contentType, - $this->relationListHelper->getRelations($content->getVersionInfo()), + iterator_to_array($this->relationListFacade->getRelations($content->getVersionInfo())), $request->getPathInfo() ); @@ -443,7 +439,7 @@ public function createDraftFromVersion($contentId, $versionNumber) 'version' => new Values\Version( $contentDraft, $contentType, - $this->relationListHelper->getRelations($contentDraft->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($contentDraft->getVersionInfo())) ), ] ); @@ -477,7 +473,7 @@ public function createDraftFromCurrentVersion($contentId) 'version' => new Values\Version( $contentDraft, $contentType, - $this->relationListHelper->getRelations($contentDraft->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($contentDraft->getVersionInfo())) ), ] ); @@ -544,7 +540,7 @@ public function updateVersion($contentId, $versionNumber, Request $request) return new Values\Version( $content, $contentType, - $this->relationListHelper->getRelations($content->getVersionInfo()), + iterator_to_array($this->relationListFacade->getRelations($content->getVersionInfo())), $request->getPathInfo() ); } @@ -659,7 +655,7 @@ public function loadVersionRelations($contentId, $versionNumber, Request $reques public function loadVersionRelation($contentId, $versionNumber, $relationId, Request $request) { $contentInfo = $this->repository->getContentService()->loadContentInfo($contentId); - $relationList = $this->relationListHelper->getRelations( + $relationList = $this->relationListFacade->getRelations( $this->repository->getContentService()->loadVersionInfo($contentInfo, $versionNumber) ); @@ -700,7 +696,7 @@ public function removeRelation($contentId, $versionNumber, $relationId, Request $versionNumber ); - $versionRelations = $this->relationListHelper->getRelations($versionInfo); + $versionRelations = $this->relationListFacade->getRelations($versionInfo); foreach ($versionRelations as $relation) { if ($relation->id == $relationId) { if ($relation->type !== Relation::COMMON) { @@ -752,7 +748,7 @@ public function createRelation($contentId, $versionNumber, Request $request) throw new ForbiddenException(/** @Ignore */ $e->getMessage()); } - $existingRelations = $this->relationListHelper->getRelations($versionInfo); + $existingRelations = $this->relationListFacade->getRelations($versionInfo); foreach ($existingRelations as $existingRelation) { if ($existingRelation->getDestinationContentInfo()->id == $destinationContentId) { throw new ForbiddenException('Relation of type COMMON to the selected destination content ID already exists'); @@ -857,7 +853,7 @@ protected function doCreateContent(Request $request, RestContentCreateStruct $co $contentType = $this->repository->getContentTypeService()->loadContentType( $content->getVersionInfo()->getContentInfo()->contentTypeId ); - $relations = $this->relationListHelper->getRelations($contentValue->getVersionInfo()); + $relations = $this->relationListFacade->getRelations($contentValue->getVersionInfo()); } return new Values\CreatedContent( @@ -867,7 +863,7 @@ protected function doCreateContent(Request $request, RestContentCreateStruct $co null, $contentValue, $contentType, - $relations + $relations !== null ? iterator_to_array($relations) : null, ), ] ); diff --git a/src/lib/Server/Controller/User.php b/src/lib/Server/Controller/User.php index ca833857..e26ec83a 100644 --- a/src/lib/Server/Controller/User.php +++ b/src/lib/Server/Controller/User.php @@ -25,7 +25,6 @@ use Ibexa\Contracts\Core\Repository\Values\User\UserRoleAssignment; use Ibexa\Contracts\Rest\Exceptions\NotFoundException; use Ibexa\Core\Base\Exceptions\UnauthorizedException; -use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Message; use Ibexa\Rest\Server\Controller as RestController; use Ibexa\Rest\Server\Exceptions; @@ -63,7 +62,7 @@ final class User extends RestController private PermissionResolver $permissionResolver; - private RelationListHelper $relationListHelper; + private ContentService\RelationListFacade $relationListFacade; public function __construct( UserService $userService, @@ -74,7 +73,7 @@ public function __construct( SectionService $sectionService, Repository $repository, PermissionResolver $permissionResolver, - RelationListHelper $relationListHelper + ContentService\RelationListFacade $relationListFacade ) { $this->userService = $userService; $this->roleService = $roleService; @@ -84,7 +83,7 @@ public function __construct( $this->sectionService = $sectionService; $this->repository = $repository; $this->permissionResolver = $permissionResolver; - $this->relationListHelper = $relationListHelper; + $this->relationListFacade = $relationListFacade; } /** @@ -126,7 +125,7 @@ public function loadUserGroup(string $groupPath): RestValue $contentType, $userGroupContentInfo, $userGroupLocation, - $this->relationListHelper->getRelations($userGroup->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($userGroup->getVersionInfo())) ), ['locationId' => $userGroupLocation->id] ); @@ -141,7 +140,7 @@ public function loadUser(int $userId): RestValue try { $userMainLocation = $this->locationService->loadLocation($userContentInfo->mainLocationId); - $relations = $this->relationListHelper->getRelations($user->getVersionInfo()); + $relations = $this->relationListFacade->getRelations($user->getVersionInfo()); } catch (UnauthorizedException $e) { // TODO: Hack for special case to allow current logged in user to load him/here self (but not relations) if ($user->id == $this->permissionResolver->getCurrentUserReference()->getUserId()) { @@ -163,7 +162,7 @@ function () use ($userContentInfo) { $contentType, $userContentInfo, $userMainLocation, - $relations + iterator_to_array($relations) ), ['locationId' => $userContentInfo->mainLocationId] ); @@ -224,7 +223,7 @@ public function createUserGroup(string $groupPath, Request $request): Values\Cre $contentType, $createdContentInfo, $createdLocation, - $this->relationListHelper->getRelations($createdUserGroup->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($createdUserGroup->getVersionInfo())) ), ] ); @@ -269,7 +268,7 @@ public function createUser(string $groupPath, Request $request): Values\CreatedU $contentType, $createdContentInfo, $createdLocation, - $this->relationListHelper->getRelations($createdUser->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($createdUser->getVersionInfo())) ), ] ); @@ -314,7 +313,7 @@ public function updateUserGroup(string $groupPath, Request $request): Values\Res $contentType, $updatedGroup->getVersionInfo()->getContentInfo(), $userGroupLocation, - $this->relationListHelper->getRelations($updatedGroup->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($updatedGroup->getVersionInfo())) ); } @@ -351,7 +350,7 @@ public function updateUser(int $userId, Request $request): Values\RestUser $contentType, $updatedContentInfo, $mainLocation, - $this->relationListHelper->getRelations($updatedUser->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($updatedUser->getVersionInfo())) ); } @@ -486,7 +485,7 @@ private function buildRestUserObject(RepositoryUser $user): Values\RestUser $this->contentTypeService->loadContentType($user->contentInfo->contentTypeId), $user->contentInfo, $this->locationService->loadLocation($user->contentInfo->mainLocationId), - $this->relationListHelper->getRelations($user->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($user->getVersionInfo())) ); } @@ -508,7 +507,7 @@ public function loadUserGroups(Request $request): RestValue $contentType, $userGroupContentInfo, $userGroupMainLocation, - $this->relationListHelper->getRelations($userGroup->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($userGroup->getVersionInfo())) ), ]; } elseif ($request->query->has('roleId')) { @@ -541,7 +540,7 @@ public function loadUserGroupByRemoteId(Request $request): Values\RestUserGroup $contentType, $contentInfo, $userGroupLocation, - $this->relationListHelper->getRelations($userGroup->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($userGroup->getVersionInfo())) ); } @@ -571,7 +570,7 @@ public function loadUserGroupsAssignedToRole($roleId): array $contentType, $userGroupContentInfo, $userGroupLocation, - $this->relationListHelper->getRelations($userGroup->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($userGroup->getVersionInfo())) ); } } @@ -722,7 +721,7 @@ public function loadSubUserGroups(string $groupPath, Request $request): RestValu $contentType, $subGroupContentInfo, $subGroupLocation, - $this->relationListHelper->getRelations($subGroup->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($subGroup->getVersionInfo())) ); } @@ -768,7 +767,7 @@ public function loadUserGroupsOfUser(int $userId, Request $request): RestValue $contentType, $userGroupContentInfo, $userGroupLocation, - $this->relationListHelper->getRelations($userGroup->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($userGroup->getVersionInfo())) ); } @@ -812,7 +811,7 @@ public function loadUsersFromGroup(string $groupPath, Request $request): RestVal $contentType, $userContentInfo, $userLocation, - $this->relationListHelper->getRelations($user->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($user->getVersionInfo())) ); } @@ -864,7 +863,7 @@ public function unassignUserFromUserGroup(int $userId, string $groupPath): Value $contentType, $userGroupContentInfo, $userGroupLocation, - $this->relationListHelper->getRelations($userGroup->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($userGroup->getVersionInfo())) ); } @@ -922,7 +921,7 @@ public function assignUserToUserGroup(int $userId, Request $request): Values\Use $contentType, $userGroupContentInfo, $userGroupLocation, - $this->relationListHelper->getRelations($userGroup->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($userGroup->getVersionInfo())) ); } diff --git a/src/lib/Server/Output/ValueObjectVisitor/Location.php b/src/lib/Server/Output/ValueObjectVisitor/Location.php index 5d7de771..28954f00 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/Location.php +++ b/src/lib/Server/Output/ValueObjectVisitor/Location.php @@ -7,13 +7,13 @@ namespace Ibexa\Rest\Server\Output\ValueObjectVisitor; +use Ibexa\Contracts\Core\Repository\ContentService\RelationListFacade; use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException; use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\Values\Content; use Ibexa\Contracts\Rest\Output\Generator; use Ibexa\Contracts\Rest\Output\ValueObjectVisitor; use Ibexa\Contracts\Rest\Output\Visitor; -use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Server\Values\RestContent as RestContentValue; /** @@ -23,7 +23,7 @@ class Location extends ValueObjectVisitor { public function __construct( private readonly LocationService $locationService, - private readonly RelationListHelper $relationListHelper + private readonly RelationListFacade $relationListFacade ) { } @@ -164,7 +164,7 @@ protected function visitLocationAttributes( $mainLocation, $content, $content->getContentType(), - $this->relationListHelper->getRelations($content->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($content->getVersionInfo())) ) ); diff --git a/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php b/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php index 0a71b339..3c2ccac5 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php +++ b/src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php @@ -7,6 +7,7 @@ namespace Ibexa\Rest\Server\Output\ValueObjectVisitor; +use Ibexa\Contracts\Core\Repository\ContentService\RelationListFacade; use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException; use Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException; use Ibexa\Contracts\Core\Repository\LocationService; @@ -15,7 +16,6 @@ use Ibexa\Contracts\Rest\Output\Generator; use Ibexa\Contracts\Rest\Output\ValueObjectVisitor; use Ibexa\Contracts\Rest\Output\Visitor; -use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Server\Values\RestContent as RestContentValue; /** @@ -25,7 +25,7 @@ class RestExecutedView extends ValueObjectVisitor { public function __construct( private readonly LocationService $locationService, - private readonly RelationListHelper $relationListHelper + private readonly RelationListFacade $relationListFacade ) { } @@ -108,7 +108,11 @@ public function visit(Visitor $visitor, Generator $generator, $data) $mainLocation, $searchHit->valueObject, $searchHit->valueObject->getContentType(), - $this->relationListHelper->getRelations($searchHit->valueObject->getVersionInfo()) + iterator_to_array( + $this->relationListFacade->getRelations( + $searchHit->valueObject->getVersionInfo() + ) + ) ); } elseif ($searchHit->valueObject instanceof ApiValues\Location) { $valueObject = $searchHit->valueObject; diff --git a/src/lib/Server/Output/ValueObjectVisitor/User.php b/src/lib/Server/Output/ValueObjectVisitor/User.php index d9a32751..65dff573 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/User.php +++ b/src/lib/Server/Output/ValueObjectVisitor/User.php @@ -8,16 +8,16 @@ namespace Ibexa\Rest\Server\Output\ValueObjectVisitor; +use Ibexa\Contracts\Core\Repository\ContentService\RelationListFacade; use Ibexa\Contracts\Rest\Output\Generator; use Ibexa\Contracts\Rest\Output\ValueObjectVisitor; use Ibexa\Contracts\Rest\Output\Visitor; -use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Output\DelegateValueObjectVisitor; use Ibexa\Rest\Server\Values\RestUser; final class User extends ValueObjectVisitor implements DelegateValueObjectVisitor { - public function __construct(private readonly RelationListHelper $relationListHelper) + public function __construct(private readonly RelationListFacade $relationListFacade) { } @@ -32,8 +32,10 @@ public function visit(Visitor $visitor, Generator $generator, $data): void $data->getContentType(), $data->contentInfo, $data->contentInfo->getMainLocation(), - $this->relationListHelper->getRelations( - $data->getVersionInfo() + iterator_to_array( + $this->relationListFacade->getRelations( + $data->getVersionInfo() + ) ) ) ); diff --git a/src/lib/Server/Output/ValueObjectVisitor/UserGroup.php b/src/lib/Server/Output/ValueObjectVisitor/UserGroup.php index 92e4ef89..708022e1 100644 --- a/src/lib/Server/Output/ValueObjectVisitor/UserGroup.php +++ b/src/lib/Server/Output/ValueObjectVisitor/UserGroup.php @@ -8,17 +8,17 @@ namespace Ibexa\Rest\Server\Output\ValueObjectVisitor; +use Ibexa\Contracts\Core\Repository\ContentService\RelationListFacade; use Ibexa\Contracts\Rest\Output\Generator; use Ibexa\Contracts\Rest\Output\ValueObjectVisitor; use Ibexa\Contracts\Rest\Output\Visitor; -use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Rest\Output\DelegateValueObjectVisitor; use Ibexa\Rest\Server\Values\RestUserGroup; final class UserGroup extends ValueObjectVisitor implements DelegateValueObjectVisitor { public function __construct( - private readonly RelationListHelper $relationListHelper + private readonly RelationListFacade $relationListFacade ) { } @@ -33,7 +33,7 @@ public function visit(Visitor $visitor, Generator $generator, $data): void $data->getContentType(), $data->contentInfo, $data->contentInfo->getMainLocation(), - $this->relationListHelper->getRelations($data->getVersionInfo()) + iterator_to_array($this->relationListFacade->getRelations($data->getVersionInfo())) ) ); } diff --git a/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php b/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php index 415d6854..febfe7f4 100644 --- a/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php +++ b/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php @@ -11,15 +11,14 @@ use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; use Ibexa\Contracts\Core\Repository\Values\Content\Location as ApiLocation; -use Ibexa\Contracts\Core\Repository\Values\Content\RelationList; use Ibexa\Core\Base\Exceptions\UnauthorizedException; -use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Core\Repository\Values\Content\Content; use Ibexa\Core\Repository\Values\Content\Location; use Ibexa\Core\Repository\Values\Content\VersionInfo; use Ibexa\Core\Repository\Values\ContentType\ContentType; use Ibexa\Rest\Server\Output\ValueObjectVisitor; use Ibexa\Tests\Rest\Output\ValueObjectVisitorBaseTest; +use PHPUnit\Framework\MockObject\MockObject; final class LocationTest extends ValueObjectVisitorBaseTest { @@ -29,16 +28,14 @@ final class LocationTest extends ValueObjectVisitorBaseTest private const LOCATION_ID = 55; - /** @var \Ibexa\Contracts\Core\Repository\LocationService&\PHPUnit\Framework\MockObject\MockObject */ - private LocationService $locationServiceMock; + private LocationService&MockObject $locationServiceMock; - /** @var \Ibexa\Contracts\Core\Repository\ContentService&\PHPUnit\Framework\MockObject\MockObject */ - private ContentService $contentServiceMock; + private ContentService\RelationListFacade&MockObject $relationListFacade; protected function setUp(): void { $this->locationServiceMock = $this->createMock(LocationService::class); - $this->contentServiceMock = $this->createMock(ContentService::class); + $this->relationListFacade = $this->createMock(ContentService\RelationListFacade::class); parent::setUp(); } @@ -78,10 +75,12 @@ public function testVisitLocationAttributesResolvesMainLocation( $this->mockLoadLocation($location); - $this->contentServiceMock->expects(self::once()) - ->method('loadRelationList') + $this->relationListFacade->expects(self::once()) + ->method('getRelations') ->with($versionInfo) - ->willReturn(new RelationList([])); + ->willReturnCallback( + static fn () => yield + ); $visitor->visit( $this->getVisitorMock(), @@ -143,7 +142,7 @@ protected function internalGetVisitor(): ValueObjectVisitor\Location { return new ValueObjectVisitor\Location( $this->locationServiceMock, - new RelationListHelper($this->contentServiceMock) + $this->relationListFacade ); } } diff --git a/tests/lib/Server/Output/ValueObjectVisitor/RestExecutedViewTest.php b/tests/lib/Server/Output/ValueObjectVisitor/RestExecutedViewTest.php index 3948d757..c15bda60 100644 --- a/tests/lib/Server/Output/ValueObjectVisitor/RestExecutedViewTest.php +++ b/tests/lib/Server/Output/ValueObjectVisitor/RestExecutedViewTest.php @@ -11,16 +11,15 @@ use Ibexa\Contracts\Core\Repository\ContentTypeService; use Ibexa\Contracts\Core\Repository\LocationService; use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; -use Ibexa\Contracts\Core\Repository\Values\Content\RelationList; use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchHit; use Ibexa\Contracts\Core\Repository\Values\Content\Search\SearchResult; -use Ibexa\Core\Helper\RelationListHelper; use Ibexa\Core\Repository\Values\Content; use Ibexa\Core\Repository\Values\Content as ApiValues; use Ibexa\Core\Repository\Values\ContentType\ContentType; use Ibexa\Rest\Server\Output\ValueObjectVisitor; use Ibexa\Rest\Server\Values\RestExecutedView; use Ibexa\Tests\Rest\Output\ValueObjectVisitorBaseTest; +use PHPUnit\Framework\MockObject\MockObject; class RestExecutedViewTest extends ValueObjectVisitorBaseTest { @@ -117,7 +116,7 @@ protected function internalGetVisitor() { return new ValueObjectVisitor\RestExecutedView( $this->getLocationServiceMock(), - new RelationListHelper($this->getContentServiceMock()) + $this->getRelationListFacadeMock() ); } @@ -129,15 +128,14 @@ public function getLocationServiceMock() return $this->createMock(LocationService::class); } - /** - * @return \Ibexa\Contracts\Core\Repository\ContentService|\PHPUnit\Framework\MockObject\MockObject - */ - public function getContentServiceMock() + private function getRelationListFacadeMock(): ContentService\RelationListFacade&MockObject { - $contentService = $this->createMock(ContentService::class); - $contentService->method('loadRelationList')->willReturn(new RelationList([])); + $relationListFacade = $this->createMock(ContentService\RelationListFacade::class); + $relationListFacade->method('getRelations')->willReturnCallback( + static fn () => yield + ); - return $contentService; + return $relationListFacade; } /**