Skip to content

Commit

Permalink
Merge pull request #74 from mezzio/2.5.x-merge-up-into-2.6.x_lbfad0Tt
Browse files Browse the repository at this point in the history
Merge release 2.5.2 into 2.6.x
  • Loading branch information
Ocramius authored Feb 16, 2023
2 parents 9e89b55 + 2380d3b commit 197ef51
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
6 changes: 2 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -401,21 +401,19 @@
<code>protected function generateSelfLink(</code>
</MethodSignatureMismatch>
<MixedArgument>
<code>$metadata-&gt;getQueryStringArguments()</code>
<code>$metadata-&gt;getQueryStringArguments() ?? []</code>
<code>$metadata-&gt;getRoute()</code>
<code>$queryParams</code>
<code>$queryStringArgs</code>
<code>$route</code>
<code>$routeParams</code>
<code>$routeParams</code>
<code>$routeParams</code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code>$queryParams</code>
<code>$queryStringArgs</code>
</MixedArgumentTypeCoercion>
<MixedAssignment>
<code>$queryParams</code>
<code>$queryStringArgs</code>
<code>$route</code>
<code>$routeParams</code>
<code>$routeParams</code>
Expand Down
2 changes: 1 addition & 1 deletion src/ResourceGenerator/RouteBasedCollectionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions test/ResourceGenerator/DoctrinePaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -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())
Expand Down
21 changes: 13 additions & 8 deletions test/ResourceGenerator/RouteBasedCollectionWithRouteParamsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)));
}

/**
Expand Down
2 changes: 2 additions & 0 deletions test/ResourceGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 197ef51

Please sign in to comment.