Skip to content

Commit cc624f3

Browse files
committed
updated tests for sortings; allowed union type in query helper
1 parent e48aef4 commit cc624f3

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/Query/Sorting.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,20 @@ public function toArray(): array
9393
}
9494

9595
/**
96-
* @param Collection $sortings
96+
* @param Sorting|Collection $sortings
9797
* @return array
9898
*/
99-
public static function sortQuery(Collection $sortings): array
99+
public static function sortQuery(Sorting|Collection $sortings): array
100100
{
101101
$querySortings = new Collection();
102102

103-
$sortings->each(function (Sorting $sorting) use ($querySortings) {
104-
$querySortings->add($sorting->toArray());
105-
});
103+
if($sortings instanceof Collection) {
104+
$sortings->each(function (Sorting $sorting) use ($querySortings) {
105+
$querySortings->push($sorting->toArray());
106+
});
107+
} else {
108+
$querySortings->push($sortings->toArray());
109+
}
106110

107111
return $querySortings->toArray();
108112
}

tests/SortingTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Illuminate\Support\Collection;
66

77
it('can sort by a single property', function () {
8-
$expectedSortQuery = '[{"property":"Birth year","direction":"ascending"}';
8+
$expectedSortQuery = '[{"property":"Birth year","direction":"ascending"}]';
99

1010
$sortBy = Sorting::propertySort("Birth year", "ascending");
1111
$this->assertEquals($expectedSortQuery, json_encode(Sorting::sortQuery($sortBy)));});
@@ -22,7 +22,7 @@
2222
});
2323

2424
it('refuses other classes than sorting or collection in the sortBy() method', function () {
25-
$this->expectException(HandlingException::class);
25+
$this->expectException(TypeError::class);
2626

2727
Notion::database('8284f3ff77e24d4a939d19459e4d6bdc')
2828
->sortBy(new stdClass())

0 commit comments

Comments
 (0)