diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 03c1807..b9be15d 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -401,21 +401,19 @@
protected function generateSelfLink(
+ $metadata->getQueryStringArguments()
$metadata->getQueryStringArguments() ?? []
$metadata->getRoute()
- $queryParams
- $queryStringArgs
$route
$routeParams
$routeParams
$routeParams
+ $queryParams
$queryStringArgs
- $queryParams
- $queryStringArgs
$route
$routeParams
$routeParams
diff --git a/src/ResourceGenerator/RouteBasedCollectionStrategy.php b/src/ResourceGenerator/RouteBasedCollectionStrategy.php
index 014919e..7923fdd 100644
--- a/src/ResourceGenerator/RouteBasedCollectionStrategy.php
+++ b/src/ResourceGenerator/RouteBasedCollectionStrategy.php
@@ -63,7 +63,7 @@ protected function generateLinkForPage(
$paginationType = $metadata->getPaginationParamType();
$paginationParam = $metadata->getPaginationParam();
$routeParams = $metadata->getRouteParams();
- $queryStringArgs = $metadata->getQueryStringArguments();
+ $queryStringArgs = array_merge($request->getQueryParams(), $metadata->getQueryStringArguments());
$paramsWithPage = [$paginationParam => $page];
$routeParams = $paginationType === Metadata\AbstractCollectionMetadata::TYPE_PLACEHOLDER
diff --git a/test/ResourceGenerator/DoctrinePaginatorTest.php b/test/ResourceGenerator/DoctrinePaginatorTest.php
index 9f5eddd..889e2db 100644
--- a/test/ResourceGenerator/DoctrinePaginatorTest.php
+++ b/test/ResourceGenerator/DoctrinePaginatorTest.php
@@ -261,7 +261,7 @@ public function testCreatesLinksForQueryBasedPagination(): void
->willReturn('test');
$this->request
- ->expects(self::once())
+ ->expects(self::exactly(6))
->method('getQueryParams')
->willReturn(['page_num' => 3]);
@@ -382,8 +382,9 @@ public function testCreatesLinksForRouteBasedPagination(): void
->willReturn('test');
$this->request
- ->expects(self::never())
- ->method('getQueryParams');
+ ->expects(self::exactly(5))
+ ->method('getQueryParams')
+ ->willReturn([]);
$this->request
->expects(self::once())
diff --git a/test/ResourceGenerator/RouteBasedCollectionWithRouteParamsTest.php b/test/ResourceGenerator/RouteBasedCollectionWithRouteParamsTest.php
index 79db675..74e364c 100644
--- a/test/ResourceGenerator/RouteBasedCollectionWithRouteParamsTest.php
+++ b/test/ResourceGenerator/RouteBasedCollectionWithRouteParamsTest.php
@@ -36,7 +36,9 @@ public function testUsesRouteParamsAndQueriesWithPaginatorSpecifiedInMetadataWhe
{
$request = $this->prophesize(ServerRequestInterface::class);
$request->getAttribute('p', 1)->willReturn(3);
- $request->getQueryParams()->shouldNotBeCalled();
+ $request->getQueryParams()->willReturn([
+ 'query_1' => 'value_1',
+ ]);
$linkGenerator = $this->prophesize(LinkGenerator::class);
$this->createLinkGeneratorProphecy($linkGenerator, $request, 'self', 3);
@@ -103,15 +105,15 @@ public function testUsesRouteParamsAndQueriesWithPaginatorSpecifiedInMetadataWhe
$this->assertInstanceOf(HalResource::class, $resource);
$self = $this->getLinkByRel('self', $resource);
- $this->assertLink('self', '/api/foo/1234/p/3?sort=ASC', $self);
+ $this->assertLink('self', '/api/foo/1234/p/3?query_1=value_1&sort=ASC', $self);
$first = $this->getLinkByRel('first', $resource);
- $this->assertLink('first', '/api/foo/1234/p/1?sort=ASC', $first);
+ $this->assertLink('first', '/api/foo/1234/p/1?query_1=value_1&sort=ASC', $first);
$prev = $this->getLinkByRel('prev', $resource);
- $this->assertLink('prev', '/api/foo/1234/p/2?sort=ASC', $prev);
+ $this->assertLink('prev', '/api/foo/1234/p/2?query_1=value_1&sort=ASC', $prev);
$next = $this->getLinkByRel('next', $resource);
- $this->assertLink('next', '/api/foo/1234/p/4?sort=ASC', $next);
+ $this->assertLink('next', '/api/foo/1234/p/4?query_1=value_1&sort=ASC', $next);
$last = $this->getLinkByRel('last', $resource);
- $this->assertLink('last', '/api/foo/1234/p/5?sort=ASC', $last);
+ $this->assertLink('last', '/api/foo/1234/p/5?query_1=value_1&sort=ASC', $last);
}
public function testUsesRouteParamsAndQueriesSpecifiedInMetadataWhenGeneratingLinkHref(): void
@@ -209,8 +211,11 @@ private function createLinkGeneratorProphecy($linkGenerator, $request, string $r
&& $params['foo_id'] === 1234
&& $params['p'] === $page;
}),
- ['sort' => 'ASC']
- )->willReturn(new Link($rel, sprintf('/api/foo/1234/p/%d?sort=ASC', $page)));
+ [
+ 'query_1' => 'value_1',
+ 'sort' => 'ASC',
+ ]
+ )->willReturn(new Link($rel, sprintf('/api/foo/1234/p/%d?query_1=value_1&sort=ASC', $page)));
}
/**
diff --git a/test/ResourceGeneratorTest.php b/test/ResourceGeneratorTest.php
index ff379b1..b87e78a 100644
--- a/test/ResourceGeneratorTest.php
+++ b/test/ResourceGeneratorTest.php
@@ -646,6 +646,8 @@ public function testGeneratorAcceptsOnePageWhenCollectionHasNoEmbedded(): void
$this->metadataMap->has(TestAsset\FooBar::class)->willReturn(true);
$this->metadataMap->get(TestAsset\FooBar::class)->willReturn($resourceMetadata);
+ $this->request->getQueryParams()->willReturn([]);
+
$this->linkGenerator
->fromRoute(
'self',