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