Skip to content

Commit

Permalink
Merge 2e8acbf into 7f46a36
Browse files Browse the repository at this point in the history
  • Loading branch information
famoser committed Mar 1, 2021
2 parents 7f46a36 + 2e8acbf commit e89d1fe
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@
* MongoDB: `date_immutable` support (#3940)
* DataProvider: Add `TraversablePaginator` (#3783)
* Swagger UI: Add `swagger_ui_extra_configuration` to Swagger / OpenAPI configuration (#3731)
* OrderFilter: Add `nulls_always_first` and `nulls_always_last` to `nulls_comparison` (#4103)

## 2.6.3

Expand Down
10 changes: 10 additions & 0 deletions src/Bridge/Doctrine/Common/Filter/OrderFilterInterface.php
Expand Up @@ -26,6 +26,8 @@ interface OrderFilterInterface
public const DIRECTION_DESC = 'DESC';
public const NULLS_SMALLEST = 'nulls_smallest';
public const NULLS_LARGEST = 'nulls_largest';
public const NULLS_ALWAYS_FIRST = 'nulls_always_first';
public const NULLS_ALWAYS_LAST = 'nulls_always_last';
public const NULLS_DIRECTION_MAP = [
self::NULLS_SMALLEST => [
'ASC' => 'ASC',
Expand All @@ -35,5 +37,13 @@ interface OrderFilterInterface
'ASC' => 'DESC',
'DESC' => 'ASC',
],
self::NULLS_ALWAYS_FIRST => [
'ASC' => 'ASC',
'DESC' => 'ASC',
],
self::NULLS_ALWAYS_LAST => [
'ASC' => 'DESC',
'DESC' => 'DESC',
],
];
}
56 changes: 56 additions & 0 deletions tests/Bridge/Doctrine/Common/Filter/OrderFilterTestTrait.php
Expand Up @@ -232,6 +232,62 @@ private function provideApplyTestArguments(): array
],
],
],
'nulls_always_first (asc)' => [
[
'dummyDate' => [
'nulls_comparison' => 'nulls_always_first',
],
'name' => null,
],
[
'order' => [
'dummyDate' => 'asc',
'name' => 'desc',
],
],
],
'nulls_always_first (desc)' => [
[
'dummyDate' => [
'nulls_comparison' => 'nulls_always_first',
],
'name' => null,
],
[
'order' => [
'dummyDate' => 'desc',
'name' => 'desc',
],
],
],
'nulls_always_last (asc)' => [
[
'dummyDate' => [
'nulls_comparison' => 'nulls_always_last',
],
'name' => null,
],
[
'order' => [
'dummyDate' => 'asc',
'name' => 'desc',
],
],
],
'nulls_always_last (desc)' => [
[
'dummyDate' => [
'nulls_comparison' => 'nulls_always_last',
],
'name' => null,
],
[
'order' => [
'dummyDate' => 'desc',
'name' => 'desc',
],
],
],
'not having order should not throw a deprecation (select unchanged)' => [
[
'id' => null,
Expand Down
20 changes: 20 additions & 0 deletions tests/Bridge/Doctrine/Orm/Filter/OrderFilterTest.php
Expand Up @@ -265,6 +265,26 @@ public function provideApplyTestData(): array
null,
$orderFilterFactory,
],
'nulls_always_first (asc)' => [
sprintf('SELECT o, CASE WHEN o.dummyDate IS NULL THEN 0 ELSE 1 END AS HIDDEN _o_dummyDate_null_rank FROM %s o ORDER BY _o_dummyDate_null_rank ASC, o.dummyDate ASC, o.name DESC', Dummy::class),
null,
$orderFilterFactory,
],
'nulls_always_first (desc)' => [
sprintf('SELECT o, CASE WHEN o.dummyDate IS NULL THEN 0 ELSE 1 END AS HIDDEN _o_dummyDate_null_rank FROM %s o ORDER BY _o_dummyDate_null_rank ASC, o.dummyDate DESC, o.name DESC', Dummy::class),
null,
$orderFilterFactory,
],
'nulls_always_last (asc)' => [
sprintf('SELECT o, CASE WHEN o.dummyDate IS NULL THEN 0 ELSE 1 END AS HIDDEN _o_dummyDate_null_rank FROM %s o ORDER BY _o_dummyDate_null_rank DESC, o.dummyDate ASC, o.name DESC', Dummy::class),
null,
$orderFilterFactory,
],
'nulls_always_last (desc)' => [
sprintf('SELECT o, CASE WHEN o.dummyDate IS NULL THEN 0 ELSE 1 END AS HIDDEN _o_dummyDate_null_rank FROM %s o ORDER BY _o_dummyDate_null_rank DESC, o.dummyDate DESC, o.name DESC', Dummy::class),
null,
$orderFilterFactory,
],
'not having order should not throw a deprecation (select unchanged)' => [
sprintf('SELECT o FROM %s o', Dummy::class),
null,
Expand Down

0 comments on commit e89d1fe

Please sign in to comment.