File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -22,8 +22,16 @@ class TasksQuery
22
22
*/
23
23
private ?array $ canceledBy = null ;
24
24
25
+ /**
26
+ * @var int|null
27
+ */
25
28
private ?int $ batchUid = null ;
26
29
30
+ /**
31
+ * @var bool|null
32
+ */
33
+ private ?bool $ reverse = null ;
34
+
27
35
/**
28
36
* @return $this
29
37
*/
@@ -66,6 +74,13 @@ public function setBatchUid(int $batchUid): self
66
74
return $ this ;
67
75
}
68
76
77
+ public function setReverse (bool $ reverse ): self
78
+ {
79
+ $ this ->reverse = $ reverse ;
80
+
81
+ return $ this ;
82
+ }
83
+
69
84
public function toArray (): array
70
85
{
71
86
return array_filter (
@@ -76,6 +91,7 @@ public function toArray(): array
76
91
'limit ' => $ this ->limit ,
77
92
'canceledBy ' => $ this ->formatArray ($ this ->canceledBy ),
78
93
'batchUid ' => $ this ->batchUid ,
94
+ 'reverse ' => (null !== $ this ->reverse ? ($ this ->reverse ? 'true ' : 'false ' ) : null ),
79
95
]
80
96
),
81
97
static function ($ item ) {
Original file line number Diff line number Diff line change 4
4
5
5
namespace Tests \Contracts ;
6
6
7
+ // TODO: refactor to make sure these tests clean up after themselves
8
+
7
9
use Meilisearch \Contracts \TasksQuery ;
8
10
use PHPUnit \Framework \TestCase ;
9
11
@@ -109,4 +111,15 @@ public function testSetFrom(): void
109
111
110
112
self ::assertSame (['from ' => 1 ], $ data ->toArray ());
111
113
}
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
+ }
112
125
}
Original file line number Diff line number Diff line change @@ -152,6 +152,22 @@ public function testCancelTasksWithFilter(): void
152
152
self ::assertSame ('succeeded ' , $ response ['status ' ]);
153
153
}
154
154
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
+
155
171
public function testExceptionIfNoTaskIdWhenGetting (): void
156
172
{
157
173
$ this ->expectException (ApiException::class);
You can’t perform that action at this time.
0 commit comments