@@ -145,15 +145,52 @@ public function testStoreCannotAddOnInvalidResponse()
145145 $ store = new Store ($ httpClient , 'http://127.0.0.1:6333 ' , 'test ' , 'test ' );
146146
147147 $ this ->expectException (ClientException::class);
148- $ this ->expectExceptionMessage ('HTTP 400 returned for "http://127.0.0.1:6333/collections/test/points". ' );
148+ $ this ->expectExceptionMessage ('HTTP 400 returned for "http://127.0.0.1:6333/collections/test/points?wait=true ". ' );
149149 $ this ->expectExceptionCode (400 );
150150 $ store ->add (new VectorDocument (Uuid::v4 (), new Vector ([0.1 , 0.2 , 0.3 ])));
151151 }
152152
153153 public function testStoreCanAdd ()
154154 {
155- $ httpClient = new MockHttpClient ([
156- new JsonMockResponse ([
155+ $ document = new VectorDocument (Uuid::v4 (), new Vector ([0.1 , 0.2 , 0.3 ]));
156+
157+ $ httpClient = new MockHttpClient (static function (string $ method , string $ url , array $ options ) use ($ document ): JsonMockResponse {
158+ self ::assertArrayHasKey ('wait ' , $ options ['query ' ]);
159+ self ::assertEquals ('true ' , $ options ['query ' ]['wait ' ]);
160+
161+ return new JsonMockResponse ([
162+ 'time ' => 0.002 ,
163+ 'status ' => 'ok ' ,
164+ 'result ' => [
165+ 'points ' => [
166+ [
167+ 'id ' => (string ) $ document ->id ,
168+ 'payload ' => (array ) $ document ->metadata ,
169+ 'vector ' => $ document ->vector ->getData (),
170+ ],
171+ ],
172+ ],
173+ ], [
174+ 'http_code ' => 200 ,
175+ ]);
176+ }, 'http://127.0.0.1:6333 ' );
177+
178+ $ store = new Store ($ httpClient , 'http://127.0.0.1:6333 ' , 'test ' , 'test ' );
179+
180+ $ store ->add ($ document );
181+
182+ $ this ->assertSame (1 , $ httpClient ->getRequestsCount ());
183+ }
184+
185+ public function testStoreCanAddAsynchronously ()
186+ {
187+ $ document = new VectorDocument (Uuid::v4 (), new Vector ([0.1 , 0.2 , 0.3 ]));
188+
189+ $ httpClient = new MockHttpClient (static function (string $ method , string $ url , array $ options ): JsonMockResponse {
190+ self ::assertArrayHasKey ('wait ' , $ options ['query ' ]);
191+ self ::assertEquals ('false ' , $ options ['query ' ]['wait ' ]);
192+
193+ return new JsonMockResponse ([
157194 'time ' => 0.002 ,
158195 'status ' => 'ok ' ,
159196 'result ' => [
@@ -162,12 +199,12 @@ public function testStoreCanAdd()
162199 ],
163200 ], [
164201 'http_code ' => 200 ,
165- ]),
166- ] , 'http://127.0.0.1:6333 ' );
202+ ]);
203+ } , 'http://127.0.0.1:6333 ' );
167204
168- $ store = new Store ($ httpClient , 'http://127.0.0.1:6333 ' , 'test ' , 'test ' );
205+ $ store = new Store ($ httpClient , 'http://127.0.0.1:6333 ' , 'test ' , 'test ' , async: true );
169206
170- $ store ->add (new VectorDocument (Uuid:: v4 (), new Vector ([ 0.1 , 0.2 , 0.3 ])) );
207+ $ store ->add ($ document );
171208
172209 $ this ->assertSame (1 , $ httpClient ->getRequestsCount ());
173210 }
0 commit comments