From 46e38fa72e3793cfdc7183e56dc26f5526c6da0d Mon Sep 17 00:00:00 2001 From: Holger Veltrup Date: Fri, 10 May 2024 15:20:18 +0200 Subject: [PATCH] feat: add custom sort field --- src/Dto/Search/Query/Sort/CustomField.php | 18 ++++++++++++++++++ src/Service/Search/Schema2xFieldMapper.php | 3 +++ .../Service/Search/Schema2xFieldMapperTest.php | 10 ++++++++++ 3 files changed, 31 insertions(+) create mode 100644 src/Dto/Search/Query/Sort/CustomField.php diff --git a/src/Dto/Search/Query/Sort/CustomField.php b/src/Dto/Search/Query/Sort/CustomField.php new file mode 100644 index 0000000..7fcb072 --- /dev/null +++ b/src/Dto/Search/Query/Sort/CustomField.php @@ -0,0 +1,18 @@ +field; default: throw new InvalidArgumentException( 'Unsupported sort criteria: ' . get_class($criteria) diff --git a/test/Service/Search/Schema2xFieldMapperTest.php b/test/Service/Search/Schema2xFieldMapperTest.php index 7c8404d..c7615f5 100644 --- a/test/Service/Search/Schema2xFieldMapperTest.php +++ b/test/Service/Search/Schema2xFieldMapperTest.php @@ -22,6 +22,7 @@ use Atoolo\Search\Dto\Search\Query\Filter\RelativeDateRangeFilter; use Atoolo\Search\Dto\Search\Query\Filter\SiteFilter; use Atoolo\Search\Dto\Search\Query\Sort\Criteria; +use Atoolo\Search\Dto\Search\Query\Sort\CustomField; use Atoolo\Search\Dto\Search\Query\Sort\Date; use Atoolo\Search\Dto\Search\Query\Sort\Headline; use Atoolo\Search\Dto\Search\Query\Sort\Name; @@ -158,6 +159,15 @@ public function testGetSortField( ); } + public function testGetSortCustomField(): void + { + $criteria = new CustomField('custom_field'); + $this->assertEquals( + 'custom_field', + $this->mapper->getSortField($criteria) + ); + } + public function testUnsupportedSortField(): void { $this->expectException(InvalidArgumentException::class);