Skip to content

Commit

Permalink
[Docs] Updating readme with mock testing instructions (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwaterz authored and polyfractal committed Jul 19, 2017
1 parent 69dbd4c commit 1623d44
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,27 @@ Array
)
```


Unit Testing using Mock a Elastic Client
========================================
```php
use GuzzleHttp\Ring\Client\MockHandler;
use Elasticsearch\ClientBuilder;

// The connection class requires 'body' to be a file stream handle
// Depending on what kind of request you do, you may need to set more values here
$handler = new MockHandler([
'status' => 200,
'transfer_stats' => [
'total_time' => 100
],
'body' => fopen('somefile.json')
]);
$builder = ClientBuilder::create();
$builder->setHosts(['somehost']);
$builder->setHandler($handler);
$client = $builder->build();
// Do a request and you'll get back the 'body' response above
```

Wrap up
=======
Expand Down

0 comments on commit 1623d44

Please sign in to comment.