10
10
use Elasticsearch \Common \Exceptions \Missing404Exception ;
11
11
use Elasticsearch \Common \Exceptions \RequestTimeout408Exception ;
12
12
use Elasticsearch \Common \Exceptions \ServerErrorResponseException ;
13
+ use Elasticsearch \Common \Exceptions \RoutingMissingException ;
13
14
use GuzzleHttp \Ring \Future \FutureArrayInterface ;
14
15
use Symfony \Component \Finder \Finder ;
15
16
use Symfony \Component \Finder \SplFileInfo ;
@@ -274,6 +275,29 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
274
275
self ::markTestIncomplete (sprintf ('Method "%s" not implement in "%s" ' , $ method , get_class ($ caller )));
275
276
}
276
277
278
+ // Exist* methods have to be manually 'unwrapped' into true/false for async
279
+ if (strpos ($ method , "exist " ) !== false && $ async === true ) {
280
+ return $ this ->executeAsyncExistRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ testName );
281
+ }
282
+
283
+ return $ this ->executeRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ testName );
284
+ }
285
+
286
+ /**
287
+ * Obtain the response from the server
288
+ *
289
+ * @param $caller
290
+ * @param $method
291
+ * @param $endpointParams
292
+ * @param $expectedError
293
+ * @param $testName
294
+ *
295
+ * @throws \Exception
296
+ *
297
+ * @return array|mixed
298
+ */
299
+ public function executeRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ testName )
300
+ {
277
301
try {
278
302
$ response = $ caller ->$ method ($ endpointParams );
279
303
@@ -291,6 +315,48 @@ public function operationDo($operation, $lastOperationResult, &$context, $testNa
291
315
}
292
316
}
293
317
318
+ /**
319
+ * Obtain the response when it is an Exists* method. These are converted into
320
+ * true/false responses
321
+ *
322
+ * @param $caller
323
+ * @param $method
324
+ * @param $endpointParams
325
+ * @param $expectedError
326
+ * @param $testName
327
+ *
328
+ * @throws \Exception
329
+ *
330
+ * @return bool
331
+ */
332
+ public function executeAsyncExistRequest ($ caller , $ method , $ endpointParams , $ expectedError , $ testName )
333
+ {
334
+ try {
335
+
336
+ $ response = $ caller ->$ method ($ endpointParams );
337
+
338
+ while ($ response instanceof FutureArrayInterface) {
339
+ $ response = $ response ->wait ();
340
+ }
341
+
342
+ if ($ response ['status ' ] === 200 ) {
343
+ return true ;
344
+ } else {
345
+ return false ;
346
+ }
347
+ } catch (Missing404Exception $ exception ) {
348
+ return false ;
349
+ } catch (RoutingMissingException $ exception ) {
350
+ return false ;
351
+ } catch (\Exception $ exception ) {
352
+ if (null !== $ expectedError ) {
353
+ return $ this ->assertException ($ exception , $ expectedError , $ testName );
354
+ }
355
+
356
+ throw $ exception ;
357
+ }
358
+ }
359
+
294
360
/**
295
361
* Check if a field in the last operation is false
296
362
*
0 commit comments