@@ -193,4 +193,57 @@ public function testSendRequestWithAsyncWillReturnElasticsearch()
193193 $ this ->assertInstanceOf (Promise::class, $ result );
194194 $ this ->assertInstanceOf (Elasticsearch::class, $ result ->wait ());
195195 }
196+
197+ public function testSetServerless ()
198+ {
199+ $ this ->client ->setServerless (true );
200+ $ this ->assertTrue ($ this ->client ->getServerless ());
201+ }
202+
203+ public function testServerlessIsDefaultFalse ()
204+ {
205+ $ this ->assertFalse ($ this ->client ->getServerless ());
206+ }
207+
208+ public function testIsServerlessTrueWhenReponseFromServerless ()
209+ {
210+ $ request = $ this ->psr17Factory ->createRequest ('GET ' , 'localhost:9200 ' );
211+ $ response = $ this ->psr17Factory ->createResponse (200 )
212+ ->withHeader ('X-Elastic-Product ' , 'Elasticsearch ' )
213+ ->withHeader (Client::API_VERSION_HEADER , Client::API_VERSION );
214+ $ this ->httpClient ->addResponse ($ response );
215+
216+ $ result = $ this ->client ->sendRequest ($ request );
217+ $ this ->assertTrue ($ this ->client ->getServerless ());
218+ }
219+
220+ public function testIsServerlessTrueWhenReponseFromServerlessWithAsyncOnSuccess ()
221+ {
222+ $ request = $ this ->psr17Factory ->createRequest ('GET ' , 'localhost:9200 ' );
223+ $ response = $ this ->psr17Factory ->createResponse (200 )
224+ ->withHeader ('X-Elastic-Product ' , 'Elasticsearch ' )
225+ ->withHeader (Client::API_VERSION_HEADER , Client::API_VERSION );
226+ $ this ->httpClient ->addResponse ($ response );
227+
228+ $ this ->client ->setAsync (true );
229+ $ result = $ this ->client ->sendRequest ($ request );
230+ $ this ->assertInstanceOf (Promise::class, $ result );
231+ $ result ->wait ();
232+ $ this ->assertTrue ($ this ->client ->getServerless ());
233+ }
234+
235+ public function testIsServerlessTrueWhenReponseFromServerlessWithAsyncOnSuccessNoException ()
236+ {
237+ $ request = $ this ->psr17Factory ->createRequest ('HEAD ' , 'localhost:9200 ' );
238+ $ response = $ this ->psr17Factory ->createResponse (200 )
239+ ->withHeader ('X-Elastic-Product ' , 'Elasticsearch ' )
240+ ->withHeader (Client::API_VERSION_HEADER , Client::API_VERSION );
241+ $ this ->httpClient ->addResponse ($ response );
242+
243+ $ this ->client ->setAsync (true );
244+ $ result = $ this ->client ->sendRequest ($ request );
245+ $ this ->assertInstanceOf (Promise::class, $ result );
246+ $ result ->wait ();
247+ $ this ->assertTrue ($ this ->client ->getServerless ());
248+ }
196249}
0 commit comments