Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nulls_always_first and nulls_always_last to nulls_comparison #4103

Merged
merged 5 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
64 changes: 64 additions & 0 deletions tests/Bridge/Doctrine/MongoDbOdm/Filter/OrderFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,70 @@ public function provideApplyTestData(): array
],
$orderFilterFactory,
],
'nulls_always_first (asc)' => [
[
[
'$sort' => [
'dummyDate' => 1,
],
],
[
'$sort' => [
'dummyDate' => 1,
'name' => -1,
],
],
],
$orderFilterFactory,
],
'nulls_always_first (desc)' => [
[
[
'$sort' => [
'dummyDate' => -1,
],
],
[
'$sort' => [
'dummyDate' => -1,
'name' => -1,
],
],
],
$orderFilterFactory,
],
'nulls_always_last (asc)' => [
[
[
'$sort' => [
'dummyDate' => 1,
],
],
[
'$sort' => [
'dummyDate' => 1,
'name' => -1,
],
],
],
$orderFilterFactory,
],
'nulls_always_last (desc)' => [
[
[
'$sort' => [
'dummyDate' => -1,
],
],
[
'$sort' => [
'dummyDate' => -1,
'name' => -1,
],
],
],
$orderFilterFactory,
],
'not having order should not throw a deprecation (select unchanged)' => [
[],
$orderFilterFactory,
Expand Down
20 changes: 20 additions & 0 deletions tests/Bridge/Doctrine/Orm/Filter/OrderFilterTest.php
Original file line number Diff line number Diff line change
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