7
7
use Meilisearch \Contracts \DocumentsQuery ;
8
8
use Meilisearch \Contracts \Http ;
9
9
use Meilisearch \Contracts \Task ;
10
+ use Meilisearch \Contracts \TaskDetails \DocumentAdditionOrUpdateDetails ;
11
+ use Meilisearch \Contracts \TaskStatus ;
10
12
use Meilisearch \Contracts \TaskType ;
11
13
use Meilisearch \Endpoints \Indexes ;
12
14
use Meilisearch \Exceptions \ApiException ;
@@ -75,11 +77,11 @@ public function testAddDocumentsCsv(): void
75
77
fclose ($ fileCsv );
76
78
77
79
$ task = $ index ->addDocumentsCsv ($ documentCsv );
80
+ $ completedTask = $ index ->waitForTask ($ task ->getTaskUid ());
78
81
79
- $ update = $ index ->waitForTask ($ task ->getTaskUid ());
80
-
81
- self ::assertSame ('succeeded ' , $ update ['status ' ]);
82
- self ::assertNotSame (0 , $ update ['details ' ]['receivedDocuments ' ]);
82
+ self ::assertSame (TaskStatus::Succeeded, $ completedTask ->getStatus ());
83
+ self ::assertInstanceOf (DocumentAdditionOrUpdateDetails::class, $ details = $ completedTask ->getDetails ());
84
+ self ::assertNotSame (0 , $ details ->receivedDocuments );
83
85
84
86
$ response = $ index ->getDocuments ();
85
87
self ::assertCount (20 , $ response );
@@ -92,11 +94,11 @@ public function testAddDocumentsCsvWithCustomSeparator(): void
92
94
$ csv = file_get_contents ('./tests/datasets/songs-custom-separator.csv ' , true );
93
95
94
96
$ task = $ index ->addDocumentsCsv ($ csv , null , '| ' );
97
+ $ completedTask = $ index ->waitForTask ($ task ->getTaskUid ());
95
98
96
- $ update = $ index ->waitForTask ($ task ->getTaskUid ());
97
-
98
- self ::assertSame ('succeeded ' , $ update ['status ' ]);
99
- self ::assertSame (6 , $ update ['details ' ]['receivedDocuments ' ]);
99
+ self ::assertSame (TaskStatus::Succeeded, $ completedTask ->getStatus ());
100
+ self ::assertInstanceOf (DocumentAdditionOrUpdateDetails::class, $ details = $ completedTask ->getDetails ());
101
+ self ::assertSame (6 , $ details ->receivedDocuments );
100
102
101
103
$ documents = $ index ->getDocuments ()->getResults ();
102
104
self ::assertSame ('Teenage Neon Jungle ' , $ documents [4 ]['album ' ]);
@@ -112,11 +114,11 @@ public function testAddDocumentsJson(): void
112
114
fclose ($ fileJson );
113
115
114
116
$ task = $ index ->addDocumentsJson ($ documentJson );
117
+ $ completedTask = $ index ->waitForTask ($ task ->getTaskUid ());
115
118
116
- $ update = $ index ->waitForTask ($ task ->getTaskUid ());
117
-
118
- self ::assertSame ('succeeded ' , $ update ['status ' ]);
119
- self ::assertNotSame (0 , $ update ['details ' ]['receivedDocuments ' ]);
119
+ self ::assertSame (TaskStatus::Succeeded, $ completedTask ->getStatus ());
120
+ self ::assertInstanceOf (DocumentAdditionOrUpdateDetails::class, $ details = $ completedTask ->getDetails ());
121
+ self ::assertNotSame (0 , $ details ->receivedDocuments );
120
122
121
123
$ response = $ index ->getDocuments ();
122
124
self ::assertCount (20 , $ response );
@@ -131,11 +133,11 @@ public function testAddDocumentsNdJson(): void
131
133
fclose ($ fileNdJson );
132
134
133
135
$ task = $ index ->addDocumentsNdjson ($ documentNdJson );
136
+ $ completedTask = $ index ->waitForTask ($ task ->getTaskUid ());
134
137
135
- $ update = $ index ->waitForTask ($ task ->getTaskUid ());
136
-
137
- self ::assertSame ('succeeded ' , $ update ['status ' ]);
138
- self ::assertNotSame (0 , $ update ['details ' ]['receivedDocuments ' ]);
138
+ self ::assertSame (TaskStatus::Succeeded, $ completedTask ->getStatus ());
139
+ self ::assertInstanceOf (DocumentAdditionOrUpdateDetails::class, $ details = $ completedTask ->getDetails ());
140
+ self ::assertNotSame (0 , $ details ->receivedDocuments );
139
141
140
142
$ response = $ index ->getDocuments ();
141
143
self ::assertCount (20 , $ response );
@@ -155,8 +157,10 @@ public function testCannotAddDocumentWhenJsonEncodingFails(): void
155
157
public function testGetSingleDocumentWithIntegerDocumentId (): void
156
158
{
157
159
$ index = $ this ->createEmptyIndex ($ this ->safeIndexName ('movies ' ));
160
+
158
161
$ task = $ index ->addDocuments (self ::DOCUMENTS );
159
162
$ index ->waitForTask ($ task ->getTaskUid ());
163
+
160
164
$ doc = $ this ->findDocumentWithId (self ::DOCUMENTS , 4 );
161
165
$ response = $ index ->getDocument ($ doc ['id ' ]);
162
166
@@ -167,8 +171,10 @@ public function testGetSingleDocumentWithIntegerDocumentId(): void
167
171
public function testGetSingleDocumentWithFields (): void
168
172
{
169
173
$ index = $ this ->createEmptyIndex ($ this ->safeIndexName ('movies ' ));
174
+
170
175
$ task = $ index ->addDocuments (self ::DOCUMENTS );
171
176
$ index ->waitForTask ($ task ->getTaskUid ());
177
+
172
178
$ doc = $ this ->findDocumentWithId (self ::DOCUMENTS , 4 );
173
179
$ response = $ index ->getDocument ($ doc ['id ' ], ['title ' ]);
174
180
@@ -179,8 +185,10 @@ public function testGetSingleDocumentWithFields(): void
179
185
public function testGetSingleDocumentWithStringDocumentId (): void
180
186
{
181
187
$ stringDocumentId = 'myUniqueId ' ;
188
+
182
189
$ index = $ this ->createEmptyIndex ($ this ->safeIndexName ('movies ' ));
183
190
$ task = $ index ->addDocuments ([['id ' => $ stringDocumentId ]]);
191
+
184
192
$ index ->waitForTask ($ task ->getTaskUid ());
185
193
$ response = $ index ->getDocument ($ stringDocumentId );
186
194
@@ -190,8 +198,10 @@ public function testGetSingleDocumentWithStringDocumentId(): void
190
198
public function testGetMultipleDocumentsByIds (): void
191
199
{
192
200
$ index = $ this ->createEmptyIndex ($ this ->safeIndexName ('movies ' ));
201
+
193
202
$ task = $ index ->addDocuments (self ::DOCUMENTS );
194
203
$ index ->waitForTask ($ task ->getTaskUid ());
204
+
195
205
$ documentIds = [1 , 2 ];
196
206
$ response = $ index ->getDocuments ((new DocumentsQuery ())->setIds ($ documentIds ));
197
207
@@ -204,8 +214,10 @@ public function testGetMultipleDocumentsByIds(): void
204
214
public function testReplaceDocuments (): void
205
215
{
206
216
$ index = $ this ->createEmptyIndex ($ this ->safeIndexName ('movies ' ));
217
+
207
218
$ task = $ index ->addDocuments (self ::DOCUMENTS );
208
219
$ index ->waitForTask ($ task ->getTaskUid ());
220
+
209
221
$ replacement = [
210
222
'id ' => 2 ,
211
223
'title ' => 'The Red And The Black ' ,
@@ -917,7 +929,7 @@ public function testUpdateDocumentsNdjsonInBatches(): void
917
929
self ::assertSame ('Ailitp ' , $ response ['artist ' ]);
918
930
}
919
931
920
- private function findDocumentWithId ($ documents , $ documentId )
932
+ private function findDocumentWithId ($ documents , $ documentId ): ? array
921
933
{
922
934
foreach ($ documents as $ document ) {
923
935
if ($ document ['id ' ] === $ documentId ) {
0 commit comments