File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ class TasksQuery
22
22
*/
23
23
private ?array $ canceledBy = null ;
24
24
25
+ private ?bool $ reverse = null ;
26
+
25
27
/**
26
28
* @return $this
27
29
*/
@@ -54,6 +56,16 @@ public function setLimit(int $limit): self
54
56
return $ this ;
55
57
}
56
58
59
+ /**
60
+ * @return $this
61
+ */
62
+ public function setReverse (bool $ reverse ): self
63
+ {
64
+ $ this ->reverse = $ reverse ;
65
+
66
+ return $ this ;
67
+ }
68
+
57
69
public function toArray (): array
58
70
{
59
71
return array_filter (
@@ -63,8 +75,12 @@ public function toArray(): array
63
75
'from ' => $ this ->from ,
64
76
'limit ' => $ this ->limit ,
65
77
'canceledBy ' => $ this ->formatArray ($ this ->canceledBy ),
78
+ 'reverse ' => (null !== $ this ->reverse ? ($ this ->reverse ? 'true ' : 'false ' ) : null ),
66
79
]
67
- ), static function ($ item ) { return null !== $ item ; }
80
+ ),
81
+ static function ($ item ) {
82
+ return null !== $ item ;
83
+ }
68
84
);
69
85
}
70
86
}
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 @@ -140,6 +140,22 @@ public function testCancelTasksWithFilter(): void
140
140
self ::assertSame ('succeeded ' , $ response ['status ' ]);
141
141
}
142
142
143
+ public function testGetAllTasksInReverseOrder (): void
144
+ {
145
+ $ startDate = new \DateTimeImmutable ('now ' );
146
+
147
+ $ tasks = $ this ->client ->getTasks ((new TasksQuery ())
148
+ ->setAfterEnqueuedAt ($ startDate )
149
+ );
150
+ $ reversedTasks = $ this ->client ->getTasks ((new TasksQuery ())
151
+ ->setAfterEnqueuedAt ($ startDate )
152
+ ->setReverse (true )
153
+ );
154
+
155
+ self ::assertSameSize ($ tasks ->getResults (), $ reversedTasks ->getResults ());
156
+ self ::assertSame ($ tasks ->getResults (), array_reverse ($ reversedTasks ->getResults ()));
157
+ }
158
+
143
159
public function testExceptionIfNoTaskIdWhenGetting (): void
144
160
{
145
161
$ this ->expectException (ApiException::class);
You can’t perform that action at this time.
0 commit comments