Skip to content

Commit 689c6f1

Browse files
committed
Merge branch 'bump-meilisearch-v0.12.0' into feat/add-batches-endpoints
2 parents 94ed604 + 77cd241 commit 689c6f1

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/Contracts/TasksQuery.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,16 @@ class TasksQuery
2222
*/
2323
private ?array $canceledBy = null;
2424

25+
/**
26+
* @var int|null
27+
*/
2528
private ?int $batchUid = null;
2629

30+
/**
31+
* @var bool|null
32+
*/
33+
private ?bool $reverse = null;
34+
2735
/**
2836
* @return $this
2937
*/
@@ -66,6 +74,13 @@ public function setBatchUid(int $batchUid): self
6674
return $this;
6775
}
6876

77+
public function setReverse(bool $reverse): self
78+
{
79+
$this->reverse = $reverse;
80+
81+
return $this;
82+
}
83+
6984
public function toArray(): array
7085
{
7186
return array_filter(
@@ -76,6 +91,7 @@ public function toArray(): array
7691
'limit' => $this->limit,
7792
'canceledBy' => $this->formatArray($this->canceledBy),
7893
'batchUid' => $this->batchUid,
94+
'reverse' => (null !== $this->reverse ? ($this->reverse ? 'true' : 'false') : null),
7995
]
8096
),
8197
static function ($item) {

tests/Contracts/TasksQueryTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Tests\Contracts;
66

7+
// TODO: refactor to make sure these tests clean up after themselves
8+
79
use Meilisearch\Contracts\TasksQuery;
810
use PHPUnit\Framework\TestCase;
911

@@ -109,4 +111,15 @@ public function testSetFrom(): void
109111

110112
self::assertSame(['from' => 1], $data->toArray());
111113
}
114+
115+
/**
116+
* @testWith [true, "true"]
117+
* [false, "false"]
118+
*/
119+
public function testSetReverse(bool $reverse, string $expected): void
120+
{
121+
$data = (new TasksQuery())->setReverse($reverse);
122+
123+
self::assertSame(['reverse' => $expected], $data->toArray());
124+
}
112125
}

tests/Endpoints/TasksTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,22 @@ public function testCancelTasksWithFilter(): void
152152
self::assertSame('succeeded', $response['status']);
153153
}
154154

155+
public function testGetAllTasksInReverseOrder(): void
156+
{
157+
$startDate = new \DateTimeImmutable('now');
158+
159+
$tasks = $this->client->getTasks((new TasksQuery())
160+
->setAfterEnqueuedAt($startDate)
161+
);
162+
$reversedTasks = $this->client->getTasks((new TasksQuery())
163+
->setAfterEnqueuedAt($startDate)
164+
->setReverse(true)
165+
);
166+
167+
self::assertSameSize($tasks->getResults(), $reversedTasks->getResults());
168+
self::assertSame($tasks->getResults(), array_reverse($reversedTasks->getResults()));
169+
}
170+
155171
public function testExceptionIfNoTaskIdWhenGetting(): void
156172
{
157173
$this->expectException(ApiException::class);

0 commit comments

Comments
 (0)