From e79efef4842b2fca9c37a396f6fa817d32d97c89 Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Mon, 28 Oct 2024 11:35:30 +0100 Subject: [PATCH] Fixed unit tests --- phpstan-baseline-7.4.neon | 5 --- phpstan-baseline-8.0.neon | 5 --- phpstan-baseline.neon | 40 ------------------- .../config/value_object_visitors.yml | 4 +- .../Exceptions/AbstractExceptionVisitor.php | 1 + src/lib/Server/Controller/Content.php | 2 +- .../ValueObjectVisitor/LocationTest.php | 11 +++-- .../RestExecutedViewTest.php | 6 ++- 8 files changed, 16 insertions(+), 58 deletions(-) diff --git a/phpstan-baseline-7.4.neon b/phpstan-baseline-7.4.neon index 42e78497..7589699d 100644 --- a/phpstan-baseline-7.4.neon +++ b/phpstan-baseline-7.4.neon @@ -1,10 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Parameter \\#1 \\$input of function array_slice expects array, iterable\\ given\\.$#" - count: 1 - path: src/lib/Server/Controller/Content.php - - message: "#^Parameter \\#2 \\$str of function explode expects string, string\\|null given\\.$#" count: 4 diff --git a/phpstan-baseline-8.0.neon b/phpstan-baseline-8.0.neon index 8a072c3c..bdc0ad04 100644 --- a/phpstan-baseline-8.0.neon +++ b/phpstan-baseline-8.0.neon @@ -30,11 +30,6 @@ parameters: count: 1 path: src/lib/Input/Handler/Xml.php - - - message: "#^Parameter \\#1 \\$array of function array_slice expects array, iterable\\ given\\.$#" - count: 1 - path: src/lib/Server/Controller/Content.php - - message: "#^Parameter \\#2 \\.\\.\\.\\$arrays of function array_merge expects array, iterable\\ given\\.$#" count: 1 diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 126dd499..9fed8314 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1015,16 +1015,6 @@ parameters: count: 1 path: src/lib/Server/Controller/Content.php - - - message: "#^Parameter \\#3 \\$relations of class Ibexa\\\\Rest\\\\Server\\\\Values\\\\Version constructor expects array\\, iterable\\ given\\.$#" - count: 4 - path: src/lib/Server/Controller/Content.php - - - - message: "#^Parameter \\#5 \\$relations of class Ibexa\\\\Rest\\\\Server\\\\Values\\\\RestContent constructor expects array\\\\|null, iterable\\\\|null given\\.$#" - count: 2 - path: src/lib/Server/Controller/Content.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Controller\\\\ContentType\\:\\:addContentTypeDraftFieldDefinition\\(\\) has parameter \\$contentTypeId with no type specified\\.$#" count: 1 @@ -1660,16 +1650,6 @@ parameters: count: 1 path: src/lib/Server/Controller/User.php - - - message: "#^Parameter \\#5 \\$relations of class Ibexa\\\\Rest\\\\Server\\\\Values\\\\RestUser constructor expects array\\, iterable\\ given\\.$#" - count: 5 - path: src/lib/Server/Controller/User.php - - - - message: "#^Parameter \\#5 \\$relations of class Ibexa\\\\Rest\\\\Server\\\\Values\\\\RestUserGroup constructor expects array\\, iterable\\ given\\.$#" - count: 10 - path: src/lib/Server/Controller/User.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractRangeAggregationParser\\:\\:dispatchRanges\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 @@ -2760,11 +2740,6 @@ parameters: count: 1 path: src/lib/Server/Output/ValueObjectVisitor/Location.php - - - message: "#^Parameter \\#5 \\$relations of class Ibexa\\\\Rest\\\\Server\\\\Values\\\\RestContent constructor expects array\\\\|null, iterable\\ given\\.$#" - count: 1 - path: src/lib/Server/Output/ValueObjectVisitor/Location.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Output\\\\ValueObjectVisitor\\\\LocationList\\:\\:visit\\(\\) has no return type specified\\.$#" count: 1 @@ -2920,11 +2895,6 @@ parameters: count: 1 path: src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php - - - message: "#^Parameter \\#5 \\$relations of class Ibexa\\\\Rest\\\\Server\\\\Values\\\\RestContent constructor expects array\\\\|null, iterable\\ given\\.$#" - count: 1 - path: src/lib/Server/Output/ValueObjectVisitor/RestExecutedView.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Output\\\\ValueObjectVisitor\\\\RestFieldDefinition\\:\\:visit\\(\\) has no return type specified\\.$#" count: 1 @@ -3120,21 +3090,11 @@ parameters: count: 1 path: src/lib/Server/Output/ValueObjectVisitor/User.php - - - message: "#^Parameter \\#5 \\$relations of class Ibexa\\\\Rest\\\\Server\\\\Values\\\\RestUser constructor expects array\\, iterable\\ given\\.$#" - count: 1 - path: src/lib/Server/Output/ValueObjectVisitor/User.php - - message: "#^Parameter \\#4 \\$mainLocation of class Ibexa\\\\Rest\\\\Server\\\\Values\\\\RestUserGroup constructor expects Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Location, Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Location\\|null given\\.$#" count: 1 path: src/lib/Server/Output/ValueObjectVisitor/UserGroup.php - - - message: "#^Parameter \\#5 \\$relations of class Ibexa\\\\Rest\\\\Server\\\\Values\\\\RestUserGroup constructor expects array\\, iterable\\ given\\.$#" - count: 1 - path: src/lib/Server/Output/ValueObjectVisitor/UserGroup.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Output\\\\ValueObjectVisitor\\\\UserGroupList\\:\\:visit\\(\\) has no return type specified\\.$#" count: 1 diff --git a/src/bundle/Resources/config/value_object_visitors.yml b/src/bundle/Resources/config/value_object_visitors.yml index 29931ade..cef85b8a 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: - $contentService: '@ibexa.api.service.content' + $relationListHelper: '@Ibexa\Core\Helper\RelationListHelper' 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: - $contentService: '@ibexa.api.service.content' + $relationListHelper: '@Ibexa\Core\Helper\RelationListHelper' tags: - { name: ibexa.rest.output.value_object.visitor, type: Ibexa\Contracts\Core\Repository\Values\User\User } diff --git a/src/contracts/Output/Exceptions/AbstractExceptionVisitor.php b/src/contracts/Output/Exceptions/AbstractExceptionVisitor.php index 47ebac40..30a273f4 100644 --- a/src/contracts/Output/Exceptions/AbstractExceptionVisitor.php +++ b/src/contracts/Output/Exceptions/AbstractExceptionVisitor.php @@ -4,6 +4,7 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ + namespace Ibexa\Contracts\Rest\Output\Exceptions; use Ibexa\Contracts\Rest\Output\Generator; diff --git a/src/lib/Server/Controller/Content.php b/src/lib/Server/Controller/Content.php index 353e255f..57d3eefc 100644 --- a/src/lib/Server/Controller/Content.php +++ b/src/lib/Server/Controller/Content.php @@ -31,7 +31,7 @@ */ class Content extends RestController { - public function __construct(private readonly RelationListHelper $relationListHelper, private readonly RelationListHelper $relationListHelper) + public function __construct(private readonly RelationListHelper $relationListHelper) { } diff --git a/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php b/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php index fdb75e0c..415d6854 100644 --- a/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php +++ b/tests/lib/Server/Output/ValueObjectVisitor/LocationTest.php @@ -11,7 +11,9 @@ 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; @@ -77,9 +79,9 @@ public function testVisitLocationAttributesResolvesMainLocation( $this->mockLoadLocation($location); $this->contentServiceMock->expects(self::once()) - ->method('loadRelations') + ->method('loadRelationList') ->with($versionInfo) - ->willReturn([]); + ->willReturn(new RelationList([])); $visitor->visit( $this->getVisitorMock(), @@ -139,6 +141,9 @@ public function getDataForTestVisitLocationAttributesResolvesMainLocation(): ite protected function internalGetVisitor(): ValueObjectVisitor\Location { - return new ValueObjectVisitor\Location($this->locationServiceMock, $this->contentServiceMock); + return new ValueObjectVisitor\Location( + $this->locationServiceMock, + new RelationListHelper($this->contentServiceMock) + ); } } diff --git a/tests/lib/Server/Output/ValueObjectVisitor/RestExecutedViewTest.php b/tests/lib/Server/Output/ValueObjectVisitor/RestExecutedViewTest.php index 537833bb..3948d757 100644 --- a/tests/lib/Server/Output/ValueObjectVisitor/RestExecutedViewTest.php +++ b/tests/lib/Server/Output/ValueObjectVisitor/RestExecutedViewTest.php @@ -11,8 +11,10 @@ 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; @@ -115,7 +117,7 @@ protected function internalGetVisitor() { return new ValueObjectVisitor\RestExecutedView( $this->getLocationServiceMock(), - $this->getContentServiceMock(), + new RelationListHelper($this->getContentServiceMock()) ); } @@ -133,7 +135,7 @@ public function getLocationServiceMock() public function getContentServiceMock() { $contentService = $this->createMock(ContentService::class); - $contentService->method('loadRelations')->willReturn([]); + $contentService->method('loadRelationList')->willReturn(new RelationList([])); return $contentService; }