File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -317,7 +317,27 @@ Array
317
317
)
318
318
```
319
319
320
-
320
+ Unit Testing using Mock a Elastic Client
321
+ ========================================
322
+ ``` php
323
+ use GuzzleHttp\Ring\Client\MockHandler;
324
+ use Elasticsearch\ClientBuilder;
325
+
326
+ // The connection class requires 'body' to be a file stream handle
327
+ // Depending on what kind of request you do, you may need to set more values here
328
+ $handler = new MockHandler([
329
+ 'status' => 200,
330
+ 'transfer_stats' => [
331
+ 'total_time' => 100
332
+ ],
333
+ 'body' => fopen('somefile.json')
334
+ ]);
335
+ $builder = ClientBuilder::create();
336
+ $builder->setHosts(['somehost']);
337
+ $builder->setHandler($handler);
338
+ $client = $builder->build();
339
+ // Do a request and you'll get back the 'body' response above
340
+ ```
321
341
322
342
Wrap up
323
343
=======
You can’t perform that action at this time.
0 commit comments