Skip to content

Commit

Permalink
fix(doctrine): use parameter.property for filter value (#6572)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil authored Sep 2, 2024
1 parent 50d2ca8 commit ef0ee64
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Doctrine/Common/ParameterValueExtractorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait ParameterValueExtractorTrait
*/
private function extractParameterValue(Parameter $parameter, mixed $value): array
{
$key = $parameter->getKey();
$key = $parameter->getProperty() ?? $parameter->getKey();
if (!str_contains($key, ':property')) {
return [$key => $value];
}
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/TestBundle/Entity/SearchFilterParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
uriTemplate: 'search_filter_parameter{._format}',
parameters: [
'foo' => new QueryParameter(filter: 'app_search_filter_via_parameter'),
'fooAlias' => new QueryParameter(filter: 'app_search_filter_via_parameter', property: 'foo'),
'order[:property]' => new QueryParameter(filter: 'app_search_filter_via_parameter.order_filter'),

'searchPartial[:property]' => new QueryParameter(filter: 'app_search_filter_partial'),
Expand Down
7 changes: 6 additions & 1 deletion tests/Functional/Parameters/DoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ public function testDoctrineEntitySearchFilter(): void
$this->assertEquals('bar', $a['hydra:member'][1]['foo']);

$this->assertArraySubset(['hydra:search' => [
'hydra:template' => \sprintf('/%s{?foo,order[order[id]],order[order[foo]],searchPartial[foo],searchExact[foo],searchOnTextAndDate[foo],searchOnTextAndDate[createdAt][before],searchOnTextAndDate[createdAt][strictly_before],searchOnTextAndDate[createdAt][after],searchOnTextAndDate[createdAt][strictly_after],q}', $route),
'hydra:template' => \sprintf('/%s{?foo,fooAlias,order[order[id]],order[order[foo]],searchPartial[foo],searchExact[foo],searchOnTextAndDate[foo],searchOnTextAndDate[createdAt][before],searchOnTextAndDate[createdAt][strictly_before],searchOnTextAndDate[createdAt][after],searchOnTextAndDate[createdAt][strictly_after],q}', $route),
'hydra:mapping' => [
['@type' => 'IriTemplateMapping', 'variable' => 'foo', 'property' => 'foo'],
],
]], $a);

$response = self::createClient()->request('GET', $route.'?fooAlias=baz');
$a = $response->toArray();
$this->assertCount(1, $a['hydra:member']);
$this->assertEquals('baz', $a['hydra:member'][0]['foo']);

$response = self::createClient()->request('GET', $route.'?order[foo]=asc');
$this->assertEquals($response->toArray()['hydra:member'][0]['foo'], 'bar');
$response = self::createClient()->request('GET', $route.'?order[foo]=desc');
Expand Down

0 comments on commit ef0ee64

Please sign in to comment.