Skip to content

Commit

Permalink
Merge pull request #14 from LibreSign/feature/add-example
Browse files Browse the repository at this point in the history
Add example
  • Loading branch information
vitormattos authored May 27, 2022
2 parents 2a24584 + 665982c commit 188f57e
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,45 @@ vendor/bin/behat -v
The verbose mode will show:
* The rootDir used
* The output of PHP Built-in server

## Usage example

```php
<?php
use Behat\Behat\Context\Context;
use PhpBuiltin\RunServerListener;
/**
* Defines application features from the specific context.
*/
class FeatureContext implements Context
{
private string $baseUrl;
public function __construct()
{
$this->baseUrl = RunServerListener::getServerRoot();
}
public function sendRequest(string $verb, string $url, ?array $body = null, array $headers = []): void
{
$client = new Client();
$fullUrl = $this->baseUrl . ltrim($url, '/');
$options['headers'] = $headers;
if (is_array($body)) {
$options['form_params'] = $body;
}
try {
$this->response = $client->{$verb}($fullUrl, $options);
} catch (ClientException $e) {
$this->response = $e->getResponse();
} catch (ServerException $e) {
$this->response = $e->getResponse();
}
}
}
```

0 comments on commit 188f57e

Please sign in to comment.