diff --git a/docs/how-to/query-database.md b/docs/how-to/query-database.md index dd180149..02e7474c 100644 --- a/docs/how-to/query-database.md +++ b/docs/how-to/query-database.md @@ -23,7 +23,7 @@ $query = Query::create() TextFilter::property("Name")->contains("John"), ) ) - ->withAddedSort(Sort::property("Name")->ascending()) + ->addSort(Sort::property("Name")->ascending()) ->withPageSize(20); $result = $notion->databases()->query($database, $query); diff --git a/src/Databases/Query.php b/src/Databases/Query.php index b3e3d4f4..2bafab2b 100644 --- a/src/Databases/Query.php +++ b/src/Databases/Query.php @@ -30,8 +30,8 @@ public function changeFilter(Filter $filter): self return new self($filter, $this->sorts, $this->startCursor, $this->pageSize); } - /** Add new sort change lowest priority */ - public function changeAddedSort(Sort $sort): self + /** Add new sort with lowest priority */ + public function addSort(Sort $sort): self { $sorts = $this->sorts; $sorts[] = $sort; @@ -39,6 +39,15 @@ public function changeAddedSort(Sort $sort): self return new self($this->filter, $sorts, $this->startCursor, $this->pageSize); } + /** + * @deprecated 1.1.0 This method will be removed in future versions. Use 'addSort' instead. + * @see \Notion\Databases\Query::addSort() + */ + public function changeAddedSort(Sort $sort): self + { + return $this->addSort($sort); + } + /** Replace all sorts */ public function changeSorts(Sort ...$sorts): self { diff --git a/tests/Unit/Databases/QueryTest.php b/tests/Unit/Databases/QueryTest.php index ec72749b..35426f9e 100644 --- a/tests/Unit/Databases/QueryTest.php +++ b/tests/Unit/Databases/QueryTest.php @@ -31,8 +31,8 @@ public function test_query_change_filter(): void public function test_add_sort(): void { $query = Query::create() - ->changeAddedSort(Sort::createdTime()->descending()) - ->changeAddedSort(Sort::property("Title")->ascending()); + ->addSort(Sort::createdTime()->descending()) + ->addSort(Sort::property("Title")->ascending()); $this->assertCount(2, $query->sorts); } @@ -40,13 +40,23 @@ public function test_add_sort(): void public function test_replace_sorts(): void { $query = Query::create() - ->changeAddedSort(Sort::createdTime()->descending()) - ->changeAddedSort(Sort::property("Title")->ascending()) + ->addSort(Sort::createdTime()->descending()) + ->addSort(Sort::property("Title")->ascending()) ->changeSorts(Sort::lastEditedTime()->descending()); $this->assertCount(1, $query->sorts); } + /** @psalm-suppress DeprecatedMethod */ + public function test_deprecated_change_added_sort(): void + { + $query = Query::create() + ->changeAddedSort(Sort::createdTime()->descending()) + ->changeAddedSort(Sort::property("Title")->ascending()); + + $this->assertCount(2, $query->sorts); + } + public function test_query_change_start_cursor(): void { $query = Query::create() @@ -87,7 +97,7 @@ public function test_complete_query_to_array(): void { $query = Query::create() ->changeFilter(TextFilter::property("Title")->contains("abc")) - ->changeAddedSort(Sort::property("Title")->ascending()) + ->addSort(Sort::property("Title")->ascending()) ->changeStartCursor("889431ed-4f50-460b-a926-36f6cf0f9669") ->changePageSize(20);