Skip to content

Commit fd0d73e

Browse files
committed
Fixing date filter to not consider empty string as a current date
1 parent 6bc8a2a commit fd0d73e

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

Doctrine/Orm/Filter/DateFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function apply(ResourceInterface $resource, QueryBuilder $queryBuilder, R
7676

7777
$nullManagement = isset($this->properties[$property]) ? $this->properties[$property] : null;
7878

79-
if (isset($values[self::PARAMETER_BEFORE])) {
79+
if (!empty($values[self::PARAMETER_BEFORE])) {
8080
$this->addWhere(
8181
$queryBuilder,
8282
$alias,
@@ -87,7 +87,7 @@ public function apply(ResourceInterface $resource, QueryBuilder $queryBuilder, R
8787
);
8888
}
8989

90-
if (isset($values[self::PARAMETER_AFTER])) {
90+
if (!empty($values[self::PARAMETER_AFTER])) {
9191
$this->addWhere(
9292
$queryBuilder,
9393
$alias,

features/doctrine/date-filter.feature

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,71 @@ Feature: Order filter on collections
226226
}
227227
}
228228
"""
229+
230+
@createSchema
231+
@dropSchema
232+
Scenario: Search for entities within a range
233+
Given there is "2" dummy objects with dummyDate
234+
When I send a "GET" request to "/dummies?dummyDate[after]="
235+
Then the response status code should be 200
236+
And the response should be in JSON
237+
And the header "Content-Type" should be equal to "application/ld+json"
238+
And the JSON node "hydra:totalItems" should be equal to "2"
239+
And the JSON should be valid according to this schema:
240+
"""
241+
{
242+
"type": "object",
243+
"properties": {
244+
"@context": {"pattern": "^/contexts/Dummy$"},
245+
"@id": {"pattern": "^/dummies\\?dummyDate\\[after\\]=$"},
246+
"@type": {"pattern": "^hydra:PagedCollection$"},
247+
"hydra:totalItems": {"type":"number"},
248+
"hydra:member": {
249+
"type": "array",
250+
"items": {
251+
"type": "object",
252+
"properties": {
253+
"@id": {
254+
"oneOf": [
255+
{"pattern": "^/dummies/1$"},
256+
{"pattern": "^/dummies/2$"}
257+
]
258+
}
259+
}
260+
}
261+
}
262+
}
263+
}
264+
"""
265+
266+
When I send a "GET" request to "/dummies?dummyDate[before]="
267+
Then the response status code should be 200
268+
And the response should be in JSON
269+
And the header "Content-Type" should be equal to "application/ld+json"
270+
And the JSON node "hydra:totalItems" should be equal to "2"
271+
And the JSON should be valid according to this schema:
272+
"""
273+
{
274+
"type": "object",
275+
"properties": {
276+
"@context": {"pattern": "^/contexts/Dummy$"},
277+
"@id": {"pattern": "^/dummies\\?dummyDate\\[before\\]=$"},
278+
"@type": {"pattern": "^hydra:PagedCollection$"},
279+
"hydra:totalItems": {"type":"number"},
280+
"hydra:member": {
281+
"type": "array",
282+
"items": {
283+
"type": "object",
284+
"properties": {
285+
"@id": {
286+
"oneOf": [
287+
{"pattern": "^/dummies/1$"},
288+
{"pattern": "^/dummies/2$"}
289+
]
290+
}
291+
}
292+
}
293+
}
294+
}
295+
}
296+
"""

0 commit comments

Comments
 (0)