Skip to content

Commit 7d529b9

Browse files
committed
Add parameter to get tasks in reverse order
1 parent 8770e2e commit 7d529b9

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/Contracts/TasksQuery.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function toArray(): array
7878
'from' => $this->from,
7979
'limit' => $this->limit,
8080
'canceledBy' => $this->formatArray($this->canceledBy),
81-
'reverse' => $this->reverse,
81+
'reverse' => $this->reverse !== null ? json_encode($this->reverse) : null,
8282
]
8383
), static function ($item) { return null !== $item; }
8484
);

tests/Contracts/TasksQueryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,6 @@ public function testSetReverse(): void
114114
{
115115
$data = (new TasksQuery())->setReverse(true);
116116

117-
self::assertSame(['reverse' => true], $data->toArray());
117+
self::assertSame(['reverse' => json_encode(true)], $data->toArray());
118118
}
119119
}

tests/Endpoints/TasksTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ public function testCancelTasksWithFilter(): void
140140
self::assertSame('succeeded', $response['status']);
141141
}
142142

143+
public function testGetAllTasksInReverseOrder(): void
144+
{
145+
$date = new \DateTime();
146+
147+
$this->seedIndex();
148+
$this->seedIndex();
149+
150+
$tasks = $this->client->getTasks((new TasksQuery())->setAfterEnqueuedAt($date)->setLimit(2));
151+
$reversedTasks = $this->client->getTasks((new TasksQuery())->setAfterEnqueuedAt($date)->setReverse(true)->setLimit(2));
152+
153+
self::assertSame($reversedTasks->getResults(), array_reverse($tasks->getResults()));
154+
}
155+
143156
public function testExceptionIfNoTaskIdWhenGetting(): void
144157
{
145158
$this->expectException(ApiException::class);

0 commit comments

Comments
 (0)