Skip to content

Commit cdfd9e0

Browse files
More test and better fix
1 parent 492d149 commit cdfd9e0

5 files changed

Lines changed: 44 additions & 13 deletions

File tree

src/Doctrine/Common/ParameterExtensionTrait.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ private function configureFilter(object $filter, Parameter $parameter): void
5757
$properties = $filter->getProperties() ?? [];
5858
}
5959

60-
$propertyKey = $parameter->getProperty() ?? $parameter->getKey();
60+
if (null !== $parameter->getProperty()) {
61+
// Since the property is normalized I dunno where
62+
// Notice that since NameConverter doesn't work for property path, it breaks nested property.
63+
$propertyKey = $this->nameConverter->denormalize($parameter->getProperty());
64+
} else {
65+
$propertyKey = $parameter->getKey();
66+
}
67+
6168
foreach ($parameter->getProperties() ?? [$propertyKey] as $property) {
6269
if (!isset($properties[$property])) {
6370
$properties[$property] = $parameter->getFilterContext();

src/Doctrine/Odm/Filter/AbstractFilter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ protected function isPropertyEnabled(string $property, string $resourceClass): b
117117
return !$this->isPropertyNested($property, $resourceClass);
118118
}
119119

120-
// We have to normalize the property back here since:
121-
// - The property was denormalized in `apply()` method.
122-
// - The `properties` property is a list of the property names without transformation.
123-
return \array_key_exists($this->normalizePropertyName($property), $this->properties);
120+
return \array_key_exists($property, $this->properties);
124121
}
125122

126123
protected function denormalizePropertyName(string|int $property): string

src/Doctrine/Orm/Filter/AbstractFilter.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ protected function isPropertyEnabled(string $property, string $resourceClass): b
107107
return !$this->isPropertyNested($property, $resourceClass);
108108
}
109109

110-
// We have to normalize the property back here since:
111-
// - The property was denormalized in `apply()` method.
112-
// - The `properties` property is a list of the property names without transformation.
113-
return \array_key_exists($this->normalizePropertyName($property), $this->properties);
110+
return \array_key_exists($property, $this->properties);
114111
}
115112

116113
protected function denormalizePropertyName(string|int $property): string

tests/Fixtures/TestBundle/Entity/FilteredBooleanParameter.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,24 @@
3333
property: 'active',
3434
nativeType: new BuiltinType(TypeIdentifier::BOOL),
3535
),
36+
'nameConverted' => new QueryParameter(
37+
filter: new BooleanFilter(),
38+
nativeType: new BuiltinType(TypeIdentifier::BOOL),
39+
),
40+
'nameNotConverted' => new QueryParameter(
41+
filter: new BooleanFilter(),
42+
nativeType: new BuiltinType(TypeIdentifier::BOOL),
43+
),
3644
'aliasWithNameConverter' => new QueryParameter(
3745
filter: new BooleanFilter(),
3846
property: 'nameConverted',
3947
nativeType: new BuiltinType(TypeIdentifier::BOOL),
4048
),
49+
'aliasWithoutNameConverter' => new QueryParameter(
50+
filter: new BooleanFilter(),
51+
property: 'nameNotConverted',
52+
nativeType: new BuiltinType(TypeIdentifier::BOOL),
53+
),
4154
],
4255
)]
4356
#[ORM\Entity]
@@ -46,6 +59,9 @@ class FilteredBooleanParameter
4659
#[ORM\Column(nullable: true)]
4760
private ?bool $nameConverted;
4861

62+
#[ORM\Column(nullable: true)]
63+
private ?bool $nameNotConverted;
64+
4965
public function __construct(
5066
#[ORM\Column]
5167
#[ORM\Id]
@@ -56,6 +72,7 @@ public function __construct(
5672
public ?bool $active = null,
5773
) {
5874
$this->nameConverted = $this->active;
75+
$this->nameNotConverted = $this->active;
5976
}
6077

6178
public function getId(): ?int
@@ -72,5 +89,6 @@ public function setActive(?bool $isActive): void
7289
{
7390
$this->active = $isActive;
7491
$this->nameConverted = $isActive;
92+
$this->nameNotConverted = $isActive;
7593
}
7694
}

tests/Functional/Parameters/BooleanFilterTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,22 @@ public static function booleanFilterScenariosProvider(): \Generator
7474
yield 'enabled_alias_false' => ['/filtered_boolean_parameters?enabled=false', 1, false];
7575
yield 'enabled_alias_numeric_1' => ['/filtered_boolean_parameters?enabled=1', 2, true];
7676
yield 'enabled_alias_numeric_0' => ['/filtered_boolean_parameters?enabled=0', 1, false];
77-
yield 'name_converted_true' => ['/filtered_boolean_parameters?aliasWithNameConverter=true', 2, true];
78-
yield 'name_converted_false' => ['/filtered_boolean_parameters?aliasWithNameConverter=false', 1, false];
79-
yield 'name_converted_numeric_1' => ['/filtered_boolean_parameters?aliasWithNameConverter=1', 2, true];
80-
yield 'name_converted_numeric_0' => ['/filtered_boolean_parameters?aliasWithNameConverter=0', 1, false];
77+
yield 'name_converted_true' => ['/filtered_boolean_parameters?nameConverted=true', 2, true];
78+
yield 'name_converted_false' => ['/filtered_boolean_parameters?nameConverted=false', 1, false];
79+
yield 'name_converted_numeric_1' => ['/filtered_boolean_parameters?nameConverted=1', 2, true];
80+
yield 'name_converted_numeric_0' => ['/filtered_boolean_parameters?nameConverted=0', 1, false];
81+
yield 'name_not_converted_true' => ['/filtered_boolean_parameters?nameNotConverted=true', 2, true];
82+
yield 'name_not_converted_false' => ['/filtered_boolean_parameters?nameNotConverted=false', 1, false];
83+
yield 'name_not_converted_numeric_1' => ['/filtered_boolean_parameters?nameNotConverted=1', 2, true];
84+
yield 'name_not_converted_numeric_0' => ['/filtered_boolean_parameters?nameNotConverted=0', 1, false];
85+
yield 'alias_name_converted_true' => ['/filtered_boolean_parameters?aliasWithNameConverter=true', 2, true];
86+
yield 'alias_name_converted_false' => ['/filtered_boolean_parameters?aliasWithNameConverter=false', 1, false];
87+
yield 'alias_name_converted_numeric_1' => ['/filtered_boolean_parameters?aliasWithNameConverter=1', 2, true];
88+
yield 'alias_name_converted_numeric_0' => ['/filtered_boolean_parameters?aliasWithNameConverter=0', 1, false];
89+
yield 'alias_name_not_converted_true' => ['/filtered_boolean_parameters?aliasWithoutNameConverter=true', 2, true];
90+
yield 'alias_name_not_converted_false' => ['/filtered_boolean_parameters?aliasWithoutNameConverter=false', 1, false];
91+
yield 'alias_name_not_converted_numeric_1' => ['/filtered_boolean_parameters?aliasWithoutNameConverter=1', 2, true];
92+
yield 'alias_name_not_converted_numeric_0' => ['/filtered_boolean_parameters?aliasWithoutNameConverter=0', 1, false];
8193
}
8294

8395
#[DataProvider('booleanFilterNullAndEmptyScenariosProvider')]

0 commit comments

Comments
 (0)